【问题标题】:Changing the redirect of the “add to cart” button in woocommerce store in Shop page在商店页面的 woocommerce 商店中更改“添加到购物车”按钮的重定向
【发布时间】:2017-04-20 13:37:41
【问题描述】:

我正在尝试将 woocommerce 中的重定向 URL 更改为单个产品页面以外的页面中的“添加到购物车”按钮。可以使用此solution 更改单个产品页面的 URL。但是,此解决方案不适用于任何其他页面,在按下“添加到购物车”按钮后更改重定向。任何帮助是极大的赞赏。

【问题讨论】:

    标签: php wordpress redirect woocommerce cart


    【解决方案1】:

    要使 woocommerce_add_to_cart_redirect 在商店、类别或标签存档页面等页面上工作,您首先需要在后端 WooCommerce > 设置 > 产品 > 显示:

    禁用复选框“启用存档上的 AJAX 添加到购物车按钮”。

    然后钩子代码将与所有 woocommerce 页面上的 woocommerce_add_to_cart_redirect 钩子一起使用。

    function wc_add_to_cart_custom_redirect() { 
        // Here the redirection
        return site_url('/mypage/'); 
    }
    add_filter( 'woocommerce_add_to_cart_redirect', 'wc_add_to_cart_custom_redirect' );
    

    【讨论】:

      【解决方案2】:

      您可以在 Appearence>Theme Editor>function.php

      中使用它
      add_filter( 'woocommerce_loop_add_to_cart_link', 'replacing_add_to_cart_button', 10, 2 );
      function replacing_add_to_cart_button( $button, $product  ) {
          $button_text = __("View product", "woocommerce");
          $button = '<a class="button" href="' . $product->get_permalink() . '">' . $button_text . '</a>';
      
          return $button;
      }
      

      这会将您的添加到购物车更改为查看产品,并且 URL 将是特定产品的 URL

      【讨论】:

        猜你喜欢
        • 2018-05-12
        • 1970-01-01
        • 2016-10-24
        • 1970-01-01
        • 2014-08-09
        • 2018-07-21
        • 2018-09-05
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多