0
votes

Woocommerce Plugin adds to cart more fee per items.

Customer select below in the shopping cart:

Product A (Big item) - $300

Product B (Big item) - $500

Product C (Normal item) - $30

Product D (Normal item) - $10

Let's assume the rule for " Big item - Normal item " below:

Big item - Charges: $20/item

Normal item - Charges: Below $150, Free delivery; Above $150, $20 Fee will be charged

How can i make it automatic when click on add to cart button with the rule above ?

1

1 Answers

0
votes
add_action( 'woocommerce_before_calculate_totals', 'add_custom_price' );
function add_custom_price( $cart_object ) {
foreach ( $cart_object->cart_contents as $key => $value ) {
   /* if ( $value['product_id'] == $target_product_id ) {*/
    //$current_prize = $value['data']->price;
    if($value['data']->price>150)
    {
        $value['data']->price = $value['data']->price + 20;
    }
}}

add above code in function.php of your current theme....hope may be helpful to u