Fee per product
-
Hi!
Is there a way to add fee to every item? Ie. If someone orders 20 items, then add to the amount 20*(fee)?
Thanks, btw, your plugin is simply great! 🙂
Błażej
-
I think its the default.
The price is always calculated for 1item of the product. If you but it in the basket the price is multiplied by woocommerce.I will check it, thank you! Wouldn’t have thought that it could be default 🙂
Hi @abpromotions,
i did code snipped for you,
Goto plugins/wc-fields-factory/inlcudes/wcff-negitiator.php
findhandle_custom_feethis method and remove the entire method
replace there following lines.`public function handle_custom_fee($_cart = null) {
if ($_cart) {
$cart = WC()->cart->get_cart();
$cart_total = WC()->cart->cart_contents_total;
$total_fee = array();
$self = $this;
foreach ($cart as $key => $citem) {
foreach ($citem as $ckey => $cval) {
if (strpos($ckey, “wccpf_”) !== false && isset($citem[$ckey][“fee_rules”]) && $citem[$ckey][“user_val”]) {
$ftype = $citem[$ckey][“ftype”];
$dformat = $citem[$ckey][“format”];
$uvalue = $citem[$ckey][“user_val”];
$f_rules = $citem[$ckey][“fee_rules”];
/* Iterate through the rules and update the price */
foreach ($f_rules as $frule) {
if ($this->check_rules($frule, $uvalue, $ftype, $dformat)) {
$is_tax = isset( $frule[“is_tx”] ) && $frule[“is_tx”] == “non_tax” ? false : true;
$fee_amount = isset( $frule[“tprice”] ) && $frule[“tprice”] == “cost” ? $frule[“amount”] : ( floatval ( $frule[“amount”] ) / 100 ) * $cart_total;
WC()->cart->add_fee($frule[“title”], $fee_amount, $is_tax, “”);if( !isset( $total_fee[ $self->change_key( $frule[“title”] ) ] ) ){
$total_fee[ $self->change_key( $frule[“title”] ) ] = array( “amount” => 0, “title” => $frule[“title”], “is_taxable” => $is_tax );
}
$namt = isset( $frule[“tprice”] ) && $frule[“tprice”] == “cost” ? floatval ( $frule[“amount”] ) : ( floatval ( $frule[“amount”] ) / 100 ) * floatval ( $citem[‘data’]->price ) ;
$total_fee[ $self->change_key( $frule[“title”] ) ][ “amount” ] = $total_fee[ $self->change_key( $frule[“title”] ) ][ “amount” ] + ( $namt * floatval( $citem[“quantity”] ) );}
}
}
}
}
foreach( $total_fee as $val ){
WC()->cart->add_fee( $val[“title”], $val[“amount”], $val[“is_taxable”], “” );
}
}
}private function change_key( $key ) {
return str_replace(array( ” “, “-” ), array(“_”, “_”), $key);
}`
The topic ‘Fee per product’ is closed to new replies.