class-wcml-per-product-shipping.php
26 lines
| 1 | <?php |
| 2 | |
| 3 | class WCML_Per_Product_Shipping implements \IWPML_Action { |
| 4 | |
| 5 | public function add_hooks() { |
| 6 | if ( ! is_admin() ) { |
| 7 | add_filter( 'woocommerce_per_product_shipping_get_matching_rule_product_id', [ $this, 'original_product_id' ] ); |
| 8 | } |
| 9 | } |
| 10 | |
| 11 | public function original_product_id( $product_id ) { |
| 12 | global $sitepress; |
| 13 | |
| 14 | $trid = $sitepress->get_element_trid( $product_id, 'post_product' ); |
| 15 | $translations = $sitepress->get_element_translations( $trid, 'post_product' ); |
| 16 | foreach ( $translations as $language_code => $translation ) { |
| 17 | if ( $translation->original ) { |
| 18 | $product_id = $translation->element_id; |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | return $product_id; |
| 23 | } |
| 24 | |
| 25 | } |
| 26 |