Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hollyboom/c642bd3fb0caf7849f3fc6859735fc5e to your computer and use it in GitHub Desktop.
Save hollyboom/c642bd3fb0caf7849f3fc6859735fc5e to your computer and use it in GitHub Desktop.
WC Advanced Fees - custom subtotal
<?php
function custom_wcaf_fee_amount_subtotal( $subtotal ) {
$subtotal = 0;
$category_id = '61'; // Your category ID here.
$cart_items = WC()->cart->get_cart();
foreach ( $cart_items as $key => $item ) {
if ( has_term( $category_id, 'product_cat', $item['product_id'] ) ) {
$subtotal += $item['line_subtotal'] + $item['line_subtotal_tax'];
}
}
return $subtotal;
}
add_filter( 'woocommerce_advanced_fees_get_fee_amount_subtotal', 'custom_wcaf_fee_amount_subtotal' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment