• Resolved dziuba

    (@dziuba)


    Because i use Woo Subscriptions i would like to skip the on-hold status to set the subscription to active.
    So the order then would be in the ‘processing’ status.
    Is there a way to automaticly set the order to ‘completed’ if the Webhook Charge.succeeded is recieved?
    Is there any action the i could use and is there a variable where i could get the status of the charge?
    And would this interfere with the plugin in any way?

    Normally i could just skip the processing status but i can’t do that here because of the subscriptions, because i would like to have a status to reflect that the payment is still pending. Otherwise i could just skip to ‘completed’.

    Right now im skipping the on-hold status like this:

    add_action( 'woocommerce_order_status_changed', 'wc_order_processing_SEPA', 10, 4 );
    function wc_order_processing_SEPA( $order_id, $status_from, $status_to, $order ) {
        if($order->get_payment_method() === 'stripe_sepa' && $status_to === 'on-hold') {
            $order->update_status( 'processing' );
        }
    }
Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Clayton R

    (@mrclayton)

    Hi @dziuba,

    Take a look at the wc_stripe_pending_charge_status filter:

    https://docs.paymentplugins.com/wc-stripe/api/source-class-WC_Stripe_Payment.html#101

    You can use that filter to control the order’s status which will have the effect of making the subscription’s status active.

    Kind regards

    Thread Starter dziuba

    (@dziuba)

    Maybe i phrased myself a little bit misleading.

    The final goal is to automaticly set the order status to ‘completed’ because the Subscriptions are virtual products.

    Which i could do if i just would skip the ‘processing’ status and go directly to ‘completed’. So it would be:
    ‘on-hold’ -> Charge.succeeded -> ‘completed’ (skipping processing)
    So ‘on-hold’ would as intended reflect a pending payment.
    I could do that if i just listen on the status change like the action above.

    But.. Because of Subscriptions i need to skip the on-hold status to make the subscription immediately active.
    So what i want is:
    ‘processing’ -> Charge.succeeded -> ‘completed’ (skipping on-hold)
    So ‘processing’ now would reflect a pending payment.

    As im already in the ‘processing’ Status to begin with i would need a possibility to add an action after the Charge.succeeded webhook was processed or instead of normally changing the status from ‘on-hold’ to ‘processing’ i would need to change from ‘processing’ to ‘completed’ on a Charge.succeeded.

    Really appreciate your help.

    • This reply was modified 5 years, 2 months ago by dziuba.
    Plugin Author Clayton R

    (@mrclayton)

    Hi @dziuba,

    The filter I gave you is what you would use to skip the on-hold status. You would return processing using that filter and it will set the order’s status to processing.

    Then when the charge.succeeded event is received, the order’s status will be updated to completed.

    Kind Regards,

    Thread Starter dziuba

    (@dziuba)

    Right now after charge.succeeded my order still stays in processing.
    Even tho it’s a virtual product.

    EDIT:
    Got it. It also has to be a downloadable product.
    Then it works.

    • This reply was modified 5 years, 2 months ago by dziuba.
    Thread Starter dziuba

    (@dziuba)

    Maybe this helps somebody.
    I just set the status of the subscription after the checkout to active
    if its a SEPA payment.

    add_action( 'woocommerce_thankyou', 'wc_subscription_set_active_SEPA', 50, 1 );
    function wc_subscription_set_active_SEPA( $order_id ){
        if( ! $order_id ) return;
    	
        $order = wc_get_order( $order_id ); // Get an instance of the WC_Order object
    
        // If the order contains a subscription and is a Stripe SEPA payment 
        if( wcs_order_contains_subscription( $order ) && $order->get_payment_method() === 'stripe_sepa' ){
    
            // Get an array of WC_Subscription objects
            $subscriptions = wcs_get_subscriptions_for_order( $order_id, array( 'order_type' => 'any' ) );
            foreach( $subscriptions as $subscription_id => $subscription ){
                // Change the status of the WC_Subscription object
                $subscription->update_status( 'active', 'Set active because of SEPA.', false );
            }
        }
    }
    
    Plugin Author Clayton R

    (@mrclayton)

    Hi @dziuba,

    Hmm that’s interesting. I recommend you hook in to filter woocommerce_payment_complete_order_status and return completed for the order status.

    You may have a 3rd party plugin that is affecting the order status during the payment complete method call. Is this only for SEPA or for other payment methods?

    Kind Regards,

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Set status to completed after Charge.succeeded is recieved’ is closed to new replies.