WC_Product_Variable_Data_Store_CPT::sync_variation_names
Syncs all variation names if the parent name is changed.
Method of the class: WC_Product_Variable_Data_Store_CPT{}
No Hooks.
Returns
null. Nothing (null).
Usage
$WC_Product_Variable_Data_Store_CPT = new WC_Product_Variable_Data_Store_CPT(); $WC_Product_Variable_Data_Store_CPT->sync_variation_names( $product, $previous_name, $new_name );
- $product(WC_Product) (required) (passed by reference — &)
- Product object.
- $previous_name(string)
- Variation previous name.
Default: '' - $new_name(string)
- Variation new name.
Default: ''
Changelog
| Since 3.0.0 | Introduced. |
WC_Product_Variable_Data_Store_CPT::sync_variation_names() WC Product Variable Data Store CPT::sync variation names code WC 10.3.3
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()
)
);
}
}