【发布时间】:2018-04-04 22:31:14
【问题描述】:
我需要根据类别和国家/地区添加额外费用! 该代码适用于国家和单一类别,但我无法为其他类别添加例外。
- 我的目标是为类别 (1,2,3) 的 30 欧元中型包装和类别 (4,5,6) 的 50 欧元大包装额外收费,两者均适用于欧洲国家/地区。
- 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');
谁能帮帮我?
【问题讨论】:
-
我也有类似的问题,但不太复杂,stackoverflow.com/questions/64117519/…
标签: php wordpress woocommerce cart fee