Мне нужно добавить дополнительную плату в зависимости от категории и страны! Код хорошо работает со страной и отдельной категорией, но я не могу добавлять исключения для других категорий.
- Моя цель - создать дополнительную плату за средние пакеты в размере 30 евро с категорией (1,2,3) и дополнительную плату за большие пакеты в размере 50 евро с категорией (4,5,6), оба действительны для страны Европы.
- Дополнительная плата в размере 10 евро, посвященная Италии с категорией (1,2,3,4,5,6).
Вот мой код:
function df_add_ticket_surcharge_large( $cart_object ) {
global $woocommerce;
$specialfeecat = 1; // category id for the special fee
$spfee = 0.00; // initialize special fee
$spfeeperprod = 50; //special fee per product
$county = array('BE','EL','LT','PT','BG','ES','LU','RO','CZ','FR','HU','SI','DK','HR','MT','SK','DE','NL','FI','EE','CY','AT','SE','IE','LV','PL','UK');
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, 'article-type' ); //get taxonamy of the prducts
if ( $terms && ! is_wp_error( $terms )) :
foreach ( $terms as $term ) {
$catid = $term->term_id;
if($specialfeecat == $catid ) {
$spfee = $spfeeperprod;
}
}
endif;
}
if ( in_array( $woocommerce->customer->get_shipping_country(), $county ) ) {
$woocommerce->cart->add_fee( 'Large Pack', $spfee, true, 'standard' );
}
}add_action('woocommerce_cart_calculate_fees','df_add_ticket_surcharge_large');
Кто-нибудь может мне помочь?