0

How do I add multiple custom menu Woo-commerce my account page? this code works but how do i show content for each my custom menus?

function pa_custom_endpoint() {
    foreach(pa_custom_endpoint_keys() as $endpointkey=>$endpointlable){
        add_rewrite_endpoint( $endpointkey, EP_ROOT | EP_PAGES );
    }
}
add_filter( 'query_vars', 'pa_custom_endpoint_query_vars', 0 );

function pa_custom_endpoint_query_vars( $vars ) {
    foreach(pa_custom_endpoint_keys() as $endpointkey=>$endpointlable){
        $vars[] = $endpointkey;
    }
    return $vars;
}
add_filter( 'woocommerce_account_menu_items', 'pa_custom_endpoint_link_my_account' );

function pa_custom_endpoint_link_my_account( $items ) {
    foreach(pa_custom_endpoint_keys() as $endpointkey=>$endpointlable){
        $items[$endpointkey] = $endpointlable;
    }
    return $items;
}
1
  • @tfrommen Thanks
    – Behzad
    Mar 14, 2023 at 14:44

1 Answer 1

-1
    function pa_custom_endpoint_keys() {
    global $wpdb;
    $charset_collate = $wpdb->get_charset_collate();
    $phantom_option  = $wpdb->prefix . 'phantom_option';
    $phantom_menu  = $wpdb->prefix . 'phantom_menu';
    $results=$wpdb->get_results("select * from $phantom_menu");
    $endpointsdata =array();
    foreach($results as $row){
    $endpointsdata[$row->pa_menu_endpoint] = $row->pa_menu_name;
    }
    return $endpointsdata;
}

add_action( 'init', 'pa_custom_endpoint' );
function pa_custom_endpoint() {
    foreach(pa_custom_endpoint_keys() as $endpointkey=>$endpointlable){
        add_rewrite_endpoint( $endpointkey, EP_ROOT | EP_PAGES );
            flush_rewrite_rules(false);
            update_option('pa_permalinks_flushed', 1);
    }

}

add_filter( 'query_vars', 'pa_custom_endpoint_query_vars', 0 );
function pa_custom_endpoint_query_vars( $vars ) {
    foreach(pa_custom_endpoint_keys() as $endpointkey=>$endpointlable){
        $vars[] = $endpointkey;
    }
    return $vars;
}

add_filter( 'woocommerce_account_menu_items', 'pa_custom_endpoint_link_my_account' );
function pa_custom_endpoint_link_my_account( $items ) {
    foreach(pa_custom_endpoint_keys() as $endpointkey=>$endpointlable){
        $items[$endpointkey] = $endpointlable;
    }
    return $items;
}

foreach (pa_custom_endpoint_keys() as $endpointkey => $endpointlable) {
    add_action('woocommerce_account_' . $endpointkey . '_endpoint', 'tabcontent');
}

function tabcontent($endpointlable) {
    global $wp;
    $request = explode('/', $wp->request);
    $myaccount_current_endpoint = end($request);
    global $wpdb;
    $charset_collate = $wpdb->get_charset_collate();
    $phantom_option  = $wpdb->prefix . 'phantom_option';
    $phantom_menu  = $wpdb->prefix . 'phantom_menu';
    $results=$wpdb->get_results("select * from $phantom_menu WHERE pa_menu_endpoint='$myaccount_current_endpoint'");
        foreach($results as $content):
            echo do_shortcode($content->pa_menu_content);
        endforeach;
    exit;
}
1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Mar 24, 2023 at 23:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.