Changeset 3490339
- Timestamp:
- 03/24/2026 08:09:20 PM (2 days ago)
- Location:
- businesscentralconnector/trunk
- Files:
-
- 2 edited
-
businesscentralconnector.php (modified) (2 diffs)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
businesscentralconnector/trunk/businesscentralconnector.php
r3476671 r3490339 4 4 * Plugin URI: https://help.synfynal.com/articles/index.html 5 5 * Description: Extends WooCommerce API for Business Central integration via Synfynal Connector. Requires Business Central/WooCommerce Connector from AppSource. 6 * Version: 1.1. 66 * Version: 1.1.7 7 7 * Author: Synfynal 8 8 * Author URI: https://www.synfynal.com/ … … 213 213 214 214 add_action('woocommerce_rest_insert_customer', 'bccentralconnector_sync_elex_pricing', 20, 3); 215 216 /** 217 * ===================================================================== 218 * Polylang translation sync via REST API 219 * 220 * When a PUT/POST to /wp-json/wc/v3/products/{id} includes 221 * { "key": "should_update", "value": "true" } 222 * in meta_data, this simulates an admin Save by creating a valid 223 * Polylang nonce and calling wp_update_post in admin context. 224 * This fires save_post with all hooks — including Polylang's sync 225 * to translated products — exactly as the admin Save button does. 226 * ===================================================================== 227 */ 228 function bccentralconnector_handle_product_update(WC_Product $product, WP_REST_Request $request, bool $creating) { 229 $user_agent = $request->get_header('user_agent'); 230 if (empty($user_agent) || stripos($user_agent, 'Synfynal') === false) { 231 return; 232 } 233 234 $meta_data = $request->get_param('meta_data'); 235 if (!is_array($meta_data)) { 236 return; 237 } 238 239 foreach ($meta_data as $meta) { 240 if (isset($meta['key'], $meta['value']) && $meta['key'] === 'should_update') { 241 if (filter_var($meta['value'], FILTER_VALIDATE_BOOLEAN)) { 242 // Provide a valid Polylang nonce and briefly set admin context so 243 // Polylang's save_post handler passes its security checks and 244 // propagates meta to all translated product variants. 245 $_POST['pll_nonce'] = wp_create_nonce('pll_language'); 246 add_filter('is_admin', '__return_true'); 247 wp_update_post(array('ID' => $product->get_id())); 248 remove_filter('is_admin', '__return_true'); 249 unset($_POST['pll_nonce']); 250 } 251 return; 252 } 253 } 254 } 255 add_action('woocommerce_rest_insert_product_object', 'bccentralconnector_handle_product_update', 10, 3); 215 256 216 257 /** -
businesscentralconnector/trunk/readme.txt
r3476671 r3490339 5 5 Requires PHP: 7.0 6 6 Tested up to: 6.8 7 Stable tag: 1.1. 67 Stable tag: 1.1.7 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html
Note: See TracChangeset
for help on using the changeset viewer.