@@ -146,55 +146,27 @@ public function skipDefaultAttributesMeta($check, $object_id, $meta_key, $meta_v
146
146
// Ignore if not 'default attribute' meta
147
147
if ('_default_attributes ' === $ meta_key ) {
148
148
$ product = wc_get_product ($ object_id );
149
+ $ current_filter = current_filter ();
149
150
150
151
// Don't let anyone delete the meta. NO ONE!
151
- if ($ product && current_filter () === 'delete_post_metadata ' ) {
152
+ if ( $ product && $ current_filter === 'delete_post_metadata ' ) {
152
153
return false ;
153
154
}
154
155
155
156
// _default_attributes meta should be unique
156
- if ($ product && current_filter () === 'add_post_metadata ' ) {
157
+ if ($ product && $ current_filter === 'add_post_metadata ' ) {
157
158
$ old_value = get_post_meta ($ product ->get_id (), '_default_attributes ' );
158
159
return empty ($ old_value ) ? $ check : false ;
159
160
}
160
161
161
- // Maybe is Variable Product
162
- // New translations of Variable Products are first created as simple
163
- if ($ product && Utilities::maybeVariableProduct ($ product )) {
164
- // Try Polylang first
165
- $ lang = pll_get_post_language ($ product ->get_id ());
166
162
167
- if (!$ lang ) {
168
- // Must be a new translation and Polylang doesn't stored the language yet
169
- $ lang = isset ($ _GET ['new_lang ' ]) ? $ _GET ['new_lang ' ] : '' ;
170
- }
171
-
172
- foreach ($ meta_value as $ key => $ value ) {
173
- //TODO JM: get_term_by is filtered by Polylang, so
174
- //will not retrieve data if the term is not in the correct language
175
- //so the rest of the check does not execute as expected
176
- //(it is not possible to get the term without knowing the language,
177
- // and not possible to get the translation without getting the term)
178
- // the fix is the additional return false which prevents save of the incorrect version when Polylang attempts to synchronise it
179
- $ term = get_term_by ('slug ' , $ value , $ key );
180
-
181
- if ($ term && pll_is_translated_taxonomy ($ term ->taxonomy )) {
182
- if ($ translated_term_id = pll_get_term ($ term ->term_id , $ lang )) {
183
- $ translated_term = get_term_by ('id ' , $ translated_term_id , $ term ->taxonomy );
184
-
185
- // If meta is taxonomy managed by Polylang and is in the
186
- // correct language continue, otherwise return false to
187
- // stop execution
188
- return ($ value === $ translated_term ->slug ) ? $ check : false ;
189
- } else {
190
- // Attribute term has no translation
191
- return false ;
192
- }
193
- }
194
- // Attribute is in wrong language and must not be saved
195
- return false ;
196
- }
197
- }
163
+ /* #432: this check was partially incorrect and
164
+ * is no longer needed after removing _default_attributes
165
+ * from the list of meta synchronised by Polylang.
166
+ * (another way of doing it would be to hook the polylang filter
167
+ * in sync-metas maybe_translate_value
168
+ * and translate the default attributes there, but that is bigger change to this plugin
169
+ */
198
170
}
199
171
200
172
return $ check ;
@@ -250,7 +222,7 @@ public function syncDefaultAttributes($post_id, $post, $update)
250
222
foreach ($ langs as $ lang ) {
251
223
$ translation_id = pll_get_post ($ product ->get_id (), $ lang );
252
224
253
- if ($ translation_id != $ product ->get_id ()) {
225
+ if ( $ translation_id && $ translation_id != $ product ->get_id ()) {
254
226
update_post_meta ($ translation_id , '_default_attributes ' , $ attributes_translation [$ lang ]);
255
227
}
256
228
}
0 commit comments