我想将自定义端点 URL 添加到 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' );
您可以使用“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;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)