Forked from JeroenSormani/wc-advanced-fees-custom-subtotal.php
Created
December 22, 2016 19:49
-
-
Save hollyboom/c642bd3fb0caf7849f3fc6859735fc5e 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