我在另一个线程上发现了这段php代码.它向WooCommerce购物车添加每种产品的百分比费用,并根据类别进行 checkout .我需要修改代码,使其添加一个统一费率的费用,而不是基于百分比的费用.我对php不是很了解,无法进行修改,所以我想问一问这里的专家能不能给我演示一下实现这一点的代码更改?
它工作得很好,只是加了%,而不是统一费率.以下是代码片段:
function df_add_ticket_surcharge( $cart_object ) {
global $woocommerce;
$specialfeecat = 33; // 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' );
我try 了我对php代码知之甚少的东西,以及在线搜索,但都没有成功.我希望能在这里找到一个解决方案.谢谢你所能提供的任何帮助.