Automattic\WooCommerce\Internal\ProductAttributesLookup

LookupDataStore::maybe_schedule_update()privateWC 1.0

Schedule an update of the product attributes lookup table for a given product. If an update for the same action is already scheduled, nothing is done.

If the 'woocommerce_attribute_lookup_direct_update' option is set to 'yes', the update is done directly, without scheduling.

Метод класса: LookupDataStore{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

// private - только в коде основоного (родительского) класса
$result = $this->maybe_schedule_update( $product_id, $action );
$product_id(int) (обязательный)
The product id to schedule the update for.
$action(int) (обязательный)
The action to perform, one of the ACTION_ constants.

Код LookupDataStore::maybe_schedule_update() WC 8.7.0

private function maybe_schedule_update( int $product_id, int $action ) {
	if ( get_option( 'woocommerce_attribute_lookup_direct_updates' ) === 'yes' ) {
		$this->run_update_callback( $product_id, $action );
		return;
	}

	$args = array( $product_id, $action );

	$queue             = WC()->get_instance_of( \WC_Queue::class );
	$already_scheduled = $queue->search(
		array(
			'hook'   => 'woocommerce_run_product_attribute_lookup_update_callback',
			'args'   => $args,
			'status' => \ActionScheduler_Store::STATUS_PENDING,
		),
		'ids'
	);

	if ( empty( $already_scheduled ) ) {
		$queue->schedule_single(
			WC()->call_function( 'time' ) + 1,
			'woocommerce_run_product_attribute_lookup_update_callback',
			$args,
			'woocommerce-db-updates'
		);
	}
}