Automattic\WooCommerce\Internal\StockNotifications\AsyncTasks

CycleStateService::save_cycle_statepublicWC 1.0

Save the cycle state.

Method of the class: CycleStateService{}

No Hooks.

Returns

true|false. Whether the state was saved.

Usage

$CycleStateService = new CycleStateService();
$CycleStateService->save_cycle_state( $product_id, $cycle_state ): bool;
$product_id(int) (required)
The product ID.
$cycle_state(array) (required)
The cycle state.

CycleStateService::save_cycle_state() code WC 10.3.6

public function save_cycle_state( int $product_id, array $cycle_state ): bool {
	if ( $product_id <= 0 ) {
		return false;
	}

	$current_cycle_state = $this->get_raw_cycle_state( $product_id );
	if ( $current_cycle_state === $cycle_state ) {
		return false;
	}

	if ( empty( $cycle_state ) ) {
		$result = delete_option( $this->get_option_name( $product_id ) );
	} else {
		$result = update_option( $this->get_option_name( $product_id ), $cycle_state, false );
	}

	if ( ! $result ) {
		$this->logger->error( sprintf( 'Failed to save cycle state for product %d. Cycle state: %s', $product_id, wc_print_r( $cycle_state, true ) ), array( 'source' => 'wc-customer-stock-notifications' ) );
	}

	return $result;
}