Asked  1 Year ago    Answers:  5   Viewed   10 times

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.

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?

 Answers

5

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.

Thursday, April 1, 2021
 
2
add_filter( 'woocommerce_page_title', 'custom_woocommerce_page_title', 15, 1 );

function custom_woocommerce_page_title( $page_title ) {
    if ( is_archive() ) {
        $exists_attr = false;

        foreach ( $_GET as $index => $value ) {
            if ( substr( $index, 0, 3 ) === 'pa_' ) {
                $attr_id = wc_attribute_taxonomy_id_by_name( $index );

                if ( $attr_id === 0 ) {
                    continue;
                }

                if ( ! $exists_attr ) {
                    $exists_attr = true;

                    $page_title .= ' (';
                } else {
                    $page_title .= ', ';
                }

                $page_title .= wc_attribute_label( $index ) . ': ' . esc_html( $value );
            }
        }

        if ( $exists_attr ) {
            $page_title .= ')';
        }
    }

    return $page_title;
}
Thursday, April 1, 2021
 
4

It worked fine after updating the search.php as following,

<?php

get_header();

//Page Title Bar
$pageTitle = 'Search results for: "'.get_search_query().'"';
echo page_title_bar( $pageTitle, get_template_directory_uri().'/framework/assets/images/pg-title-bar.jpg');
?>

<div class="container blog-wrapper page-container">
    <div class="row">
        <div class="col-lg-9 col-md-9 col-sm-12 col-xs-12">
            <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

                <?php
                    // Include Blog Posts List
                    get_template_part('framework/template-parts/post/blog', 'post-list');
                ?>

            <?php endwhile; ?>

            <div class="pagination-wrapper">
                <?php pagination(); ?>
            </div>

            <?php else: ?>
                <h3>No results found for: '<?php echo get_search_query(); ?>'</h3>
            <?php endif; ?>
        </div>

        <div class="col-lg-3 col-md-3 col-sm-12 col-xs-12">
            <?php
                // Include Blog Sidebar
                get_template_part('framework/template-parts/post/blog', 'sidebar');
            ?>
        </div>
    </div>
</div>


<?php get_footer(); ?>

If I get a reasonable and well described answer I can offer the bounty for that answer.

Saturday, May 29, 2021
4

I've actually found the answer to my problem, I used "id" instead of "ID" when accessing the property of the WC_Product object.

Saturday, May 29, 2021
 
2

To get the Order details from the WC_Subscription Object, you will need first to get the parent ID (which is the order ID) using get_parent_id() method:

$order_id = $subscription->get_parent_id();

Then you will get the WC_Order Object from the order Id using:

$order = wc_get_order( $order_id );

Then to get order details: How to get WooCommerce order details

Related:

  • How to get the user ID from a WC_Subscription instance Object
  • How to get the Product ID from a WC_Subscription instance Object
Friday, August 20, 2021
 
Pratik
 
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :