Created
February 10, 2016 17:48
-
-
Save JeroenSormani/5c28eb8f50ce9fbd235b to your computer and use it in GitHub Desktop.
WC Advanced Fees - custom subtotal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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