WordPress at Your Fingertips
function is not described

WC_Product_Variable_Data_Store_CPT::sync_variation_names() public WC 3.0.0

Syncs all variation names if the parent name is changed.

{} It's a method of the class: WC_Product_Variable_Data_Store_CPT{}

No Hooks.

Return

null. Nothing.

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.

Code of WC_Product_Variable_Data_Store_CPT::sync_variation_names() WC 5.7.0

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()
			)
		);
	}
}