Skip to content

Instantly share code, notes, and snippets.

@plugin-republic
Last active January 23, 2018 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plugin-republic/b22a91760439d07bea9b1ec0dc601b48 to your computer and use it in GitHub Desktop.
Save plugin-republic/b22a91760439d07bea9b1ec0dc601b48 to your computer and use it in GitHub Desktop.
function before_calculate_totals( $cart_obj ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
return;
}
// Iterate through each cart item
foreach( $cart_obj->get_cart() as $key=>$value ) {
if( isset( $value['warranty_price'] ) ) {
$price = $value['warranty_price'];
$value['data']->set_price( ( $price ) );
}
}
}
add_action( 'woocommerce_before_calculate_totals', 'before_calculate_totals', 10, 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment