FIrst Add the PHP code in code snippets and then use these shortcode to display anywhere.
I have created lot of more shortcodes and main php code. Check here:
🔥 Full List of 40 WooCommerce Shortcodes to show any customer or order data
Detail
Shortcode
Customer Name
[woo_customer_name]
[woo_customer_email]
Order Items List
[woo_order_items]
Order Total
[woo_order_total]
Billing Address
[woo_billing_address]
Shipping Address
[woo_shipping_address]
Order Date
[woo_order_date]
Order Status
[woo_order_statu]
Add this php code to use above shortcodes:
// Make sure WooCommerce is active
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
function get_current_order() {
// Get latest order of current user
$customer_orders = wc_get_orders( array(
'customer_id' => get_current_user_id(),
'limit' => 1,
'orderby' => 'date',
'order' => 'DESC',
) );
return !empty($customer_orders) ? $customer_orders[0] : false;
}
function shortcode_customer_name() {
$order = get_current_order();
return $order ? $order->get_formatted_billing_full_name() : '';
}
add_shortcode('woo_customer_name', 'shortcode_customer_name');
function shortcode_customer_email() {
$order = get_current_order();
return $order ? $order->get_billing_email() : '';
}
add_shortcode('woo_customer_email', 'shortcode_customer_email');
function shortcode_order_items() {
$order = get_current_order();
if ( !$order ) return '';
$items = '';
foreach ( $order->get_items() as $item ) {
$items .= $item->get_name() . ' x' . $item->get_quantity() . '<br>';
}
return $items;
}
add_shortcode('woo_order_items', 'shortcode_order_items');
function shortcode_order_total() {
$order = get_current_order();
return $order ? $order->get_formatted_order_total() : '';
}
add_shortcode('woo_order_total', 'shortcode_order_total');
function shortcode_billing_address() {
$order = get_current_order();
return $order ? nl2br( $order->get_formatted_billing_address() ) : '';
}
add_shortcode('woo_billing_address', 'shortcode_billing_address');
function shortcode_shipping_address() {
$order = get_current_order();
return $order ? nl2br( $order->get_formatted_shipping_address() ) : '';
}
add_shortcode('woo_shipping_address', 'shortcode_shipping_address');
function shortcode_order_date() {
$order = get_current_order();
return $order ? $order->get_date_created()->date('Y-m-d H:i') : '';
}
add_shortcode('woo_order_date', 'shortcode_order_date');
function shortcode_order_status() {
$order = get_current_order();
return $order ? wc_get_order_status_name( $order->get_status() ) : '';
}
add_shortcode('woo_order_status', 'shortcode_order_status');
}
