Wordpress Woocommerce产品正在页面刷新时添加到购物车

时间:2017-10-23 05:27:22

标签: php wordpress woocommerce

我在使用woocommerce时遇到了问题。

将产品添加到购物车后,浏览器中的链接变为 link /?add-to-cart = 72 ,如果我刷新页面,产品将再次添加到购物车中。

每次刷新都会在购物车中添加产品。 我禁用了所有插件,除了woocommerce,仍然是相同的。

关于如何解决这个问题的任何想法?谢谢。

1 个答案:

答案 0 :(得分:6)

我曾经遇到过同样的问题,这是您应该添加到主题的functions.php文件或自己的​​自定义插件的代码:

add_action('add_to_cart_redirect', 'resolve_dupes_add_to_cart_redirect');

function resolve_dupes_add_to_cart_redirect($url = false) {

     // If another plugin beats us to the punch, let them have their way with the URL
     if(!empty($url)) { return $url; }

     // Redirect back to the original page, without the 'add-to-cart' parameter.
     // We add the `get_bloginfo` part so it saves a redirect on https:// sites.
     return get_bloginfo('wpurl').add_query_arg(array(), remove_query_arg('add-to-cart'));

}

当用户将产品添加到购物车时,它会添加重定向。我希望这会有所帮助。