phpwoocommercehook-woocommerceendpointgetcontent

WooCommerce endpoints content


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; ?>

Solution

  • 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"]