我在myaccount菜单中添加了一个自定义端点,它与Yith Woccommerce Wishlist相对应。 我添加了此代码以创建edpoint并显示内容:
function my_custom_endpoints() {
add_rewrite_endpoint( 'yith-my-wishlist', EP_ROOT | EP_PAGES );
}
add_action( 'init', 'my_custom_endpoints' );
function my_custom_query_vars( $vars ) {
$vars[] = 'yith-my-wishlist';
return $vars;
}
add_filter( 'query_vars', 'my_custom_query_vars', 0 );
function my_flush_rewrite_rules() {
flush_rewrite_rules();
}
add_action( 'wp_loaded', 'my_flush_rewrite_rules' );
function my_custom_my_account_menu_items( $items ) {
$items = array(
'customer-logout' => __( 'Logout', 'woocommerce' ),
'edit-account' => __( 'My Profile', 'woocommerce' ),
'yith-my-wishlist' => __('My Wishlist', 'woocommerce'),
//'dashboard' => __( 'Dashboard', 'woocommerce' ),
'orders' => __( 'Orders', 'woocommerce' )
//'downloads' => __( 'Downloads', 'woocommerce' ),
//'edit-address' => __( 'Addresses', 'woocommerce' ),
//'payment-methods' => __( 'Payment Methods', 'woocommerce' ),
);
return $items;
}
add_filter( 'woocommerce_account_menu_items', 'my_custom_my_account_menu_items' );
function my_custom_endpoint_content() {
include 'yith-woocommerce-wishlist/wishlist-view.php';
}
add_action( 'woocommerce_account_special-page_endpoint', 'my_custom_endpoint_content' );
但内容并未出现。我认为my_custom_endpoint_content()函数中的url出错了。
我有一个子主题,此代码位于子主题的functions.php中。我将childtheme文件夹中的yith插件文件夹与我想要显示的文件一起复制。
我该如何解决?
答案 0 :(得分:-1)
你的
var top = 100; // not ok (it's Window Object)
var top2 = 100; // ok
var left = 200; // ok
/* top */
console.log(alert("<div style='position: absolute; left:" + top +"px; top:" + left + "px;'> <h1 style='font-size:10px; color:blue;'> HELLO WORLD </h1></div>"));
// <div style='position: absolute; left:[object Window]px; top:200px;'> <h1 style='font-size:10px; color:blue;'> HELLO WORLD </h1></div>
/* top2 */
<div style='position: absolute; left:[object Window]px; top:200px;'> <h1 style='font-size:10px; color:blue;'> HELLO WORLD </h1></div>
// <div style='position: absolute; left:100px; top:200px;'> <h1 style='font-size:10px; color:blue;'> HELLO WORLD </h1></div
应该是
add_action( 'woocommerce_account_special-page_endpoint', 'my_custom_endpoint_content' );
它的格式为add_action( 'woocommerce_account_yith-my-wishlist_endpoint', 'my_custom_endpoint_content' );
,其中'woocommerce_account_' . $key . '_endpoint'
为$key
。
另外,我认为yith-my-wishlist
不适用于functions.php。如果此文件来自插件,则需要插件的路径。