Skip to content

Instantly share code, notes, and snippets.

@xlplugins
Last active June 6, 2025 14:00
Show Gist options
  • Save xlplugins/1abcb060c1620ff17716c7a56ac88d05 to your computer and use it in GitHub Desktop.
Save xlplugins/1abcb060c1620ff17716c7a56ac88d05 to your computer and use it in GitHub Desktop.
forcefully create subscription
<?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