如何将外部自定义 url 添加到 woocommerce 端点 [英] How to add external custom url to woocommerce endpoint

查看:26
本文介绍了如何将外部自定义 url 添加到 woocommerce 端点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想向 woocommerce 上的我的帐户页面添加自定义端点 URL.是否可以?因此,当客户点击此链接时,他们将重定向到我的 YouTube 页面

I want to add a custom endpoint url to my-account page on woocommerce. is it possible? So when customer clicks to this link they will redirect to my youtube page

function custom_wc_end_point() {
    if(class_exists('WooCommerce')){
    add_rewrite_endpoint( 'videos', EP_ROOT | EP_PAGES );
}
}
add_action( 'init', 'custom_wc_end_point' );
function custom_endpoint_query_vars( $vars ) {
    $vars[] = 'videos';
    return $vars;
}
add_filter( 'query_vars', 'custom_endpoint_query_vars', 0 );
function ac_custom_flush_rewrite_rules() {
    flush_rewrite_rules();
}
add_action( 'after_switch_theme', 'ac_custom_flush_rewrite_rules' );
// add the custom endpoint in the my account nav items
function custom_endpoint_acct_menu_item( $items ) {

    $download = $items['downloads'];
    unset( $items['downloads'] );
    $items['videos'] = __( 'Watch Videos ', 'woocommerce' ); // replace videos with your endpoint name
    $items['downloads'] = $download;
        return $items;
}


add_filter( 'woocommerce_account_menu_items', 'custom_endpoint_acct_menu_item' );

function youtube_custom_endpoint() {
      // Is it possible wehn click on this link it move to my youtube page

}
add_action( 'woocommerce_account_videos_endpoint', 'youtube_custom_endpoint' );

推荐答案

add_filter ( 'woocommerce_account_menu_items', 'misha_one_more_link' );
function misha_one_more_link( $menu_links ){

    // we will hook "anyuniquetext123" later
    $new = array( 'anyuniquetext123' => '**Candidate Dashboard**' );

    // or in case you need 2 links
    // $new = array( 'link1' => 'Link 1', 'link2' => 'Link 2' );

    // array_slice() is good when you want to add an element between the other ones
    $menu_links = array_slice( $menu_links, 0, 1, true ) 
    + $new 
    + array_slice( $menu_links, 1, NULL, true );


    return $menu_links;
}

add_filter( 'woocommerce_get_endpoint_url', 'misha_hook_endpoint', 10, 4 );
function misha_hook_endpoint( $url, $endpoint, $value, $permalink ){

    if( $endpoint === 'anyuniquetext123' ) {

        // ok, here is the place for your custom URL, it could be external
        $url = **'http://alatta.org.ye/candidate-dashboard/';**

    }
    return $url;

}

只需更改候选人仪表板",即出现在我的帐户菜单中的页面名称或标题名称.

just change the "Candidate Dashboard" which is the the page name or the title name that appear in the my-account menu.

第二件事是将 URL 更改为您的 url,我将要更改的内容加粗.

second thing change the URL to your url, i make it in bold the things to be changed.

最好,

这篇关于如何将外部自定义 url 添加到 woocommerce 端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆