1

i create snippet for added custom endpoint and this my code:

/**
 * Register new endpoint to use inside My Account page.
 *
 * @see https://developer.wordpress.org/reference/functions/add_rewrite_endpoint/
 */
function my_subscriptions_endpoints() {
    add_rewrite_endpoint( 'my-subscriptions', EP_ROOT | EP_PAGES );
}
add_action( 'init', 'my_subscriptions_endpoints' );

/**
 * Add new query var.
 *
 * @param array $vars
 * @return array
 */
function my_subscriptions_query_vars( $vars ) {
    $vars[] = 'my-subscriptions';

    return $vars;
}
add_filter( 'query_vars', 'my_subscriptions_query_vars', 0 );


/**
 * Flush rewrite rules on theme activation.
 */
function my_subscriptions_flush_rewrite_rules() {
    add_rewrite_endpoint( 'my-subscriptions', EP_ROOT | EP_PAGES );
    flush_rewrite_rules();
}
add_action( 'after_switch_theme', 'my_subscriptions_flush_rewrite_rules' );

/**
 * Custom help to add new items into an array after a selected item.
 *
 * @param array $items
 * @param array $new_items
 * @param string $after
 * @return array
 */
function my_subscriptions_insert_after_helper( $items, $new_items, $after ) {
    // Search for the item position and +1 since is after the selected item key.
    $position = array_search( $after, array_keys( $items ) ) + 1;

    // Insert the new item.
    $array = array_slice( $items, 0, $position, true );
    $array += $new_items;
    $array += array_slice( $items, $position, count( $items ) - $position, true );

    return $array;
}

/**
 * Insert the new endpoint into the My Account menu.
 *
 * @param array $items
 * @return array
 */
function my_subscriptions_my_account_menu_items( $items ) {
    $new_items = array();
    $new_items['my-subscriptions'] = __( 'My Subscriptions', 'woocommerce' );

    // Add the new item after `orders`.
    return my_subscriptions_insert_after_helper( $items, $new_items, 'orders' );
}
add_filter( 'woocommerce_account_menu_items', 'my_subscriptions_my_account_menu_items' );

/**
 * Custom Endpoint content
 */
function gc_custom_endpoint_content() {
    echo do_shortcode('[ywsbs_my_account_subscriptions]');
}
add_action( 'woocommerce_account_my-subscriptions_endpoint', 'gc_custom_endpoint_content' );

This snippet showing My Subscriptions tab with endpoint my-subscriptions with gear icon, my question how to change icon?

1

you can change the icon with CSS and using FontAwesome http://fontawesome.io/

e.g. to put a calendar

.woocommerce-MyAccount-navigation ul li.woocommerce-MyAccount-navigation-link--my-subscriptions a::before
{
    content : "\f073";
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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