我想在woocommerce上添加自定义端点网址到我的帐户页面。可能吗?因此,当客户点击此链接时,他们会重定向到我的YouTube页面
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' );
答案 0 :(得分:1)
您可以使用“woocommerce_get_endpoint_url”过滤器来实现您的目标:
add_filter( 'woocommerce_get_endpoint_url', 'maybe_redirect_endpoint', 10, 4 );
function maybe_redirect_endpoint ($url, $endpoint, $value, $permalink)
{
if( $endpoint == 'my-custom-endpoint')
$url = 'https://www.youtube.com/watch?v=Q0q1gCsZykg';
return $url;
}
答案 1 :(得分:0)
我知道这个问题已经存在了一段时间,但是我想写我的答案以帮助现在或将来的某个人。正在从事一个数字电子商务项目,该项目需要大量定制才能匹配EDD。这个问题是自定义问题之一(在该情况下,我不希望访问编辑地址端点;而是应该重定向到编辑帐户端点。我也测试了此代码以回答您的问题,然后将其重定向到YouTube。根据您的需要进行定制。
function howabout_redirect_endpoint () {
$my_account_link = get_permalink( get_option('woocommerce_myaccount_page_id') );
/*
* Redirect to any URL of your choice
*/
$location_1 = 'https://youtube.com';
/*
* Redirect to Other Endpoint of Choice, i chose Edit Account Endpoint
**/
$location_2 = $my_account_link.'edit-account/';
if (is_wc_endpoint_url( 'edit-address' )) { //You can add your custom Endpoint here.
wp_redirect( $location_1 ); //Pass any of the Variable in here, i chose the youtube variable, which answers this question
exit;
}
}
add_action( 'template_redirect', 'howabout_redirect_endpoint' );
代码进入您的活动子主题(或活动主题)的function.php文件中。经过测试并有效。
WP:v5.1.1
WC:v3.6.2
答案 2 :(得分:0)
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;
}
只需更改“候选仪表板”,即我的帐户菜单中显示的页面名称或标题名称。
第二件事将URL更改为您的URL,我将要更改的内容以粗体显示。
最佳,