Last active
June 6, 2025 14:00
-
-
Save xlplugins/1abcb060c1620ff17716c7a56ac88d05 to your computer and use it in GitHub Desktop.
forcefully create subscription
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Funnelkit_Force_Create_Subscription { | |
public function __construct() { | |
add_action( 'woocommerce_checkout_process', [ $this, 'attach_dependant_hooks' ] ); | |
} | |
/** | |
* Attach order meta update hook during checkout. | |
*/ | |
public function attach_dependant_hooks() { | |
add_action( 'woocommerce_checkout_update_order_meta', [ $this, 'process_subscription_checkout' ], 999, 2 ); | |
} | |
/** | |
* Trigger subscription processing after order meta update. | |
* | |
* @param int $order_id Order ID. | |
* @param array $data Checkout data. | |
*/ | |
public function process_subscription_checkout( $order_id, $data ) { | |
if ( ! class_exists( 'WC_Subscriptions_Checkout' ) ) { | |
return; | |
} | |
WC_Subscriptions_Checkout::process_checkout( $order_id, $data ); | |
} | |
} | |
new Funnelkit_Force_Create_Subscription(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment