<?php
add_action( 'woocommerce_cart_calculate_fees', 'basedfeesbysitiweb' );
if ( ! function_exists( 'basedfeesbysitiweb' ) ) {
function basedfeesbysitiweb( $cart ) {
$fees = array(
'cadeau-service' => 1.24,
);
$x = 0;
foreach ( $cart->get_cart() as $cart_item_key => $values ) {
$product_categories = get_the_terms( $values['product_id'], 'product_cat' );
if ( $product_categories && ! is_wp_error( $product_categories ) ) {
$product_categories = wp_list_pluck( $product_categories, 'slug' );
foreach ( $product_categories as $product_category ) {
if ( ! empty( $fees[ $product_category ] ) && !empty($values['wcgwp_line_item_note']) ) {
$x++;
}
}
}
}
if ($x > 0) {
if($x >= 2){
$name = $x . ' kaartjes bij verpakking';
}else{
$name = $x . ' kaartje bij verpakking';
}
$amount = 1.24;
$taxable = true;
$tax_class = '';
$cart->add_fee( $name, $amount * $x, $taxable, $tax_class );
}
}
}
?>