WC_Product_Grouped::sync( WC_Product|int $product, bool $save = true )

Sync a grouped product with it’s children. These sync functions sync upwards (from child to parent) when the variation is saved.


Description Description


Parameters Parameters

$product

(Required) Product object or ID for which you wish to sync.

$save

(Optional) If true, the product object will be saved to the DB before returning it.

Default value: true


Top ↑

Return Return

(WC_Product) Synced product object.


Top ↑

Source Source

File: includes/class-wc-product-grouped.php

	public static function sync( $product, $save = true ) {
		if ( ! is_a( $product, 'WC_Product' ) ) {
			$product = wc_get_product( $product );
		}
		if ( is_a( $product, 'WC_Product_Grouped' ) ) {
			$data_store = WC_Data_Store::load( 'product-' . $product->get_type() );
			$data_store->sync_price( $product );
			if ( $save ) {
				$product->save();
			}
		}
		return $product;
	}


Top ↑

User Contributed Notes User Contributed Notes

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