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: ''


Top ↑

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

Top ↑

Changelog Changelog

Changelog
Version Description
3.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.