0
我想将自定义端点网址添加到woocommerce的我的帐户页面。可能吗?所以,当客户点击此链接,他们将重定向到我的YouTube页面如何将外部自定义网址添加到woocommerce端点
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特定的端点是WordPress核心的一部分。似乎有许多“会员链接”插件可以做重定向。你有没有试过这些?我强烈建议不要在每次页面加载时运行'flush_rewrite_rules()'。这应该只在您的自定义插件被激活时运行。 – helgatheviking
好的感谢您的建议 – Firefog
是的,我通过重定向端点链接 – Firefog