Search code examples
phpwordpresswoocommercehook-woocommerceshortcode

Extract shortcode for each section of "My account" page in WooCommerce


Good evening,

I need to extract the shortcode for each section of "My Account" page in WooCommerce:

  1. Dashboard
  2. Orders
  3. Addresses
  4. Account details
  5. Logout

In have tried this code snippet:

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();
}

With this snippet:

[my_account_section section="orders"]

It works fine but for the other section, no result. Thank you in advance.


Solution

  • Please use the below shortcode to render my-account sections.

    [my_account_section section="orders"]
    [my_account_section section="edit-address"]
    [my_account_section section="edit-account"]