wordpress 在woocommerce中,是否有查看所有订单的短代码/页面?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29980505/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
in woocommerce, is there a shortcode/page to view all orders?
提问by dave
I'm using the plugin woocommerce for my wordpress site, and need a section where member can see their order history. Are there any shortcodes or page in woocommerce that shows the order history of a member?
我正在为我的 wordpress 网站使用插件 woocommerce,并且需要一个部分,成员可以在其中查看他们的订单历史记录。woocommerce 中是否有任何短代码或页面可以显示会员的订单历史记录?
回答by d79
My Accountshortcode:
我的帐户简码:
[woocommerce_my_account order_count="-1"]
Shows the ‘my account' section where the customer can view past orders and update their information. You can specify the number or order to show, it's set by default to 15 (use -1to display all orders.)
显示“我的帐户”部分,客户可以在其中查看过去的订单并更新他们的信息。您可以指定要显示的数量或订单,默认设置为 15(使用-1显示所有订单。)
Reference: Woocommerce Shortcodes
Update
更新
If you need only the orders I don't know if there's already a shortcode, but I made one taking woocommerce_my_account as example:
如果您只需要订单,我不知道是否已经有简码,但我以 woocommerce_my_account 为例制作了一个:
function shortcode_my_orders( $atts ) {
extract( shortcode_atts( array(
'order_count' => -1
), $atts ) );
ob_start();
wc_get_template( 'myaccount/my-orders.php', array(
'current_user' => get_user_by( 'id', get_current_user_id() ),
'order_count' => $order_count
) );
return ob_get_clean();
}
add_shortcode('my_orders', 'shortcode_my_orders');
Add this to your functions.phpfile and then use it like [my_orders order_counts=10](order_countsis optional, if missing it lists all the orders).
将它添加到您的functions.php文件中,然后像使用[my_orders order_counts=10](order_counts是可选的,如果缺少它会列出所有订单)。
回答by A.Sh
I was reading about extract and apparently its not recommended by Wordpress anymore. I found this soloution, hope this helps:
我正在阅读有关提取物的内容,显然 Wordpress 不再推荐它了。我找到了这个解决方案,希望这有帮助:
function shortcode_my_orders( $atts ) {
$args= shortcode_atts(
array(
'order_count' => -1
),
$atts
);
$order_count = esc_attr( $args['order_count'] );
ob_start();
wc_get_template( 'myaccount/my-orders.php', array(
'current_user' => get_user_by( 'id', get_current_user_id() ),
'order_count' => $order_count
) );
return ob_get_clean();
}
}

