WooCommerce Order and Subscription Creation Actions
Patrick Steadman - Jan 4, 2021 in Notes
Actions not firing upon subscription creation? Try these actions and filters. Actions not firing upon subscription creation? Try these actions and filters.
If you’re using a WooCommerce plugin like Cartflows, subscription actions initialized using woocommerce_checkout_subscription_created may not fire. In the case of Cartflows, child orders created in Upsells or Downflows do not trigger the aforementioned action, presumably because a unique checkout is not occurring.
If you still need to trigger an action for the creation of a Cartflow upsold subscription, there is also an undocumented action wcs_create_subscription. There is also a filter with the same name, you can check out the source here. It seems like using this hook may be more robust than woocommerce_checkout_subscription_created or the status change actions.
Example of usage:
<br>1<br>2<br>3<br>4<br>5<br> |
<br>function on_subscription_created($subscription)<br>{<br> // do action here<br>}<br>add_action( 'wcs_create_subscription', 'on_subscription_created', 1, 1 ); <br> |
Note on Subscriptions Created via Admin Note on Subscriptions Created via Admin
The wcs_create_subscription action will not fire for subscriptions created via the admin interface. In order to trigger actions in admin, you must use the strangely-named woocommerce_process_shop_order_meta, and then add logic to confirm that the order is a subscription. See this stackoverflow post for more information.