diff --git a/src/compatibility/woocommerce.php b/src/compatibility/woocommerce.php index 47dfe27f0..d47475274 100644 --- a/src/compatibility/woocommerce.php +++ b/src/compatibility/woocommerce.php @@ -58,3 +58,33 @@ function stackable_get_woocommerce_shop_page_id( $post_id ) { add_filter( 'stackable/get_post_id_for_cached_css', 'stackable_get_woocommerce_shop_page_id' ); } + +/** + * Preserve escaped block attributes when WooCommerce duplicates a product. + * + * WooCommerce passes a product description read from the database directly to + * wp_insert_post(), which expects slashed data. Without restoring that slash + * layer, escaped characters in block comment JSON (for example, \u003c in an + * SVG icon or \u002d in a preset CSS variable) lose their backslashes. + */ +if ( ! function_exists( 'stackable_preserve_woocommerce_duplicate_block_escaping' ) ) { + + function stackable_preserve_woocommerce_duplicate_block_escaping( $duplicate, $product ) { + $description = $duplicate->get_description( 'edit' ); + + if ( ! is_string( $description ) || $description === '' ) { + return; + } + + if ( strpos( $description, '