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' );

```
I think the user can can change the order status within five minutes. So I wrote the below code with hook-

```
add_action( 'woocommerce_order_status_failed', 'the_dramatist_woocommerce_auto_delete_order' );
add_action( 'woocommerce_order_status_pending', 'the_dramatist_woocommerce_auto_delete_order' );
add_action( 'woocommerce_order_status_cancelled', 'the_dramatist_woocommerce_auto_delete_order' );

function the_dramatist_woocommerce_auto_delete_order( $order_id ) {
    // 5*60 = 300 seconds. Here 1minute = 60 seconds.
    wp_schedule_single_event(tim() + 300, 'the_dramatist_main_delete_event', $order_id);
}

function the_dramatist_main_delete_event( $order_id ) {
    global $woocommerce;
    $order = new WC_Order( $order_id );
    $order_status = $order->get_status();
    if ( !$order_id )
        return false;
    if ('cancelled' == $order_status || 'failed' == $order_status ||   'pending' == $order_status ) {
        wp_delete_post($order_id,true);
        return true;
    }
    return false;
}

```

Here we are detecting order status change by hook and checking the order status again after wake from sleep. So if the user change the order status with in five minutes then the delete will not occur. Please test it. I've not tested it. Hope that help you.

> 
> P.S. I think `sleep()` function will cause some delay in the WordPress life cycle. So better we use `wp_schedule_single_event` function. So I updated my code.
> 
> 
>