I'm not a lot familiar with code, but I have to manage an e-commerce for friends. They ask me to add a surcharge in the cart, for all the products except for 1-2 categories. I found this code that is doing the job, but this add the surcharge to a specific category (86), and I want to add the surcharge to all the categories except the 86. How can I do this? Tried with !=86 and <> but no luck... (I'm sorry, I suppose it's an easy question...but I'm not familiar with code...) thanks for any help
This is the code:
function df_add_ticket_surcharge( $cart_object ) {
global $woocommerce;
$specialfeecat = 86; // category id for the special fee
$spfee = 0.00; // initialize special fee
$spfeeperprod = 0.05; //special fee per product
foreach ( $cart_object->cart_contents as $key => $value ) {
$proid = $value['product_id']; //get the product id from cart
$quantiy = $value['quantity']; //get quantity from cart
$itmprice = $value['data']->price; //get product price
$terms = get_the_terms( $proid, 'product_cat' ); //get taxonamy of the prducts
if ( $terms && ! is_wp_error( $terms ) ) :
foreach ( $terms as $term ) {
$catid = $term->term_id;
if($specialfeecat == $catid ) {
$spfee = $spfee + $itmprice * $quantiy * $spfeeperprod;
}
}
endif;
}
if($spfee > 0 ) {
$woocommerce->cart->add_fee( 'Ticket Concierge Charge', $spfee, true, 'standard' );
}
}
add_action( 'woocommerce_cart_calculate_fees', 'df_add_ticket_surcharge' );