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 4.7.6 4.7.7 4.7.8 4.7.9 4.8.0 4.9.0 4.9.1 5.0.1 5.0.2 5.1.1 5.1.2 5.1.3 5.2.0 5.2.1 5.3.2 5.3.3.1 5.3.4 5.3.5 5.3.6 5.3.7
woocommerce-multilingual / classes / Synchronization / Component / Taxonomies.php
woocommerce-multilingual / classes / Synchronization / Component Last commit date
Attachments.php 2 weeks ago Attributes.php 2 weeks ago DownloadableFiles.php 2 weeks ago Linked.php 2 weeks ago Meta.php 2 weeks ago Post.php 2 weeks ago Stock.php 2 weeks ago Synchronizer.php 2 weeks ago SynchronizerForMeta.php 2 weeks ago Taxonomies.php 2 weeks ago VariationAttachments.php 2 weeks ago VariationMeta.php 2 weeks ago VariationTaxonomies.php 2 weeks ago Variations.php 2 weeks ago
Taxonomies.php
100 lines
1 <?php
2
3 namespace WCML\Synchronization\Component;
4
5 use WCML\Terms\SuspendWpmlFiltersFactory;
6 use WCML\Utilities\DB;
7 use WPML_Non_Persistent_Cache;
8 class Taxonomies extends Synchronizer {
9
10 public function run( $product, $translationsIds, $translationsLanguages ) {
11 $filtersSuspend = SuspendWpmlFiltersFactory::create();
12 foreach ( $translationsLanguages as $translationId => $language ) {
13 $this->runForTranslation( $product->ID, $translationId, $language );
14 }
15 $filtersSuspend->resume();
16 }
17
18 private function runForTranslation( $productId, $translationId, $language ) {
19 $taxonomyExceptions = [ 'product_type', 'product_visibility' ];
20 $taxonomySyncEmpty = [ \WCML_Terms::PRODUCT_SHIPPING_CLASS ];
21 $taxonomies = $taxonomyExceptions;
22 if ( $this->sitepress->get_setting( 'sync_post_taxonomies' ) ) {
23 $taxonomies = get_object_taxonomies( 'product' );
24 }
25
26 $found = false;
27 $allTerms = WPML_Non_Persistent_Cache::get( $productId, __CLASS__, $found );
28 if ( ! $found ) {
29 $allTerms = wp_get_object_terms( $productId, $taxonomies );
30 WPML_Non_Persistent_Cache::set( $productId, $allTerms, __CLASS__ );
31 }
32 if ( ! is_wp_error( $allTerms ) ) {
33 foreach ( $taxonomies as $taxonomy ) {
34 if ( ! apply_filters( 'wpml_is_translated_taxonomy', false, $taxonomy ) ) {
35 $taxonomyExceptions[] = $taxonomy;
36 }
37 $ttIds = [];
38 $ttNames = [];
39 $terms = array_filter(
40 $allTerms,
41 function ( $term ) use ( $taxonomy ) {
42 return $term->taxonomy === $taxonomy;
43 }
44 );
45 if ( ! $terms && ! in_array( $taxonomy, $taxonomySyncEmpty, true ) ) {
46 continue;
47 }
48 foreach ( $terms as $term ) {
49 if ( in_array( $term->taxonomy, $taxonomyExceptions, true ) ) {
50 $ttNames[] = $term->name;
51 continue;
52 }
53 $ttIds[] = $term->term_taxonomy_id;
54 }
55
56 if ( $this->woocommerceWpml->terms->is_translatable_wc_taxonomy( $taxonomy ) && ! in_array( $taxonomy, $taxonomyExceptions, true ) ) {
57 $this->setTranslatedTerms( $ttIds, $language, $taxonomy, $translationId );
58 } else {
59 wp_set_post_terms( $translationId, $ttNames, $taxonomy );
60 }
61 }
62 }
63
64 }
65
66 private function setTranslatedTerms( $ttIds, $language, $taxonomy, $translationId ) {
67 $ttIdsTrans = [];
68
69 foreach ( $ttIds as $ttId ) {
70 $ttIdTrans = $this->elementTranslations->element_id_in( $ttId, $language );
71 if ( $ttIdTrans ) {
72 $ttIdsTrans[] = $ttIdTrans;
73 }
74 }
75
76 $ttIdsTrans = array_values( array_unique( array_map( 'intval', $ttIdsTrans ) ) );
77
78 if ( empty( $ttIdsTrans ) ) {
79 return;
80 }
81
82 if ( in_array( $taxonomy, [ 'product_cat', 'product_tag' ] ) ) {
83 $this->sitepress->switch_lang( $language );
84 wp_update_term_count( $ttIdsTrans, $taxonomy );
85 $this->sitepress->switch_lang();
86 }
87
88 $termIds = $this->wpdb->get_col(
89 $this->wpdb->prepare(
90 "SELECT term_id FROM {$this->wpdb->term_taxonomy} WHERE term_taxonomy_id IN (" . DB::prepareIn( $ttIdsTrans, '%d' ) . ") LIMIT %d",
91 count( $ttIdsTrans )
92 )
93 );
94
95 $termIds = array_unique( array_map( 'intval', $termIds ) );
96 wp_set_post_terms( $translationId, $termIds, $taxonomy );
97 }
98
99 }
100