Woocommerce 商业类别和区域特定服务费

Woocommerce 商业类别和区域特定服务费,woocommerce,Woocommerce,我发现这段代码是为了给WooCommerce增加服务费 // Add Service Fee to Category function woo_add_cart_fee() { $category_ID = '23'; global $woocommerce; foreach ($woocommerce->cart->cart_contents as $key => $values ) { // Get the terms, i.e. category li

我发现这段代码是为了给WooCommerce增加服务费

    // Add Service Fee to Category
function woo_add_cart_fee() {

$category_ID = '23';
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) {
        // 23 is the ID of the category for which we want to remove the payment gateway
        if($term->term_id == $category_ID){
         $excost = 6;
         }
         }
        $woocommerce->cart->add_fee('Service Fee', $excost, $taxable = false, $tax_class = '');
}
}
add_action( 'woocommerce_cart_calculate_fees', 'woo_add_cart_fee' );
如何仅向某些区域添加服务费


如果购物车金额超过250美元,这怎么能被忽略呢?

$woocmerce->customer->get_country()和WC_cart::get_cart_total();是的,这些可能是钩子,但实际上不是一个片段