WooCommerce 从购物车中删除所有产品并将当前产品添加到购物车 [英] WooCommerce Delete all products from cart and add current product to cart

查看:33
本文介绍了WooCommerce 从购物车中删除所有产品并将当前产品添加到购物车的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 WooCommerce 的新手,我只需要在购物车中添加一个产品.当我点击添加到购物车"按钮时,我想清除所有产品并将当前产品添加到购物车.

I am new to WooCommerce and I need to be able to only add one single product in the cart. I want to clear all products and add the current product to the cart when I click the "Add to cart" button.

我该怎么做?

推荐答案

试试这个,

//For removing all the items from the cart
global $woocommerce;
$woocommerce->cart->empty_cart();
$woocommerce->cart->add_to_cart($product_id,$qty);

类文件是 wp-content/plugins/woocommerce/classes/class-wc-cart.php

希望它有所帮助..

这篇关于WooCommerce 从购物车中删除所有产品并将当前产品添加到购物车的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆