【问题标题】:Redirect of product URL in WooCommerce appWooCommerce 应用程序中产品 URL 的重定向
【发布时间】:2021-11-30 18:28:47
【问题描述】:

我想重定向第一个链接 URL 为 "product" 的所有单个产品页面,该页面将被重定向到 store 感谢页面。 我想保留单品,我只想重定向开头路径为/product/的产品。由于我目前使用的产品没有/product/,因此我需要从重复项中删除。

例如:

domain.com/product/category/product-name

domain.com/product/product-name

move to

domain.com/shop

【问题讨论】:

    标签: redirect woocommerce product


    【解决方案1】:

    基于WooCommerce: Single Product Page Redirect for Logged In Customers,以下 sn-p 应该适用于您的所有单个产品页面:

    add_action( 'template_redirect', 'bbloomer_single_product_redirect );
     
    function bbloomer_single_product_redirect() { 
        if ( ! is_product() ) return;  
        wp_safe_redirect( '/shop' );
        exit;
    }
    

    【讨论】:

    • 哦@businessbloomer,我也喜欢你的博客,对不起,我没有正确解释。我想保留单个产品,我只想重定向路径 /product/ 开头的产品。由于我目前使用的产品没有/product/,所以我需要从重复项中删除
    • 明白了。您可以使用相同的 sn-p 并检查当前 URL 是否包含 /product/ - 然后才进行重定向:stackoverflow.com/questions/7118823/…
    猜你喜欢
    • 1970-01-01
    • 2016-11-29
    • 1970-01-01
    • 2019-01-27
    • 2023-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多