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