0

I recently found a code in this forum for creating a custom tab on the WooCommerce my account page with specific user roles. I adapted the code to my site. When adding the first tab and testing it, everything is still fine. When I copy this code for a 2nd custom tab and modify it for the 2nd tab, my website crashes.

the following code comes from the functions.php of the child theme


/* Create Premium Support Tab on Woo Account Page with premium customer role
----------------------------------------------------------------------------*/

add_action( 'init', 'add_prem_support_account_endpoint' );
function add_prem_support_account_endpoint() {
    add_rewrite_endpoint( 'prem-support', EP_PAGES );
}

add_filter ( 'woocommerce_account_menu_items', 'custom_account_menu_items', 10 );
function custom_account_menu_items( $menu_links ){
    if ( current_user_can('klant_premium') ) {
        $menu_links = array_slice( $menu_links, 0,4 , true )
        + array( 'prem-support' => __('Premium Support') )
        + array_slice( $menu_links, 3, NULL, true );
    }
    return $menu_links;
}

add_action( 'woocommerce_account_prem-support_endpoint', 'prem_support_account_endpoint_content' );
function prem_support_account_endpoint_content() {
    if ( current_user_can('klant_premium') ) {
        echo "<h3>Premium Support</h3><p>Als premium klant, kan je gebruik maken van ons Premium Support System. We bieden je de mogelijkheid om via een ticket systeem contact op te nemen en op die manier snel en overzichtelijk een antwoord te krijgen op je vragen. Op die manier sta je er niet meer alleen voor en kan Code4u je partner worden voor je internet-onderneming.</p> ";
   echo do_shortcode( ' [supportcandy]  ' ) ;
    }
}


/* Create Strippenkaart Tab on Woo Account Page with strippenkaart customer role
--------------------------------------------------------------------------------*/

add_action( 'init', 'add_hourly_support_account_endpoint' );
function add_hourly_support_account_endpoint() {
    add_rewrite_endpoint( 'hourly-support', EP_PAGES );
}

add_filter ( 'woocommerce_account_menu_items', 'custom_account_menu_items', 10 );
function custom_account_menu_items( $menu_links ){
    if ( current_user_can('klant_strippenkaart') ) {
        $menu_links = array_slice( $menu_links, 0,5 , true )
        + array( 'hourly-support' => __('Strippenkaart') )
        + array_slice( $menu_links, 3, NULL, true );
    }
    return $menu_links;
}

add_action( 'woocommerce_account_hourly-support_endpoint', 'hourly_support_account_endpoint_content' );
function hourly_support_account_endpoint_content() {
    if ( current_user_can('klant_strippenkaart') ) {
        echo "<h3>Strippenkaart</h3>";
   echo do_shortcode( ' [wph-client-reports] ' ) ;
    }
}

I should be able to log in as a premium customer and see the premium tab, if I log in as a "strippenkaart" customer I should see the "strippenkaart" tab. Also, there may be customers who see both tabs because they have the role of premium and "strippenkaart" customer

0 Answers0