• Resolved Dana Harrison

    (@danaharrison)


    Hi all,

    I’m looking for a plugin or something that would allow me to auto-expire an On Hold order with certain payment methods. We expect our users to pay within two days, and want to expire orders (even for stuff where stock is unlimited) that haven’t been paid (but have been submitted) after those two days.

    Any such plugins or ideas? I’ve been searching and searching with no success so far.

    WordPress environment
    Home URL:		-REDACTED-
    Site URL:		-REDACTED-
    WC version:		3.2.1
    Log directory writable:		 /var/www/html/wordpress/wp-content/uploads/wc-logs/
    WP version:		4.8.2
    WP multisite:		–
    WP memory limit:		256 MB
    WP debug mode:		
    WP cron:		
    Language:		en_CA
    Server environment
    Server info:		Apache/2.4.6 (Red Hat Enterprise Linux) OpenSSL/1.0.2k-fips PHP/5.4.16
    PHP version:		 5.4.16 - We recommend a minimum PHP version of 5.6. See: How to update your PHP version
    PHP post max size:		30 MB
    PHP time limit:		30
    PHP max input vars:		1000
    cURL version:		7.29.0, NSS/3.28.3
    SUHOSIN installed:		–
    Max upload size:		30 MB
    Default timezone is UTC:		
    fsockopen/cURL:		
    SoapClient:		 Your server does not have the SoapClient class enabled - some gateway plugins which use SOAP may not work as expected.
    DOMDocument:		
    GZip:		
    Multibyte string:		
    Remote post:		
    Remote get:		
    Database
    WC database version:		3.2.1
    Database prefix	 	wp_
    Total Database Size	 	4.03MB
    Database Data Size	 	3.04MB
    Database Index Size	 	0.99MB
    wp_woocommerce_sessions	 	Data: 0.02MB + Index: 0.02MB
    wp_woocommerce_api_keys	 	Data: 0.02MB + Index: 0.03MB
    wp_woocommerce_attribute_taxonomies	 	Data: 0.02MB + Index: 0.02MB
    wp_woocommerce_downloadable_product_permissions	 	Data: 0.02MB + Index: 0.05MB
    wp_woocommerce_order_items	 	Data: 0.02MB + Index: 0.02MB
    wp_woocommerce_order_itemmeta	 	Data: 0.02MB + Index: 0.03MB
    wp_woocommerce_tax_rates	 	Data: 0.02MB + Index: 0.06MB
    wp_woocommerce_tax_rate_locations	 	Data: 0.02MB + Index: 0.03MB
    wp_woocommerce_shipping_zones	 	Data: 0.02MB + Index: 0.00MB
    wp_woocommerce_shipping_zone_locations	 	Data: 0.02MB + Index: 0.03MB
    wp_woocommerce_shipping_zone_methods	 	Data: 0.02MB + Index: 0.00MB
    wp_woocommerce_payment_tokens	 	Data: 0.02MB + Index: 0.02MB
    wp_woocommerce_payment_tokenmeta	 	Data: 0.02MB + Index: 0.03MB
    wp_woocommerce_log	 	Data: 0.02MB + Index: 0.02MB
    wp_awpcp_adfees	 	Data: 0.00MB + Index: 0.00MB
    wp_awpcp_admeta	 	Data: 0.00MB + Index: 0.00MB
    wp_awpcp_ads	 	Data: 0.00MB + Index: 0.00MB
    wp_awpcp_ad_regions	 	Data: 0.00MB + Index: 0.00MB
    wp_awpcp_categories	 	Data: 0.00MB + Index: 0.00MB
    wp_awpcp_credit_plans	 	Data: 0.00MB + Index: 0.00MB
    wp_awpcp_media	 	Data: 0.00MB + Index: 0.00MB
    wp_awpcp_payments	 	Data: 0.00MB + Index: 0.00MB
    wp_awpcp_tasks	 	Data: 0.00MB + Index: 0.00MB
    wp_aws_index	 	Data: 0.02MB + Index: 0.00MB
    wp_commentmeta	 	Data: 0.02MB + Index: 0.03MB
    wp_comments	 	Data: 0.02MB + Index: 0.09MB
    wp_links	 	Data: 0.02MB + Index: 0.02MB
    wp_options	 	Data: 2.05MB + Index: 0.05MB
    wp_pollsa	 	Data: 0.02MB + Index: 0.00MB
    wp_pollsip	 	Data: 0.02MB + Index: 0.05MB
    wp_pollsq	 	Data: 0.02MB + Index: 0.00MB
    wp_postmeta	 	Data: 0.17MB + Index: 0.14MB
    wp_posts	 	Data: 0.28MB + Index: 0.06MB
    wp_termmeta	 	Data: 0.02MB + Index: 0.03MB
    wp_terms	 	Data: 0.02MB + Index: 0.03MB
    wp_term_relationships	 	Data: 0.02MB + Index: 0.02MB
    wp_term_taxonomy	 	Data: 0.02MB + Index: 0.03MB
    wp_usermeta	 	Data: 0.02MB + Index: 0.03MB
    wp_users	 	Data: 0.02MB + Index: 0.05MB
    Post Type Counts
    advert	 	4
    attachment	 	13
    custom_css	 	1
    customize_changeset	 	2
    faq	 	12
    faqconc	 	2
    listing	 	2
    nav_menu_item	 	14
    page	 	13
    post	 	4
    product	 	6
    product_variation	 	13
    revision	 	79
    shop_order	 	2
    tribe_events	 	3
    wpcf7_contact_form	 	3
    wpcf7s	 	22
    Security
    Secure connection (HTTPS):		
    Hide errors from visitors		
    Active plugins (21)
    Query Monitor	 	by John Blackbourn – 2.15.0
    Admin Custom Login	 	by Weblizar – 2.5.4
    Adminimize	 	by Frank Bültge – 1.11.2
    Advanced Woo Search	 	by ILLID – 1.25 – Not tested with the active version of WooCommerce
    Arconix FAQ	 	by John Gardner – 1.7.0
    Contact Form 7 Conditional Fields	 	by Jules Colle – 1.3.4
    Contact Form 7	 	by Takayuki Miyoshi – 4.7
    Contact Form Submissions	 	by Jason Green – 1.5.6
    FAQ Concertina	 	by Michael Burridge, Zyriab Ltd. – 1.4.3
    Hide This	 	by Andrés Villarreal – 1.1.3
    Import users from CSV with meta	 	by codection – 1.10.7.2
    Collapse-O-Matic	 	by twinpictures, baden03 – 1.7.6
    Nav Menu Roles	 	by Kathy Darling – 1.8.6
    Post My CF7 Form	 	by Aurovrata V. – 2.0.3
    The Events Calendar	 	by Modern Tribe, Inc. – 4.6.1
    WooCommerce Hide Checkout Shipping Address	 	by Web Whales – 1.3 – Not tested with the active version of WooCommerce
    WooCommerce Max Quantity	 	by Isabel Castillo – 1.5 – Not tested with the active version of WooCommerce
    WooCommerce Services	 	by Automattic – 1.8.1 – Not tested with the active version of WooCommerce
    WooCommerce	 	by Automattic – 3.2.1
    WP-Polls	 	by Lester 'GaMerZ' Chan – 2.73.7
    WP Adverts	 	by Greg Winiarski – 1.1.6
    Settings
    API enabled:		
    Force SSL:		–
    Currency		CAD ($)
    Currency position		left
    Thousand separator		,
    Decimal separator		.
    Number of decimals		2
    Taxonomies: Product types		external (external), grouped (grouped), simple (simple), variable (variable)
    Taxonomies: Product visibility		exclude-from-catalog (exclude-from-catalog), exclude-from-search (exclude-from-search), featured (featured), outofstock (outofstock), rated-1 (rated-1), rated-2 (rated-2), rated-3 (rated-3), rated-4 (rated-4), rated-5 (rated-5)
    WC pages
    Shop base:		#27 - /shop/
    Cart:		#28 - /cart/
    Checkout:		#29 - /checkout/
    My account:		#30 - /my-account/
    Terms and conditions:		 Page not set
    Theme
    Name:		Spacious
    Version:		1.4.7 – 1.4.8 is available
    Author URL:		https://themegrill.com
    Child theme:		 – If you are modifying WooCommerce on a parent theme that you did not build personally we recommend using a child theme. See: How to create a child theme
    WooCommerce support:		
    Templates
    Overrides:	 	–
Viewing 7 replies - 1 through 7 (of 7 total)
  • Hi,
    I need your clothes, your boots and your motorcycle your website address and the specific methods you want to expire.

    Plugin Support Hannah S.L.

    (@fernashes)

    Automattic Happiness Engineer

    We haven’t heard back from you in a while, so I’m going to mark this as resolved – if you have any further questions, you can start a new thread.

    Thread Starter Dana Harrison

    (@danaharrison)

    In case anyone else searches this: I wrote a function and added it to CRON.

    danielgbr

    (@danielgbr)

    Hey @danaharrison,

    Would LOVE to see how you did this! Been looking high and low for something like this

    Thread Starter Dana Harrison

    (@danaharrison)

    Here you go, @danielgbr. After adding this to my child theme’s functions.php, I was able to add this action to WP-Cron with my Cron plugin of choice.

    What this will do is get all of the unpaid, submitted orders older than two days (wc-on-hold status), iterate them, and – in our case, if the payment method is not Cheque – cancel the order. I also added additional filtering for whether or not the items are managed or unmanaged stock, but this should give you a baseline.

    function get_unpaid_submitted() {        
            global $wpdb;
            
            $unpaid_submitted = $wpdb->get_col( $wpdb->prepare( "
                    SELECT posts.ID
                    FROM {$wpdb->posts} AS posts
                    WHERE posts.post_status = 'wc-on-hold'
                    AND posts.post_date < %s
            ", date( 'Y-m-d H:i:s', strtotime('-2 days') ) ) );
            
            return $unpaid_submitted;
    }
    
    function wc_cancel_unpaid_submitted() {        
            $unpaid_submit = get_unpaid_submitted();
            
            if ( $unpaid_submit ) {                
                    foreach ( $unpaid_submit as $unpaid_order ) {                        
                            $order = wc_get_order( $unpaid_order );
                            $cancel_order = True;
    
                            foreach  ( $order->get_items() as $item_key => $item_values) {                                
                                    $manage_stock = get_post_meta( $item_values['variation_id'], '_manage_stock', true );
                                    if ( $manage_stock == "no" ) {                                        
                                            $payment_method = $order->get_payment_method();                                        
                                            if ( $payment_method == "cheque" ) {
                                                    $cancel_order = False;
                                            }
                                    }                                
                            }
                            if ( $cancel_order == True ) {
                                    $order -> update_status( 'cancelled', __( 'Unpaid submission expired after two days.', 'woocommerce') );
                            }
                    }
            }        
    }
    add_action( 'woocommerce_cancel_unpaid_submitted', 'wc_cancel_unpaid_submitted' );
    danielgbr

    (@danielgbr)

    Thanks for replying! I’m going to test this out. Just a question.. if I want to change the cancelation to like 9 days, i would chage this:

    strtotime('-2 days') ) ) );

    to strtotime('-9 days') ) ) );

    correct?

    Thread Starter Dana Harrison

    (@danaharrison)

    Correct!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Expiring ‘on hold’ cheque orders after X days’ is closed to new replies.