Automattic\WooCommerce\Internal\ProductFeed\Integrations\POSCatalog

POSProductVisibilitySync::sync_pos_visibility_to_variationsprivateWC 10.5.0

Sync POS visibility to all variations of a variable product.

Method of the class: POSProductVisibilitySync{}

No Hooks.

Returns

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->sync_pos_visibility_to_variations( $product, $visible_in_pos ): void;
$product(WC_Product) (required)
The variable product.
$visible_in_pos(true|false) (required)
Whether the product should be visible in POS.

Changelog

Since 10.5.0 Introduced.

POSProductVisibilitySync::sync_pos_visibility_to_variations() code WC 10.9.4

private function sync_pos_visibility_to_variations( \WC_Product $product, bool $visible_in_pos ): void {
	$variation_ids = $product->get_children();
	foreach ( $variation_ids as $variation_id ) {
		if ( $visible_in_pos ) {
			wp_remove_object_terms( $variation_id, 'pos-hidden', 'pos_product_visibility' );
		} else {
			wp_set_object_terms( $variation_id, 'pos-hidden', 'pos_product_visibility' );
		}

		// Save variation to update date_modified.
		$variation = wc_get_product( $variation_id );
		if ( $variation ) {
			$variation->save();
		}
	}
}