Skip to content

Instantly share code, notes, and snippets.

@musamamasood
Created August 3, 2016 19:49
Show Gist options
  • Save musamamasood/b65975b7792cf09434f7b6dea75cebc8 to your computer and use it in GitHub Desktop.
Save musamamasood/b65975b7792cf09434f7b6dea75cebc8 to your computer and use it in GitHub Desktop.
WooCommerce Dynamic Pricing with Product Add-ons on Checkout
/**
* Add option price in WooCommerce product
* WooCommerce Dynamic Pricing with Product Add-ons on Checkout
* https://www.youtube.com/watch?v=syd2OlKdeVc
*/
add_action( 'woocommerce_before_calculate_totals', 'divi_add_option_price' );
function divi_add_option_price( $cart_object ){
foreach ( $cart_object->cart_contents as $key => $value ) {
//$product_id = $value['product_id'];
$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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment