Automattic\WooCommerce\Internal
DownloadPermissionsAdjuster::maybe_schedule_adjust_download_permissions()
Schedule a download permissions adjustment for a product if necessary. This should be executed whenever a product is saved.
Method of the class: DownloadPermissionsAdjuster{}
No Hooks.
Return
null
. Nothing (null).
Usage
$DownloadPermissionsAdjuster = new DownloadPermissionsAdjuster(); $DownloadPermissionsAdjuster->maybe_schedule_adjust_download_permissions( $product );
- $product(\WC_Product) (required)
- The product to schedule a download permission adjustments for.
DownloadPermissionsAdjuster::maybe_schedule_adjust_download_permissions() DownloadPermissionsAdjuster::maybe schedule adjust download permissions code 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 ); } }