Skip to content

Instantly share code, notes, and snippets.

@JeroenSormani
Created February 10, 2016 17:48
Show Gist options
  • Save JeroenSormani/5c28eb8f50ce9fbd235b to your computer and use it in GitHub Desktop.
Save JeroenSormani/5c28eb8f50ce9fbd235b 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