mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
Unschedule renewal action if subscription was created with PayPal Subscriptions API
This commit is contained in:
parent
70dc55dcc1
commit
cbfa41ae67
1 changed files with 30 additions and 0 deletions
|
@ -9,6 +9,7 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace WooCommerce\PayPalCommerce\Subscription;
|
namespace WooCommerce\PayPalCommerce\Subscription;
|
||||||
|
|
||||||
|
use ActionScheduler_Store;
|
||||||
use Exception;
|
use Exception;
|
||||||
use WC_Product;
|
use WC_Product;
|
||||||
use WC_Product_Subscription_Variation;
|
use WC_Product_Subscription_Variation;
|
||||||
|
@ -290,6 +291,35 @@ class SubscriptionModule implements ModuleInterface {
|
||||||
30,
|
30,
|
||||||
2
|
2
|
||||||
);
|
);
|
||||||
|
|
||||||
|
add_action(
|
||||||
|
'action_scheduler_before_execute',
|
||||||
|
/**
|
||||||
|
* Param types removed to avoid third-party issues.
|
||||||
|
*
|
||||||
|
* @psalm-suppress MissingClosureParamType
|
||||||
|
*/
|
||||||
|
function( $action_id ) {
|
||||||
|
/**
|
||||||
|
* Class exist in WooCommerce.
|
||||||
|
*
|
||||||
|
* @psalm-suppress UndefinedClass
|
||||||
|
*/
|
||||||
|
$store = ActionScheduler_Store::instance();
|
||||||
|
$action = $store->fetch_action( $action_id );
|
||||||
|
|
||||||
|
$subscription_id = $action->get_args()['subscription_id'] ?? null;
|
||||||
|
if ( $subscription_id ) {
|
||||||
|
$subscription = wcs_get_subscription( $subscription_id );
|
||||||
|
if ( is_a( $subscription, WC_Subscription::class ) ) {
|
||||||
|
$paypal_subscription_id = $subscription->get_meta( 'ppcp_subscription' ) ?? '';
|
||||||
|
if ( $paypal_subscription_id ) {
|
||||||
|
as_unschedule_action( $action->get_hook(), $action->get_args() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue