Created
August 3, 2016 19:49
-
-
Save musamamasood/b65975b7792cf09434f7b6dea75cebc8 to your computer and use it in GitHub Desktop.
WooCommerce Dynamic Pricing with Product Add-ons on Checkout
This file contains hidden or 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 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