We are using Woocommerce and Woocommerce Subscriptions plugins in Wordpress. We have a custom meta key/value on the subscriptions, and we need to check this value during the renewal process. If the value is not equal to "X", we need to immediately end the payment process.

I have dug all through the Woocommerce and Woocommerce subscriptions docs, and I found the woocommerce_scheduled_subscription_payment hook, but I'm not sure if this is a good place to intercept the payment process. I tested it, and it does fire before the payment is processed, which is good, but I can't figure out how to make my code break out of the payment process and ensure that the gateway is never hit.

Is this the right hook, and if so, what do I need to do to break out of the payment process? For reference, here is what I have now:

function pbt_intercept_payment($subscription_id) {
    $agreed = get_post_meta($subscription_id, 'agreed_to_charges', true);
    if($agreed != 1) {
        // Need to jump out of the payment process here...

I would actually prefer to jump in before the renewal order is even created. Woocommerce, when the subscription renews, creates a new renewal order. I would prefer to hook in before that even happens, to prevent the order from being created at all, but reading through the docs, I couldn't find any applicable action hooks that would allow me to jump into that spot. However, if there is a way to do that, I would much prefer that, so that we don't have unprocessable renewal orders being created...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.