woocommerce_account_menu_items
Позволяет добавлять/удалять пункты меню в личном кабинете.
Использование
add_filter( 'woocommerce_account_menu_items', 'wp_kama_woocommerce_account_menu_items_filter', 10, 2 );
/**
* Function for `woocommerce_account_menu_items` filter-hook.
*
* @param $items
* @param $endpoints
*
* @return
*/
function wp_kama_woocommerce_account_menu_items_filter( $items, $endpoints ){
// filter...
return $items;
}
- $items(массив)
- Ассоциативный массив зарегистрированных пунктов меню.
- $endpoints(массив)
- Ассоциативный массив зарегистрированных конечных точек для пунктов меню.
Примеры
#1 Удалим пункт меню 'Загрузки'
add_filter( 'woocommerce_account_menu_items', 'remove_downloads_link' );
function remove_downloads_link( $items ) {
if ( isset( $items['downloads'] ) ) {
unset( $items['downloads'] );
}
return $items;
} #2 Добавим новый пункт меню 'Список желаний' c конечной точкой и выводом контента
// Добавим пункт меню список желаний
add_filter( 'woocommerce_account_menu_items', 'add_wish_list_item' );
function add_wish_list_item( $items ) {
$items['wish-list'] = __( 'Wish list' );
return $items;
}
// Добавим конечную точку
// После добавления конечной точки нужно обновить пермалинки!
add_action( 'init', 'add_wish_list_endpoint' );
function add_wish_list_endpoint() {
add_rewrite_endpoint( 'wish-list', EP_PAGES );
}
// Выведем контент для страницы
add_action( 'woocommerce_account_wish-list_endpoint', 'show_wish_list' );
function show_wish_list() {
echo 'Hello world';
}
Где вызывается хук
woocommerce_account_menu_items
woocommerce/includes/wc-account-functions.php 138
return apply_filters( 'woocommerce_account_menu_items', $items, $endpoints );
Где используется хук в WooCommerce
woocommerce/src/Internal/ShopperLists/ShopperListsController.php 86
add_filter( 'woocommerce_account_menu_items', array( $this, 'add_wishlist_menu_item' ) );
