Woocommerce - 如何在单独的页面上显示订单详细信息(我的帐户) [英] Woocommerce - How to show Order details (my-account) on a separate page

查看:74
本文介绍了Woocommerce - 如何在单独的页面上显示订单详细信息(我的帐户)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,在 woocommerce 中,短代码 [woocommerce_my_account] 显示整个我的帐户"页面以及所有选项卡选项.

Right now, in woocommerce the shortcode [woocommerce_my_account] displays the entire "My Account" page with all the tabbed options.

我只想在单独的页面上显示订单详细信息(位于订单"标签下).

I only want to show the order details (found under the Orders tab) on a separate page.

那么,我可以只使用 woocommerce 模板 orders.php (woocommerce/templates/myaccount/orders.php) 并在空白的新页面上使用它,还是有更好的方法它吗?

So, can I just use the woocommerce template orders.php (woocommerce/templates/myaccount/orders.php) and use it on a blank new page or is there a better way to go about it?

推荐答案

Woocommerce 有函数 woocommerce_account_orders() ,其中包含 Orders 模板.您可以按照以下步骤在单独的页面上仅显示订单.

Woocommerce has function woocommerce_account_orders() which includes Orders template. You can follow the below steps to display only orders on a separate page.

第 1 步:将以下代码放在您主题的functions.php 中(如果您已创建,请放在子主题中).

Step-1: Place below code in your theme's functions.php (Place in child theme if you have created).

function woocommerce_orders() {
    $user_id = get_current_user_id();
    if ($user_id == 0) {
         return do_shortcode('[woocommerce_my_account]'); 
    }else{
        ob_start();
        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');

第 2 步:在管理端的任何页面中放置短代码 [woocommerce_orders] 并检查前端.

Step-2: Place shortcode [woocommerce_orders] in any pages in admin side and check on front end.

如果客户已登录,上面的代码将显示订单,否则将显示 woocommerce 的登录/注册页面.

Above Code will display orders if customer is loggedin otherwise it will display woocommerce's login/registration page.

如果您想隐藏我的帐户"页面上的订单"选项卡,请转到管理端,然后Woocommerce > 设置 > 帐户(选项卡)在那里您可以看到我的帐户端点",那里的订单"字段为空.它将隐藏前端我的帐户"页面中的订单".

If you want to hide "Orders" tabbed option which is on "My Account" Page then go to Admin Side and then Woocommerce > Settings > Accounts (tab) where you can see "My account endpoints", empty "orders" field there. It will hide "Orders" from frontend "My Account" page.

确保您检查前端以客户"用户身份登录,并且该客户用户至少下过一个订单,否则会在那里显示空白页面.

Make sure that you check on frontend loggedin as "Customer" user and that customer user has atleast one order placed otherwise blank page will display there.

这篇关于Woocommerce - 如何在单独的页面上显示订单详细信息(我的帐户)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆