Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[WooCommerce] 顯示訂單資訊的短碼(Shortcode) https://www.mxp.tw/8545/
<?php
function woocommerce_orders() {
$user_id = get_current_user_id();
if ($user_id == 0) {
//沒登入就呼叫用戶後台的標準短碼
return do_shortcode('[woocommerce_my_account]');
} else {
ob_start();
//登入的用戶就撈 orders 的樣板來顯示訂單資料
wc_get_template('myaccount/my-orders.php', array(
'current_user' => get_user_by('id', $user_id),
'order_count' => $order_count,
));
return ob_get_clean();
}
}
add_shortcode('woocommerce_orders', 'woocommerce_orders');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.