:::: MENU ::::
Monthly Archives: June 2021

WooCommerce get all products

Today we talk about WooCommerce or WordPress get all products programmatically. In this tutorial, We focus on how to get all product data. In this example, we focus on getting all product information, information like product status, product type, product id, product title, and product price. You can use the following method to get all product wc_get_products. You can filter status to get products that are published and use limit filter -1 to get all the products.

Let’s start with our example.

$products = wc_get_products( array( 'status' => 'publish', 'limit' => -1 ) );

foreach ( $products as $product ){ 
    echo  $product->get_status();  // Product status
    echo  $product->get_type();  // Product type
    echo  $product->get_id();    // Product ID
    echo  $product->get_title(); // Product title
    echo  $product->get_slug(); // Product slug
    echo  $product->get_price(); // Product price
    echo  $product->get_catalog_visibility(); // Product visibility
    echo  $product->get_stock_status(); // Product stock status
    // product date information
    echo $product->get_date_created()->date('Y-m-d H:i:s');
    echo $product->get_date_modified()->date('Y-m-d H:i:s');
}
Author: Qaisar Satti
Last Modified: June 9, 2021


WooCommerce get order detail

Today we talk about WooCommerce or WordPress get order detail programmatically. In this tutorial, We focus on how to get order data by order id. You need to first get an order id. In this example, we focus on getting order billing information, order shipping information, other order details like order status, order payment method, order shipping method, and order tax information.

Let’s start with our example.

$orderId = 1;
$orderData =   wc_get_order( $orderId );
echo $order_id = $orderData->get_id();
echo $orderParentId = $orderData->get_parent_id();
echo $orderStatus = $orderData->get_status();
echo $orderCurrency = $orderData->get_currency();
echo $orderVersion = $orderData->get_version();

// Order payment details
echo $orderPaymentMethod = $orderData->get_payment_method();
echo $orderPaymentMethodTitle = $orderData->get_payment_method_title();

//Order Shipping details
$orderData->get_shipping_methods();

// Order date information
echo $orderDateCreated = $orderData->get_date_created()->date('Y-m-d H:i:s');
echo $orderDateModified = $orderData->get_date_modified()->date('Y-m-d H:i:s');


echo $orderDiscountTotal = $orderData->get_discount_total();
echo $orderDiscountTax = $orderData->get_discount_tax();
echo $orderShippingTotal = $orderData->get_shipping_total();
echo $orderShippingTax = $orderData->get_shipping_tax();
echo $orderTotal = $orderData->get_total();
echo $orderTotalTax = $orderData->get_total_tax();

//Order Billing Information:

echo $orderBillingFirstName = $orderData->get_billing_first_name();
echo $orderBillingLastName = $orderData->get_billing_last_name();
echo $orderBillingCompany = $orderData->get_billing_company();
echo $orderBillingAddress1 = $orderData->get_billing_address_1();
echo $orderBillingAddress2 = $orderData->get_billing_address_2();
echo $orderBillingCity = $orderData->get_billing_city();
echo $orderBillingState = $orderData->get_billing_state();
echo $orderBillingPostcode = $orderData->get_billing_postcode();
echo $orderBillingCountry = $orderData->get_billing_country();
echo $orderBillingEmail = $orderData->get_billing_email();
echo $orderBillingPhone = $orderData->get_billing_phone();

//Order Shipping Information:
echo $orderShippingFirstName = $orderData->get_shipping_first_name();;
echo $orderShippingLastName = $orderData->get_shipping_last_name();
echo $orderShippingCompany = $orderData->get_shipping_company();
echo $orderShippingAddress1 = $orderData->get_shipping_address_1();
echo $orderShippingAddress2 = $orderData->get_shipping_address_2();
echo $orderShippingCity = $orderData->get_shipping_city();
echo $orderShippingState = $orderData->get_shipping_state();
echo $orderShippingPostcode = $orderData->get_shipping_postcode();
echo $orderShippingCountry = $orderData->get_shipping_country();
Author: Qaisar Satti
Last Modified: June 9, 2021