Question: I need to show in the each post his parent category and sub category, at the moment I use this code:

```
<?php
$categories = get_the_category();

echo 'Parent Category: <a href="' . esc_url( get_category_link( $categories[0]->term_id ) ) . '">' . esc_html( $categories[0]->name ) . '</a> \n';

echo 'Sub Category: <a href="' . esc_url( get_category_link( $categories[1]->term_id ) ) . '">' . esc_html( $categories[1]->name ) . '</a>';
?>

```

The problem is that this code gives categories[0] and categories[1] values based on their order. In some post the order is Parent -> Sub, in others is Sub -> Parent (don't know why). So when I access $categories[1] in some posts I get the parent instead of the sub.

Answer: 
do the following code in your child theme function.php file as given below.

```
function wc_remove_cancelled_status( $statuses ){
  if( isset( $statuses['wc-cancelled'] ) ){
      unset( $statuses['wc-cancelled'] );
  }
  return $statuses;
} 
add_filter( 'wc_order_statuses', 'wc_remove_cancelled_status' );

```
Hmm... If we use your script, I think if you save the time like: 

```
<?php
function update_order_status( $order_id ) {
$order = new WC_Order( $order_id );
$order_status = $order->get_status();

if ('cancelled' == $order_status || 'failed' == $order_status ||   'pending' == $order_status ) { 
        $current_time = date('h:i:s');    /* this is not necessary - not being used. */

        sleep(300);       // 300 seconds in 5 minutes

        wp_delete_post($order_id,true);    
   }    

}

```

Look, I don't know if this will work, but it's worth a try.