Product.php
23 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WCML\OrderItems\LineItem; |
| 4 | |
| 5 | use WCML\OrderItems\Translator; |
| 6 | |
| 7 | class Product implements Translator { |
| 8 | |
| 9 | public function translateItem( $item, $targetLanguage ) { |
| 10 | if ( ! $item instanceof \WC_Order_Item_Product ) { |
| 11 | return; |
| 12 | } |
| 13 | |
| 14 | $productId = $item->get_product_id(); |
| 15 | $translatedProductId = apply_filters( 'wpml_object_id', $productId, 'product', true, $targetLanguage ); |
| 16 | if ( $productId && $productId !== $translatedProductId ) { |
| 17 | $item->set_product_id( $translatedProductId ); |
| 18 | $item->set_name( get_post( $translatedProductId )->post_title ); |
| 19 | $item->apply_changes(); |
| 20 | } |
| 21 | } |
| 22 | } |
| 23 |