Skip to content

Instantly share code, notes, and snippets.

@plugin-republic
Last active January 23, 2018 15:26
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/4746b252462a36963b8de3643580c13d to your computer and use it in GitHub Desktop.
Save plugin-republic/4746b252462a36963b8de3643580c13d to your computer and use it in GitHub Desktop.
function add_cart_item_data( $cart_item_data, $product_id, $variation_id ) {
// Has our option been selected?
if( ! empty( $_POST['extended_warranty'] ) ) {
$product = wc_get_product( $product_id );
$price = $product->get_price();
// Store the overall price for the product, including the cost of the warranty
$cart_item_data['warranty_price'] = $price + 250;
}
return $cart_item_data;
}
add_filter( 'woocommerce_add_cart_item_data', 'add_cart_item_data', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment