1

How can I get the endpoint's contents of my-account page in WooCommerce? for example: i want to show the content for each endpoints in custom tabs the below code just give me the endpoints and slug. is there ways to get contents too?

   <?php foreach ( wc_get_account_menu_items() as $endpoint => $label ) : ?>
        <li class="<?php echo wc_get_account_menu_item_classes( $endpoint ); ?>">
            <a href="<?php echo esc_url( wc_get_account_endpoint_url( $endpoint ) ); ?>"><?php echo esc_html( $label ); ?></a>
        </li>
    <?php endforeach; ?>
James Z
  • 12,209
  • 10
  • 24
  • 44
Behzad
  • 75
  • 1
  • 7

1 Answers1

1
add_shortcode('my_account_section', 'shortcode_my_account_section');

function shortcode_my_account_section($atts) {
    extract(shortcode_atts(['section' => ''], $atts));
    ob_start();
    do_action('woocommerce_account_' . $section . '_endpoint');
    return ob_get_clean();
}

Add the above code snippet to your active theme functions.php

You can then use the below shortcodes to render it anywhere in the fronetnd.

[my_account_section section="orders"]
[my_account_section section="edit-address"]
[my_account_section section="edit-account"]
[my_account_section section="payment-methods"]
[my_account_section section="downloads"]
mujuonly
  • 11,370
  • 5
  • 45
  • 75
  • kindly thank you dear @mujuonly. is this way works for my-account others endpoints too? i get array of my-account menu item keys and by foreach method want to show content of them too – Behzad Feb 20 '23 at 15:31
  • @Behzad Which ae the other endpoints you are mentioning.? BTW you can accept if the answer was helpful :) – mujuonly Feb 20 '23 at 15:47
  • by this issue well done @mujuonly Thank you so much. how can i get menu 3 slug? $mslugs=wc_get_account_menu_items() foreach($mslugs as $mslug) $endpoint3=mslug[03] but not work – Behzad Feb 20 '23 at 16:14
  • @Behzad Checkout the updated shortcode for more endpoints – mujuonly Feb 20 '23 at 16:32
  • Dear @mujuonly the code work well, and also return all my endpoints content, even the unofficial (custom) endpoints too. but its not show sub endpoints. for ex: it shows the orders, but if you wannat click on order #123, doing nothing. in other ways refreshing the same page. if you mind i can give a page that now the code running on it. maybe you can get my point beter – Behzad Feb 20 '23 at 16:45