我正在尝试向"我的账户"部分,以显示愿望列表(由Yith的插件生成(。我遵循了下面的教程,但出于某种原因,我最终把标签放在了左侧,就像我想要的那样,但如果我点击它,我会被重定向到愿望列表页面,而不是像其他标签那样把内容显示在右侧。
我想我已经在类似的线程中尝试过stackoverflow上建议的任何代码,但都没有用。
以下是我迄今为止所做的一切:
// ------------------
// 1. Register new endpoint (URL) for My Account page
// Note: Re-save Permalinks or it will give 404 error
function bbloomer_add_premium_support_endpoint() {
add_rewrite_endpoint( 'wishlist', EP_ROOT | EP_PAGES );
}
add_action( 'init', 'bbloomer_add_premium_support_endpoint' );
// ------------------
// 2. Add new query var
function bbloomer_premium_support_query_vars( $vars ) {
$vars[] = 'premium-support';
return $vars;
}
add_filter( 'query_vars', 'bbloomer_premium_support_query_vars', 0 );
// ------------------
// 3. Insert the new endpoint into the My Account menu
function bbloomer_add_premium_support_link_my_account( $items ) {
$items['wishlist'] = 'Wishlist';
return $items;
}
add_filter( 'woocommerce_account_menu_items', 'bbloomer_add_premium_support_link_my_account' );
// ------------------
// 4. Add content to the new tab
function bbloomer_premium_support_content() {
echo '<h3>Wishlist</h3>';
echo do_shortcode( ' [yith_wcwl_wishlist] ' );
}
add_action( 'woocommerce_account_premium-support_endpoint', 'bbloomer_premium_support_content' );
// Note: add_action must follow 'woocommerce_account_{your-endpoint-slug}_endpoint' format
\\\\\\\\\\\\\\\\\\\\\\\\
/* Insert the new endpoint into the My Account menu. @param array $items @return array */
function my_custom_my_account_menu_items( $items ) {
// Remove the logout menu item.
$logout = $items['customer-logout'];
unset( $items['customer-logout'] );
// Insert your custom endpoint.
$items['wishlist'] = __( 'Wishlist', 'woocommerce' );
// Insert back the logout item.
$items['customer-logout'] = $logout;
return $items;
}
add_filter( 'woocommerce_account_menu_items', 'my_custom_my_account_menu_items' );
function my_custom_endpoint_content() {
echo do_shortcode( ' [yith_wcwl_wishlist] ' );
}
add_action( 'woocommerce_account_my-custom-endpoint_endpoint', 'my_custom_endpoint_content' );
\\\\\\\\\\\\\\\\\\\\\\\
/* hook wishlist in my account */
add_filter('woocommerce_account_menu_items', function($items) {
$logout = $items['customer-logout'];
unset($items['customer-logout']);
$items['wishlist'] = __('Wishlist', 'txtdomain');
$items['customer-logout'] = $logout;
return $items;
});
add_action('woocommerce_account_license-keys_endpoint', function() {
echo do_shortcode( ' [yith_wcwl_wishlist] ' );
});
请注意,我在不同的时间尝试过这些片段,ofc不是一次全部\"行用于标记代码段的末尾。
修改您必须将函数从premium_support
更改为wishlist
的第一个代码段,并使用代码段插件添加到您的网站中。
// 1. Register new endpoint to use for My Account page
// Note: Resave Permalinks or it will give 404 error
function bbloomer_add_wishlist_endpoint() {
add_rewrite_endpoint( 'wishlist', EP_ROOT | EP_PAGES );
}
add_action( 'init', 'bbloomer_add_wishlist_endpoint' );
// ------------------
// 2. Add new query var
function bbloomer_wishlist_query_vars( $vars ) {
$vars[] = 'wishlist';
return $vars;
}
add_filter( 'query_vars', 'bbloomer_wishlist_query_vars', 0 );
// ------------------
// 3. Insert the new endpoint into the My Account menu
function bbloomer_add_wishlist_link_my_account( $items ) {
$items['wishlist'] = 'Wishlist';
return $items;
}
add_filter( 'woocommerce_account_menu_items',
'bbloomer_add_wishlist_link_my_account' );
// ------------------
// 4. Add content to the new endpoint
function bbloomer_wishlist_content() {
echo do_shortcode( ' [yith_wcwl_wishlist] ' );
}
add_action( 'woocommerce_account_wishlist_endpoint', 'bbloomer_wishlist_content' );
// Note: add_action must follow 'woocommerce_account_{your-endpoint-slug}_endpoint' format