-
-
Save michaeltieso/0068bf05f4ad64577e54 to your computer and use it in GitHub Desktop.
add_action( 'woocommerce_before_calculate_totals', 'add_custom_price' ); | |
function add_custom_price( $cart_object ) { | |
foreach ( $cart_object->cart_contents as $key => $value ) { | |
$addons = $value['addons']; | |
$add_to_price = 0; | |
foreach($addons as $addon) { | |
$add_to_price .= $addon['price']; | |
} | |
$price = $value['data']->price; | |
$price += $add_to_price; | |
$value['data']->price = $price; | |
} | |
} |
Thanks Michael for the credit!
Michael and Brandon,
Thanks for finding the solution and posting this. You saved me a lot of hunting around and helped me save the day.
You guys both just earned some good karma. Thank you!
Any idea about a discount possibility? Options that lowers the price instead of +?
Hey guys! Thanks for the code. I'm having an issue when I try to add more than one product addon? Seems to work with one but not two charges. Any solutions?
I've added the code via code snippets plugin, with no effect whatsoever. Any suggestions?
How can I make this work with Gravity Forms Product Add-Ons? It works great when you use the Woocoommerce add-ons field but not when you are using Gravity Forms for the add-ons. Any suggestions?
@kemmieg
I just came across this thread. Gravity Forms Product Addons does this automatically if you select the "Enable Dynamic Price" when attaching a form to a product. It was an option I added in early 2016.
Credit: http://www.brandonbrotsky.com