[SUPPORT NOTICE] We will close from 27 April to 01 May to celebrate our Reunification Day and Labor Day!

Cart

Prevent order go to processing status if condition is true

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #9921
    loictheaztec
    Participant

    You can try the following for Cash on delivery (COD) payment method, replacing in the code both 'my_variable' with the correct slug:

    add_filter( 'woocommerce_cod_process_payment_order_status', 'conditionally_change_cod_order_status_to_pending', 10, 2 );
    function conditionally_change_cod_order_status_to_pending( $status, $order ) {
        $global_var = $GLOBALS; 
    
        if ( isset($global_var['my_variable']) && $global_var['my_variable'] ) {
            return 'pending';
        }
        return $status;
    }
    

    Code goes in functions.php file of your child theme (or in a plugin). It should work.

    #9920
    alench
    Participant

    I tried many scenarios and hooks and at the end even in child template file for thankyou page

    So if order is not failed and global variable == true switch to pending:

    <?php if ($order->has_status('failed')) : ?>
    
    //code
    
    <?php else : ?>
    
    <?php if ($GLOBALS['variable'] == true) : ?>
    
    
        <?php $order->update_status('pending'); ?>
    
    
    <?php endif; ?>
    

    Status is changing but the problem is that it is going from processing to pending. How to prevent going to processing status if condition ($GLOBALS[‘variable’]) is true?

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.