Php Wordpress Woocommerce产品正在页面刷新时添加到购物车
我在使用woocommerce时遇到问题 将产品添加到购物车后,浏览器中的链接变为link/?add to cart=72,如果我刷新页面,产品将再次添加到购物车中 每次刷新都会将产品添加到购物车中。 我禁用了除woocommerce之外的所有插件,但仍然是一样的Php Wordpress Woocommerce产品正在页面刷新时添加到购物车,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,我在使用woocommerce时遇到问题 将产品添加到购物车后,浏览器中的链接变为link/?add to cart=72,如果我刷新页面,产品将再次添加到购物车中 每次刷新都会将产品添加到购物车中。 我禁用了除woocommerce之外的所有插件,但仍然是一样的 关于如何解决这个问题有什么想法吗?谢谢。我曾经遇到过同样的问题,下面是您应该添加到主题的functions.php文件或您自己的自定义插件中的代码: add_action('add_to_cart_redirect', 'resolv
关于如何解决这个问题有什么想法吗?谢谢。我曾经遇到过同样的问题,下面是您应该添加到主题的
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'));
}
当用户将产品添加到购物车时,它将添加重定向。我希望这有帮助。这也对我有帮助,但是如果你使用自定义文件夹,你必须将
get\u bloginfo('wpurl')
更改为get\u bloginfo('url')