您好,当购物车中产品的总和(还必须包括运费)大于变量的值($minimum_cart_total = 77.47;)时,我试图在结帐中插入费用,其中之一产品属于特定类别。
该功能部分工作,但它不会自动计算根据购物车总和修改的运费。
你能帮助我吗?
function woo_add_cart_fee() {
$shipping_tax_amount = WC() - > cart - > cart_shipping_total;
$category_ID = '220';
$minimum_cart_total = 77.47;
$cart_total = WC() - > cart - > cart_contents_total;
$field_id = 'wholesale_checkbox';
$cart_total_ship = $cart_total + $shipping_tax_amount;
global $woocommerce;
foreach($woocommerce - > cart - > cart_contents as $key => $values) {
// Get the terms, i.e. category list using the ID of the product
$terms=get_the_terms( $values['product_id'], 'product_cat' );
// Because a product can have multiple categories, we need to iterate through the list of the products category for a match
foreach ($terms as $term){
// 220 is the ID of the category for which we want to remove the payment gateway
if($term->term_id==$category_ID && $cart_total_ship > $minimum_cart_total )
{$excost=2;}}
$woocommerce->cart->add_fee('Other fee', $excost, $taxable=false, $tax_class='');}}