Skip to content

Instantly share code, notes, and snippets.

@heanfig
Created November 1, 2017 12:21
Show Gist options
  • Save heanfig/b1ffbdbfcf9685ea32f5998c5b81e6f7 to your computer and use it in GitHub Desktop.
Save heanfig/b1ffbdbfcf9685ea32f5998c5b81e6f7 to your computer and use it in GitHub Desktop.
<?php
// This variable value is passed to our function
$bookable_total = 1;
function woo_add_cart_fee( $bookable_total = 0 ) {
//global $bookable_total;
/*if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;*/
// just for this example
//$item_count = 0;
//$item_fee = 5;
// going through each cart items
//foreach( WC()->cart->get_cart() as $values ) {
//$item = $values['data'];
//if ( empty( $item ) )
// break;
// getting the cart item_id
//$item_id = $item->id;
//$item_count++;
// your calculations
//}
// We test $bookable_total value, defined to '1' outside our function
// and to 'O' if not defined outside (in this case the fee will be '0')
//$fee = $item_count * $bookable_total * $item_fee;
$fee = 120000;
// add_fee method (TAX will NOT be applied here)
WC()->cart->add_fee( 'Impuesto por viajes: ', $fee, false );
}
add_action( 'woocommerce_cart_calculate_fees','woo_add_cart_fee' );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment