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 Додамо новий пункт меню ‘Список бажань’ з кінцевою точкою та виведенням контенту
// Додамо пункт меню список бажань
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
Використання не знайдено.
