Automattic\WooCommerce\Internal

DownloadPermissionsAdjuster::maybe_schedule_adjust_download_permissions()publicWC 1.0

Schedule a download permissions adjustment for a product if necessary. This should be executed whenever a product is saved.

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

Хуков нет.

Возвращает

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

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

$DownloadPermissionsAdjuster = new DownloadPermissionsAdjuster();
$DownloadPermissionsAdjuster->maybe_schedule_adjust_download_permissions( $product );
$product(\WC_Product) (обязательный)
The product to schedule a download permission adjustments for.

Код DownloadPermissionsAdjuster::maybe_schedule_adjust_download_permissions() WC 8.7.0

public function maybe_schedule_adjust_download_permissions( \WC_Product $product ) {
	$children_ids = $product->get_children();
	if ( ! $children_ids ) {
		return;
	}

	$are_any_children_downloadable = false;
	foreach ( $children_ids as $child_id ) {
		$child = wc_get_product( $child_id );
		if ( $child && $child->is_downloadable() ) {
			$are_any_children_downloadable = true;
			break;
		}
	}

	if ( ! $product->is_downloadable() && ! $are_any_children_downloadable ) {
		return;
	}

	$scheduled_action_args = array( $product->get_id() );

	$already_scheduled_actions =
		WC()->call_function(
			'as_get_scheduled_actions',
			array(
				'hook'   => 'adjust_download_permissions',
				'args'   => $scheduled_action_args,
				'status' => \ActionScheduler_Store::STATUS_PENDING,
			),
			'ids'
		);

	if ( empty( $already_scheduled_actions ) ) {
		WC()->call_function(
			'as_schedule_single_action',
			WC()->call_function( 'time' ) + 1,
			'adjust_download_permissions',
			$scheduled_action_args
		);
	}
}