在 woocommerce 中,是否有 shortcode/page 来查看所有订单?

in woocommerce, is there a shortcode/page to view all orders?

我正在为我的 wordpress 网站使用插件 woocommerce,并且需要一个会员可以查看其订单历史记录的部分。 woocommerce 中是否有显示会员订单历史记录的短代码或页面?

我的账户简码:

[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 -1 to display all orders.)

参考:Woocommerce Shortcodes


更新

如果你只需要订单我不知道是否已经有简码,但我以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');

将此添加到您的 functions.php 文件中,然后像 [my_orders order_counts=10] 一样使用它(order_counts 是可选的,如果缺少它会列出所有订单)。

我正在阅读有关 extract 的内容,显然 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();

}