我已经尝试了一段时间才能使这个工作,但我没有找到任何解决方案完全符合我们的需要,而且我远非PHP专家,所以我有点迷失.
我们使用WooCommerce和WooTickets.目标是仅对"门票"类别(ID:34)中的产品增加5%的"服务费"费用.
我们找到了此代码段,根据产品类别添加固定成本:
// Add Service Fee to Category
function woo_add_cart_fee() {
$category_ID = '23';
global $woocommerce;
foreach ($woocommerce->cart->cart_contents as $key => $values ) {
// Get the terms, i.e. category list using the ID of the product
$terms = get_the_terms( $values['product_id'], 'product_cat' );
// Because a product can have multiple categories, we need to iterate through the list of the products category for a match
foreach ($terms as $term) {
// 23 is the ID of the category for …Run Code Online (Sandbox Code Playgroud)