Woocommerce - How to show Order details (my-account) on a separate page

后端 未结 1 2133
迷失自我
迷失自我 2021-02-11 08:57

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 th

1条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-11 09:42

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

    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');
    

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

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

    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.

    Edit: 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.

    0 讨论(0)
提交回复
热议问题