File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
sample-code-snippets/premium/ecommerce Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /**
4+ * This snippet sets the product permalink to its translated version when using WooCommerce + WPML
5+ *
6+ * See https://github.com/ibericode/mailchimp-for-wordpress/issues/775
7+ */
8+
9+ add_filter ('mc4wp_ecommerce_product_data ' , function ($ data , WC_Product $ product ) {
10+ $ language = apply_filters ('wpml_element_language_code ' , null , array (
11+ 'element_id ' => $ data ['id ' ],
12+ 'element_type ' => 'product '
13+ ));
14+ $ data ['url ' ] = apply_filters ('wpml_permalink ' , $ data ['url ' ], $ language );
15+ return $ data ;
16+ }, 10 , 2 );
17+
18+ add_filter ('mc4wp_ecommerce_product_variants_data ' , function ($ variants , $ product ) {
19+ foreach ($ variants as $ key => $ variant ) {
20+ $ language = apply_filters ('wpml_element_language_code ' , null , array (
21+ 'element_id ' => $ variant ['id ' ],
22+ 'element_type ' => 'product '
23+ ));
24+ $ variants [$ key ]['url ' ] = apply_filters ('wpml_permalink ' , $ variant ['url ' ], $ language );
25+ }
26+ return $ variants ;
27+ }, 10 , 2 );
You can’t perform that action at this time.
0 commit comments