Site logo

Archived topic

Display Woocommerce Endpoint Title in Header Element

3 replies · Started by Kim on October 24, 2019

Viewing posts 1–4 of 4

Hi there, I would like to add a custom header to the my account area of woocommerce and try to display the titel of the current woocommerce endpoint (like "Downloads" etc.). {{post_title}} does not work unfortunately, it only shows "My Account" on every site. Can you provide some help with this?

BR and many thanks :)

Hi there,

hmmm would require custom development for another shortcode to do this, and Woo doesn't make it easy - Try this:

function db_display_current_endpoint() {
    if ( is_account_page() ) {
        $endpoint = WC()->query->get_current_endpoint();
        switch ($endpoint) {
            case "downloads":
                $endpoint_title = "Downloads";
                break;
            case "orders":
                $endpoint_title = "Orders";
                break;
            case "edit-address":
                $endpoint_title = "Addresses";
                break;
            case "edit-account":
                $endpoint_title = "Account";
                break;
            default:
                $endpoint_title = "My Account";
                break;         
        }
        ob_start();
        echo '<h2 class="endpoint-title">' . $endpoint_title . '</h2>';
        return ob_get_clean();
    }
}

add_shortcode( 'current_endpoint', 'db_display_current_endpoint' );

This provides the [current_endpoint] shortcode

You can edit the $endpoint_title variables to display a custom message.

AWESOME! Works perfectly :) Many thanks!

You're welcome

This archived topic is closed to new replies.