Category: PHP

Get order date from order id in WooCommerce

You can use the WC_Order object for get order date from order id.
if you have the order ID then use the following code to fetch order date.

$order = new WC_Order($order_id);
$order_date = $order->order_date;

Have any doubt, then comment here!

Get all orders of a single customer in WooCommerce by user ID

You can fetch all WooCommerce orders of a single customer by different parameter.
Here you can find all WooCommerce orders of a customer by user id.
Use the following to fetch all orders of a single customer in WooCommerce by user ID.
You have to replace customer id instead of ‘CUSTOMER_USER_ID_HERE’.

$user_id='CUSTOMER_USER_ID_HERE';
$customer_orders = get_posts( array(
                    'meta_key'    => '_customer_user',
                    'meta_value'  => $user_id,
                    'post_type'   => 'shop_order',
                    'post_status' => array_keys( wc_get_order_statuses() ),
                    'numberposts' => -1
                ));

Have any doubt, then comment here!

Get all orders of a single customer in WooCommerce by email ID

You can fetch all WooCommerce orders of a single customer by different parameter.
Here you can find all orders of a customer by email id.
Use the following to fetch all orders of a single customer in WooCommerce by email ID.
You have to replace customer email id instead of ‘CUSTOMER_EMAIL_ID_HERE’.

$billing_email='CUSTOMER_EMAIL_ID_HERE';
$customer_orders = get_posts( array(
                    'meta_key'    => '_billing_email',
                    'meta_value'  => $billing_email,
                    'post_type'   => 'shop_order',
                    'post_status' => array_keys( wc_get_order_statuses() ),
                    'numberposts' => -1
                ));

Have any doubt, then comment here!

Get All WooCommerce Orders for a Customer

There are several ways to get all WooCommerce Orders for a Customer.
Here you can get all Woocommerce orders for a customer by customer email id.
Use the following code to fecth WooCommerce orders for a customer.
The following code will fecth all orders for a current user.

$customer_orders = get_posts( array(    
    'meta_key'    => '_customer_user',
    'meta_value'  => get_current_user_id(),
    'post_type'   => 'shop_order',
    'post_status' => array_keys( wc_get_order_statuses() ),
    'numberposts' => -1
) );

Have any doubt, then comment here!

How to change default product visibility in woocommerce

If you want to change default product visibility in woocommerce then add that following code in your functions.php file.
Here instead of “hidden” change your default visibility values.

function filter_woocommerce_product_visibility_default( $visible ) { 
    return "hidden"; 
	//return your default value here
}; 
add_filter( 'woocommerce_product_visibility_default', 'filter_woocommerce_product_visibility_default', 10, 1 );

Have any doubt, then comment here!