Skip to content

Instantly share code, notes, and snippets.

@nczz
Created June 27, 2019 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nczz/816a3e6a028c3d80832dea6f145483fa to your computer and use it in GitHub Desktop.
Save nczz/816a3e6a028c3d80832dea6f145483fa to your computer and use it in GitHub Desktop.
[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