Skip to content

Instantly share code, notes, and snippets.

@git-bhanu
Last active December 4, 2020 13:25
Show Gist options
  • Save git-bhanu/221f49e1afd9538979a213a487a5b9fc to your computer and use it in GitHub Desktop.
Save git-bhanu/221f49e1afd9538979a213a487a5b9fc to your computer and use it in GitHub Desktop.
WooCommerce Learnings resource

This gist will contain all the learnings gathered while working with WooCommerce which we can come back in case of confusion.

WooCommerce Orders Data

All the possible status of WooCoomerce Orders

$order_statuses = array(
    'wc-pending'    => _x( 'Pending payment', 'Order status', 'woocommerce' ),
    'wc-processing' => _x( 'Processing', 'Order status', 'woocommerce' ),
    'wc-on-hold'    => _x( 'On hold', 'Order status', 'woocommerce' ),
    'wc-completed'  => _x( 'Completed', 'Order status', 'woocommerce' ),
    'wc-cancelled'  => _x( 'Cancelled', 'Order status', 'woocommerce' ),
    'wc-refunded'   => _x( 'Refunded', 'Order status', 'woocommerce' ),
    'wc-failed'     => _x( 'Failed', 'Order status', 'woocommerce' ),
);

Use wc_get_order_statuses() which will throw the above array.

WC_Order_Query Sample

$query = new WC_Order_Query( array(
'limit' => -20,
'orderby' => 'date',
'order' => 'DESC',
'return' => 'ids',
));

// Fetch Orders
$orders = $query->get_orders();

// Loop through Order
foreach($orders as $order_id ) {

  // Get Order
  $order = wc_get_order($order_id);

  // Loop in all Order Item
  foreach ($order->get_items() as $item_key => $item ){
    
  }
}

WooCommerce Product Data

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment