One off fee added to cart
-
Hi there,
I’ve got a function running in my cart which adds a one off fee for a Logo upload:add_action( 'woocommerce_before_calculate_totals', 'cp_add_custom_price' ); function cp_add_custom_price( $cart_object ) { // Some query here global $woocommerce; foreach ( $cart_object->cart_contents as $key => $value ) { //Get the product data like below $proid = $value['product_id']; $variantid = $value['variation_id']; $price = $value['data']->price; //check your condition if($youcondition == true ) { //update with the new price $value['data']->price = $newprice; } } $excost = 99; $woocommerce->cart->add_fee( 'Logo set up fee', $excost, $taxable = false, $tax_class = '' ); }
This works well by adding a one off fee of $99 to the cart, regardless of quantity.
The issue i have, is I want to make this conditional if an item has been previously been selected.I have Gravity Forms running with Product Add ons, and if Logo Upload is selected it passes through a value of $0 to the cart, and says Logo upload: yes.
If Logo upload is yes, I want to add the fee, if it says No, I don’t want to add the fee.
Any ideas?
BTW: I cant just add the fee on the product page, otherwise the quantity box picks it up and multiples it!
Have tried using get_post_meta to try and look to see if it is there and can’t seem to get it work.
Example of product in cart:
Testing product
Size:
A4Colour:
Dark greenCorners:
NoPVC Pockets:
A4Quantity:
1Logo upload:
Yes
- The topic ‘One off fee added to cart’ is closed to new replies.