Skip to content

Instantly share code, notes, and snippets.

@michaeltieso
Created September 22, 2014 20:17
Show Gist options
  • Save michaeltieso/0068bf05f4ad64577e54 to your computer and use it in GitHub Desktop.
Save michaeltieso/0068bf05f4ad64577e54 to your computer and use it in GitHub Desktop.
Dynamic Pricing + Product Add-ons
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
Copy link

kemmieg commented Apr 16, 2016

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?

@lucasstark
Copy link

@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