Created
June 27, 2019 14:30
-
-
Save nczz/816a3e6a028c3d80832dea6f145483fa to your computer and use it in GitHub Desktop.
[WooCommerce] 顯示訂單資訊的短碼(Shortcode) https://www.mxp.tw/8545/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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