title: Woocommerce Doesn't cancel orders on hold status
body: <p>I Need to cancel the on-hold orders in a certain scenario after 4 hours from creating the order.</p>
  
  <p>Example: 2 Customers</p>
  
  <p>1st Customer Make Order at 5:00 PM so its on-hold status ( i want it to be canceled after 4 hours from the creation date of the order if he didn't pay so it has to be canceled on 9:00 PM )</p>
  
  <p>2nd Customer Make Order at 5:37 so Its on-hold status ( i want it to be canceled after 4 hours too from the creation date of the order if he didn't pay so it has to be canceled on 9:37 )</p>
  
  <p>I want it to cancel the orders immediately after each order is expired after 4 hours from the creation date of the order separately not as a cron job to work each 4 hours so in the previous example if the cron event starts at 6:00 PM and will run each 4 hours so the first customer order will expire on 10:00 PM and the 2nd will expire on 10:00 PM too.</p>
  
  <p>I have tried the solution here <a href="https://stackoverflow.com/questions/55792360/automatically-cancel-order-after-x-days-if-no-payment-in-woocommerce">Automatically cancel order after X days if no payment in WooCommerce</a></p>
  
  <p>but couldn't make it expire after 4 hours as its defined in days only, also didn't know which answer of them is the best for me scenario to run for each order to be canceled separately after 4 hours from the creation date not as a cron event, </p>
  
  <p>I used many of the solutions mentioned in the related question above but only that works the first answer as i remember which is when admin/shop manager visits the orders page .. i need it to be done automatically without any actions from humans.</p>
  
  <p>Here is my code in the plugin to cancel the orders</p>
  
  <pre><code>&lt;?php
  
  
  function ash2osh_faw_get_unpaid_submitted() {        
          global $wpdb;
            $options = get_option('woocommerce_' . ASH2OSH_FAW_PAYMENT_METHOD . '_settings');
          $expire_hours =  $options['unpaid_expire'];
          if(!trim($expire_hours)){
              $expire_hours='48';
          }
          $unpaid_submitted = $wpdb-&gt;get_col( $wpdb-&gt;prepare( "
                  SELECT posts.ID
                  FROM {$wpdb-&gt;posts} AS posts
                  WHERE posts.post_status = 'wc-on-hold'
                  AND posts.post_date &lt; %s
          ", date( 'Y-m-d H:i:s', strtotime('-'.$expire_hours.' hours') ) ) ); 
  
          return $unpaid_submitted;
  }
  
  function ash2osh_faw_wc_cancel_unpaid_submitted() {        
          $unpaid_submit = ash2osh_faw_get_unpaid_submitted();
  
          if ( $unpaid_submit ) {                
                  foreach ( $unpaid_submit as $unpaid_order ) {                        
                          $order = wc_get_order( $unpaid_order );
                          $cancel_order = True;
  
                          foreach  ( $order-&gt;get_items() as $item_key =&gt; $item_values) {                                
                                  $manage_stock = get_post_meta( $item_values['variation_id'], '_manage_stock', true );
                                  if ( $manage_stock == "no" ) {                                        
                                          $payment_method = $order-&gt;get_payment_method();                                        
                                          if ( $payment_method == "cheque" ) {
                                                  $cancel_order = False;
                                          }
                                  }                                
                          }
                          if ( $cancel_order == True ) {
                                  $order -&gt; update_status( 'cancelled', __( 'Unpaid submission expired after hours set in payment plugin options.', 'woocommerce') );
                          }
                  }
          }        
  }
  add_action( 'woocommerce_cancel_unpaid_submitted', 'ash2osh_faw_wc_cancel_unpaid_submitted' );//for customization purposes
  </code></pre>
  
  <p><strong>This third solution here: <a href="https://stackoverflow.com/questions/55792360/automatically-cancel-order-after-x-days-if-no-payment-in-woocommerce">Automatically cancel order after X days if no payment in WooCommerce</a> is tested and works fine: BUT i want it to be canceled when the order is on-hold status not completed/processing and to be canceled if its passed 4 hours after the order creation date and this to be scheduled and run each 30 min not daily</strong></p>