English 中文(简体)
在WooCommerce Myaccount科增加一个有习俗联系的习俗菜单
原标题:Add a Custom menu item with a custom link in WooCommerce My Account Section

我正成功地在WooCommerce My账户科添加新习惯。 但是,我无法改变菜单项目链接,而是与我的URL账户挂钩。

I want to remove the http://site-test.local/my-account
from this absolute link "http://site-test.local/my-account/https:/mycustomwebsite.com/"

我只想看到“https:/mycustomwebsite.com/”在我点击“NEW CUSTOM TAB”的菜单。

我在我的主题职能中加入了这一法典。 php file:

function custom_add_my_account_menu_item($items) {
    // Add a new menu item with the key  custom_option 
    $items[ https://mycustomwebsite.com ] = __( NEW CUSTOM TAB ,  your-text-domain );

    $cleanLink = str_replace( http://site-test.local/my-account ,   , $items); //I m trying to remove the site-test.local/my-account, but it doesn t work
    
    $items = $cleanLink;
    
    return $items;
}

add_filter( woocommerce_account_menu_items ,  custom_add_my_account_menu_item );

// Display content for the custom option in the My Account section
function custom_my_account_endpoint_content() {
    echo  <p>This is the content for the custom option.</p> ;
}

add_action( woocommerce_account_custom_option_endpoint ,  custom_my_account_endpoint_content );   

如何改变菜单项目与习俗的联系?

问题回答

为了与我的账户菜单项目建立习俗联系,你可以采用以下做法:

// Add a custom menu item
add_filter( woocommerce_account_menu_items ,  add_my_account_custom_menu_item );
function add_my_account_custom_menu_item( $menu_items ) {
    $menu_item_key =  custom_link ;
    $menu_items[$menu_item_key] = __( Custom Link ,  woocommerce );

    return $menu_items;
}
   
// Replace the custom menu item Link
add_action( template_redirect ,  change_my_account_custom_menu_item_link , 10);
function change_my_account_custom_menu_item_link() {
    if ( is_user_logged_in() && is_account_page() ) {
        $menu_item_key =  custom_link ; // HERE set the custom menu item key you are using
        $custom_link   = esc_url( https://mycustomwebsite.com/ ); // HERE set your custom link
        // jQuery code
        wc_enqueue_js("$( li.woocommerce-MyAccount-navigation-link--{$menu_item_key} a ).attr( href , {$custom_link} );");
    }
}

《刑法》生效。 网址是你的孩子主题(或gin)。 测试和工程。


如果你希望在新的窗口中打开链接,将最后一项功能改为:

// Replace the custom menu item Link
add_action( template_redirect ,  change_my_account_custom_menu_item_link , 10);
function change_my_account_custom_menu_item_link() {
    if ( is_user_logged_in() && is_account_page() ) {
        $menu_item_key =  custom_link ; // HERE set the custom menu item key you are using
        $custom_link   = esc_url( https://mycustomwebsite.com/ ); // HERE set your custom link
        // jQuery code
        wc_enqueue_js("$( li.woocommerce-MyAccount-navigation-link--{$menu_item_key} a ).attr( href , {$custom_link} ).attr( target , _blank );");
    }
}

请注意,如果存在习惯菜单项目链接,有关制表内容永远不会显示。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签