Clear global_unique_id when restoring a product with an existing global_unique_id (#50496)
* Clear global_unique_id when restoring a product that doesn't have an unique id * Check if product exists before calling methods
This commit is contained in:
parent
10bc399c07
commit
9297409c5a
|
@ -0,0 +1,4 @@
|
|||
Significance: minor
|
||||
Type: update
|
||||
|
||||
Clear global_unique_id when restoring a product that doesn't have an unique id
|
|
@ -405,6 +405,7 @@ class WC_Post_Data {
|
|||
$data_store->untrash_variations( $id );
|
||||
|
||||
wc_product_force_unique_sku( $id );
|
||||
self::clear_global_unique_id_if_necessary( $id );
|
||||
|
||||
wc_get_container()->get( ProductAttributesLookupDataStore::class )->on_product_changed( $id );
|
||||
} elseif ( 'product_variation' === $post_type ) {
|
||||
|
@ -412,6 +413,19 @@ class WC_Post_Data {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear global unique id if it's not unique.
|
||||
*
|
||||
* @param mixed $id Post ID.
|
||||
*/
|
||||
private static function clear_global_unique_id_if_necessary( $id ) {
|
||||
$product = wc_get_product( $id );
|
||||
if ( $product && ! wc_product_has_global_unique_id( $id, $product->get_global_unique_id() ) ) {
|
||||
$product->set_global_unique_id( '' );
|
||||
$product->save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the post type for a given post.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue