Skip to content

Instantly share code, notes, and snippets.

@deshabhishek007
Last active May 16, 2018 17:48
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 deshabhishek007/3293b91e69db618a98168e1f23dc5a1b to your computer and use it in GitHub Desktop.
Save deshabhishek007/3293b91e69db618a98168e1f23dc5a1b to your computer and use it in GitHub Desktop.
Override WooCommerce Product Price
add_action( 'woocommerce_before_calculate_totals', 'add_custom_price' );
function add_custom_price( $cart_object ) {
$custom_price = 100; // This will be your custome price
$target_product_id = 15;
foreach ( $cart_object->cart_contents as $value ) {
if ( $value['product_id'] == $target_product_id ) {
$value['data']->set_price ($custom_price);
}
/*
// If your target product is a variation
if ( $value['variation_id'] == $target_product_id ) {
$value['data']->price = $custom_price;
}
*/
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment