WPITECHWPITECH

    Subscribe to Updates

    Get Latest WordPress Tutorials and Updates

    What's Hot

    12 Best Ecommerce Software in 2021 & in the Future

    July 31, 2021

    Why Is My Canon Printer Not Printing Properly?

    July 31, 2021

    5 Best Google Analytics Plugins

    May 28, 2021
    Facebook Twitter Instagram
    Facebook Twitter Instagram
    WPITECH WPITECH
    Subscribe
    • Home
    • Tutorials
      • WordPress Tutorials
      • WordPress Plugin
      • WordPress Themes
      • WooCommerce
      • Ecommerce
      • PHP
    • Hosting
    • Deals
      • Hosting Deals
    • SEO TOOLS
      • Bulk Url Checker
      • Structured Data
      • Google Cache
      • Hyperlink Generator
      • Free URL Checker
    • Marketing
      • SEO
      • Advertising
    • Reviews
    • Write for Us
    • About Us
    WPITECHWPITECH
    Home » How to Change WooCommerce Payment Status for Prepaid Orders
    WooCommerce

    How to Change WooCommerce Payment Status for Prepaid Orders

    WPITECHBy WPITECHOctober 12, 2019No Comments3 Mins Read
    Facebook Twitter Pinterest LinkedIn Tumblr Email
    How to Change WooCommerce Payment Status
    Share
    Facebook Twitter LinkedIn Pinterest Email

    WooCommerce payment status management is an important online store operation that could take a lot of time to process. That’s why it is necessary that all the orders should be updated automatically to show the most recent status.

    Cash-on-Delivery is the most demanding option that no WooCommerce store owners can overlook. There are several scenarios where customers want to pre-pay for their online purchases to speed up the order fulfillment process. In some cases, the order has been fulfilled and delivered to the customer but the payment status for the order not updated.

    How to Update WooCommerce Payment Status Automatically

    You can simply automate the whole process of payment status update for orders that are pre-paid. The orders updated to “Complete” automatically when the WooCommerce payment status will be updated.

    add_action('woocommerce_order_payment_status_changed', 'woocommerce_payment_complete_order_status',10,3);
    function woocommerce_payment_complete_order_status($order_id)
    {
        if ( ! $order_id ) {
            return;
        }
        $order = wc_get_order( $order_id );
        if ($order->data['status'] == 'wc-processing') {
            $payment_method=$order->get_payment_method();
            if ($payment_method != "cod")
            {
                $order->update_status( 'wc-completed' );
            }
        }
    }
    

    The above code uses the woocommerce_order_payment_status_changed hook to call in the function when the WooCommerce order status gets changed. Once the order status is “Processing” and the payment method is not Cash-on-Delivery, the status changed to “Complete”

    update_status() sets the order payment status that is passed to the woocommerce_order_payment_status_changed method. Here is a detailed list of the WooCommerce payment status you can pass to this method:

    <option value=”wc-on-hold”>On hold</option>
    
    <option value=”wc-completed”>Completed</option>
    
    <option value=”wc-pending”>Pending payment</option>
    
    <option value=”wc-processing”>Processing</option>
    
    <option value=”wc-cancelled”>Cancelled</option>
    
    <option value=”wc-refunded”>Refunded</option>
    
    <option value=”wc-failed”>Failed</option>
    

    wc_get_order() is a wrapper function to get the data about a specific order and $order gets the order information as an object through wc_get_order() function. You can also use the following code to get the total order.

    $order->get_id();
    
    $order->get_formatted_order_total( );
    
    

    If you have selected “Cash on delivery” payment method then the checkout page shown as:

    Cash on delivery WooCommerce payment status

    After the order processed you will see

    WooCommerce complte order payment status

    Display WooCommerce Order Product Information

    Adding the below code snippet will display the products in an order. You have to place this code in the template file where you want to display the information.

    $filters = array(
    'post_status' => 'any',
    'post_type' => 'shop_order',
    'orderby' => 'modified',
    'order' => 'ASC'
    );
    $loop = new WP_Query($filters);
    while ($loop->have_posts()) {
    $loop->the_post();
    $order = new WC_Order($loop->post->ID);
    foreach ($order->get_items() as $key => $lineItem) {
    echo '<br>' . 'Product Name : ' . $lineItem['name'];
    echo 'Product ID : ' . $lineItem['product_id'];
    if ($lineItem['variation_id']) {
    echo 'Product Type : Variable Product';
    } else {
    echo 'Product Type : Simple Product';
    }
    }
    }
    

    If you want to change the WooCommerce order status based on the order status then there is a short tutorial on WooCommerce order status.

    WooCommerce change payment status WooCommerce payment status
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    WPITECH

    Related Posts

    5 Best WooCommerce Affiliate Plugins

    January 3, 2020

    How to Customize Add to Cart Button in WooCommerce

    October 21, 2019

    How to Customize WooCommerce Product Variations

    October 13, 2019
    Add A Comment

    Leave A Reply Cancel Reply

    Recent Posts
    • 12 Best Ecommerce Software in 2021 & in the Future
    • Why Is My Canon Printer Not Printing Properly?
    • 5 Best Google Analytics Plugins
    • 12 Best Email List Building Tools in 2021
    • 9 Amazing Benefits of Using WordPress for Your Projects
    Recent Comments
    • 20+ Top Ecommerce Marketing Agencies To Hire for 2020 on Conversion Rate Optimization Tips to Improve Conversions and Increase Revenue
    • Hottest B2B Content Marketing Trends and Statistics in 2019 on The Ultimate Guide to Broken Link Building 2020
    • Digital Chetan on SEO 2020 Google RankBrain Algorithm GUIDE
    Editors Picks
    Top Reviews
    Advertisement
    Demo
    Facebook Twitter Instagram Pinterest Vimeo YouTube
    • Home
    © 2022 All rights reserved

    Type above and press Enter to search. Press Esc to cancel.