Last active
May 16, 2018 17:48
-
-
Save deshabhishek007/3293b91e69db618a98168e1f23dc5a1b to your computer and use it in GitHub Desktop.
Override WooCommerce Product Price
This file contains 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_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