Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to new WooCommerce my account custom tab with custom content

How can i add new endpoints to WooCommerce my account menu and show my custom content with below array? endpoint=custom_endpoint, lable=endpoint lable, icon=any icon
just the below code return 404 eror

// Enable endpoint
add_filter( 'woocommerce_get_query_vars', 'myaccount_custom_endpoint_query_var' );
function myaccount_custom_endpoint_query_var( $query_vars ) {
    $query_vars['custom-endpoint'] = 'custom-endpoint';

    return $query_vars;
}

// Endpoint displayed content
add_action('woocommerce_account_custom-endpoint_endpoint', 'display_custom_endpoint_content' ); 
function display_custom_endpoint_content(){
    echo '<p>' . __("hello") . '</p>';
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

May be following code will be helpful. Make Sure Save Permalinks after adding this code.

/**
 * Register New Endpoint.
 *
 * @return void.
 */
function register_new_item_endpoint() {
    add_rewrite_endpoint( 'new-item', EP_ROOT | EP_PAGES );
}
add_action( 'init', 'register_new_item_endpoint');



/**
 * Add new query var.
 *
 * @param array $vars vars.
 *
 * @return array An array of items.
 */
function new_item_query_vars( $vars ) {

    $vars[] = 'new-item';
    return $vars;
}
add_filter( 'query_vars', 'new_item_query_vars' );


/**
 * Add New tab in my account page.
 *
 * @param array $items myaccount Items.
 *
 * @return array Items including New tab.
 */
function add_new_item_tab( $items ) {

    $items['new-item'] = 'New Menu';
    return $items;
}
add_filter( 'woocommerce_account_menu_items', 'add_new_item_tab' );


/**
 * Add content to the new tab.
 *
 * @return  string.
 */
function add_new_item_content() {
    echo 'New Contents here!';
}
add_action( 'woocommerce_account_new-item_endpoint', 'add_new_item_content' );
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading