WC_Product_Variable_Data_Store_CPT::sync_variation_names( WC_Product $product, string $previous_name = '', string $new_name = '' )
Syncs all variation names if the parent name is changed.
Description Description
Parameters Parameters
- $product
-
(Required) Product object.
- $previous_name
-
(Optional) Variation previous name.
Default value: ''
- $new_name
-
(Optional) Variation new name.
Default value: ''
Source Source
File: includes/data-stores/class-wc-product-variable-data-store-cpt.php
public function sync_variation_names( &$product, $previous_name = '', $new_name = '' ) { if ( $new_name !== $previous_name ) { global $wpdb; $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->posts} SET post_title = REPLACE( post_title, %s, %s ) WHERE post_type = 'product_variation' AND post_parent = %d", $previous_name ? $previous_name : 'AUTO-DRAFT', $new_name, $product->get_id() ) ); } }
Changelog Changelog
Version | Description |
---|---|
3.0.0 | Introduced. |