Created
September 22, 2014 20:17
-
-
Save michaeltieso/0068bf05f4ad64577e54 to your computer and use it in GitHub Desktop.
Dynamic Pricing + Product Add-ons
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
@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.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?