contains_subscription() only accepts WC_Order object or ID. if ( ( is_a( $order, 'WC_Order' ) && $order->get_status() === 'refunded' ) || is_a( $order, 'WC_Order_Refund' ) || is_a( $order, OrderRefund::class ) ) { Learndash_WooCommerce::remove_course_access( $order->get_id() ); return true; } return wcs_order_contains_subscription( $order, 'any' ); } /** * Processes the orders during the retroactive access tool batch. * * @since 2.0.0 * * @param WC_Order[] $orders Orders to process. * * @return void */ private function process_orders( array $orders ): void { $granted_order_statuses = Status_Access::get_access_granted_order_statuses(); $denied_order_statuses = Status_Access::get_access_denied_order_statuses(); foreach ( $orders as $order ) { $status = $order->get_status(); $order_id = $order->get_id(); if ( $this->should_skip_order( $order ) ) { continue; } if ( in_array( $status, array_keys( $granted_order_statuses ), true ) ) { Learndash_WooCommerce::add_course_access( $order_id ); } if ( in_array( $status, array_keys( $denied_order_statuses ), true ) ) { Learndash_WooCommerce::remove_course_access( $order_id ); } /** * Partial refund order still can have a status of `completed` or other status, so the order status * won't match with the status of the denied access settings. We check all orders if it has a partial * refund. */ Learndash_WooCommerce::remove_course_access_on_refund( $order_id, 0 ); } } /** * Processes the subscriptions during the retroactive access tool batch. * * @since 2.0.0 * * @param WC_Subscription[] $subscriptions Subscriptions to process. * * @return void */ private function process_subscriptions( array $subscriptions ): void { $granted_subscription_statuses = Status_Access::get_access_granted_subscription_statuses(); $denied_subscription_statuses = Status_Access::get_access_denied_subscription_statuses(); foreach ( $subscriptions as $subscription ) { $subscription_status = $subscription->get_status(); if ( in_array( $subscription_status, array_keys( $granted_subscription_statuses ), true ) ) { Learndash_WooCommerce::add_subscription_course_access( $subscription ); } foreach ( $denied_subscription_statuses as $denied_subscription_status => $label ) { if ( $subscription_status === $denied_subscription_status && $subscription_status === 'expired' && get_option( 'learndash_woocommerce_disable_access_removal_on_expiration', 'no' ) === 'yes' ) { continue; } if ( $subscription_status !== $denied_subscription_status ) { continue; } Learndash_WooCommerce::remove_subscription_course_access( $subscription ); } } } /** * Schedules the process batch number. * * @since 2.0.0 * * @param int $batch The batch number. * @param string $type The type of the batch. 'order' or 'subscription'. Default 'order'. * * @return void */ private function schedule_batch( int $batch, string $type = 'order' ): void { as_schedule_single_action( time(), self::ACTION_KEY, [ $batch, $type, ] ); } /** * Run order batch. * * @since 2.0.0 * * @param int $batch The current batch to process. * * @return void */ private function run_order_batch( int $batch ): void { $per_batch = $this->get_per_batch(); $offset = ( $batch - 1 ) * $per_batch; /** * Get orders. * * @var WC_Order[] $orders Orders to process. */ $orders = wc_get_orders( [ 'limit' => $per_batch, 'offset' => $offset, 'order' => 'ASC', ] ); if ( empty( $orders ) ) { // If there are no orders left, we process subscriptions batches next. $this->schedule_batch( 1, 'subscription' ); return; } $this->process_orders( $orders ); $this->schedule_batch( $batch + 1, 'order' ); } /** * Run subscription batch. * * @since 2.0.0 * * @param int $batch The current batch to process. * * @return void */ private function run_subscription_batch( int $batch ): void { $per_batch = $this->get_per_batch(); $offset = ( $batch - 1 ) * $per_batch; $subscriptions = []; if ( function_exists( 'wcs_get_subscriptions' ) ) { $subscriptions = wcs_get_subscriptions( [ 'subscriptions_per_page' => $per_batch, 'offset' => $offset, 'order' => 'ASC', ] ); } if ( empty( $subscriptions ) ) { // Finish and update the retroactive access tool status. $this->end(); return; } $this->process_subscriptions( $subscriptions ); $this->schedule_batch( $batch + 1, 'subscription' ); } /** * Get number of orders or subscriptions to process per batch. * * @since 2.0.0 * * @return int */ private function get_per_batch(): int { /** * Filters the number of orders to process per batch. * * Kept for backward compatibility. * * @since 1.5.0 * @deprecated 2.0.0 Use `learndash_woocommerce_retroactive_access_tool_per_batch` instead. * * @param int $per_batch The number of orders to process per batch. Default 10. * * @return int The number of orders to process per batch. */ $per_batch = apply_filters_deprecated( 'learndash_woocommerce_retroactive_tool_per_batch', [ self::PER_BATCH ], '2.0.0', 'learndash_woocommerce_retroactive_access_tool_per_batch' ); /** * Filters the number of orders to process per batch. * * @since 2.0.0 * * @param int $per_batch The number of orders to process per batch. Default 10. * * @return int The number of orders to process per batch. */ return apply_filters( 'learndash_woocommerce_retroactive_access_tool_per_batch', $per_batch ); } } contains_subscription() only accepts WC_Order object or ID. if ( ( is_a( $order, 'WC_Order' ) && $order->get_status() === 'refunded' ) || is_a( $order, 'WC_Order_Refund' ) || is_a( $order, OrderRefund::class ) ) { Learndash_WooCommerce::remove_course_access( $order->get_id() ); return true; } return wcs_order_contains_subscription( $order, 'any' ); } /** * Processes the orders during the retroactive access tool batch. * * @since 2.0.0 * * @param WC_Order[] $orders Orders to process. * * @return void */ private function process_orders( array $orders ): void { $granted_order_statuses = Status_Access::get_access_granted_order_statuses(); $denied_order_statuses = Status_Access::get_access_denied_order_statuses(); foreach ( $orders as $order ) { $status = $order->get_status(); $order_id = $order->get_id(); if ( $this->should_skip_order( $order ) ) { continue; } if ( in_array( $status, array_keys( $granted_order_statuses ), true ) ) { Learndash_WooCommerce::add_course_access( $order_id ); } if ( in_array( $status, array_keys( $denied_order_statuses ), true ) ) { Learndash_WooCommerce::remove_course_access( $order_id ); } /** * Partial refund order still can have a status of `completed` or other status, so the order status * won't match with the status of the denied access settings. We check all orders if it has a partial * refund. */ Learndash_WooCommerce::remove_course_access_on_refund( $order_id, 0 ); } } /** * Processes the subscriptions during the retroactive access tool batch. * * @since 2.0.0 * * @param WC_Subscription[] $subscriptions Subscriptions to process. * * @return void */ private function process_subscriptions( array $subscriptions ): void { $granted_subscription_statuses = Status_Access::get_access_granted_subscription_statuses(); $denied_subscription_statuses = Status_Access::get_access_denied_subscription_statuses(); foreach ( $subscriptions as $subscription ) { $subscription_status = $subscription->get_status(); if ( in_array( $subscription_status, array_keys( $granted_subscription_statuses ), true ) ) { Learndash_WooCommerce::add_subscription_course_access( $subscription ); } foreach ( $denied_subscription_statuses as $denied_subscription_status => $label ) { if ( $subscription_status === $denied_subscription_status && $subscription_status === 'expired' && get_option( 'learndash_woocommerce_disable_access_removal_on_expiration', 'no' ) === 'yes' ) { continue; } if ( $subscription_status !== $denied_subscription_status ) { continue; } Learndash_WooCommerce::remove_subscription_course_access( $subscription ); } } } /** * Schedules the process batch number. * * @since 2.0.0 * * @param int $batch The batch number. * @param string $type The type of the batch. 'order' or 'subscription'. Default 'order'. * * @return void */ private function schedule_batch( int $batch, string $type = 'order' ): void { as_schedule_single_action( time(), self::ACTION_KEY, [ $batch, $type, ] ); } /** * Run order batch. * * @since 2.0.0 * * @param int $batch The current batch to process. * * @return void */ private function run_order_batch( int $batch ): void { $per_batch = $this->get_per_batch(); $offset = ( $batch - 1 ) * $per_batch; /** * Get orders. * * @var WC_Order[] $orders Orders to process. */ $orders = wc_get_orders( [ 'limit' => $per_batch, 'offset' => $offset, 'order' => 'ASC', ] ); if ( empty( $orders ) ) { // If there are no orders left, we process subscriptions batches next. $this->schedule_batch( 1, 'subscription' ); return; } $this->process_orders( $orders ); $this->schedule_batch( $batch + 1, 'order' ); } /** * Run subscription batch. * * @since 2.0.0 * * @param int $batch The current batch to process. * * @return void */ private function run_subscription_batch( int $batch ): void { $per_batch = $this->get_per_batch(); $offset = ( $batch - 1 ) * $per_batch; $subscriptions = []; if ( function_exists( 'wcs_get_subscriptions' ) ) { $subscriptions = wcs_get_subscriptions( [ 'subscriptions_per_page' => $per_batch, 'offset' => $offset, 'order' => 'ASC', ] ); } if ( empty( $subscriptions ) ) { // Finish and update the retroactive access tool status. $this->end(); return; } $this->process_subscriptions( $subscriptions ); $this->schedule_batch( $batch + 1, 'subscription' ); } /** * Get number of orders or subscriptions to process per batch. * * @since 2.0.0 * * @return int */ private function get_per_batch(): int { /** * Filters the number of orders to process per batch. * * Kept for backward compatibility. * * @since 1.5.0 * @deprecated 2.0.0 Use `learndash_woocommerce_retroactive_access_tool_per_batch` instead. * * @param int $per_batch The number of orders to process per batch. Default 10. * * @return int The number of orders to process per batch. */ $per_batch = apply_filters_deprecated( 'learndash_woocommerce_retroactive_tool_per_batch', [ self::PER_BATCH ], '2.0.0', 'learndash_woocommerce_retroactive_access_tool_per_batch' ); /** * Filters the number of orders to process per batch. * * @since 2.0.0 * * @param int $per_batch The number of orders to process per batch. Default 10. * * @return int The number of orders to process per batch. */ return apply_filters( 'learndash_woocommerce_retroactive_access_tool_per_batch', $per_batch ); } } https://andainas.es/post-sitemap.xml 2025-10-29T19:51:48+00:00 https://andainas.es/page-sitemap.xml 2026-07-03T12:47:05+00:00 https://andainas.es/attachment-sitemap.xml 2026-07-06T08:09:38+00:00 https://andainas.es/product-sitemap.xml 2026-07-06T08:12:22+00:00 https://andainas.es/sfwd-courses-sitemap.xml 2026-07-03T12:13:16+00:00 https://andainas.es/sfwd-lessons-sitemap.xml 2026-06-19T08:54:34+00:00 https://andainas.es/sfwd-topic-sitemap.xml 2025-05-15T13:41:46+00:00 https://andainas.es/groups-sitemap.xml 2026-07-03T12:23:06+00:00 https://andainas.es/category-sitemap.xml 2026-07-03T12:23:06+00:00 https://andainas.es/product_cat-sitemap.xml 2026-07-06T08:12:22+00:00 https://andainas.es/ld_course_category-sitemap.xml 2026-07-03T08:50:18+00:00 https://andainas.es/ld_lesson_category-sitemap.xml 2026-06-19T08:54:34+00:00 https://andainas.es/ld_lesson_tag-sitemap.xml 2025-10-17T09:00:42+00:00