
How to get admin user ID
Share This Post How to get admin User ID? It’s been really difficult for many to get back the admin user ID but it’s so
It’s been always seen that Woocommerce has only an option to tag the product price but if you want to update product price on cart/checkout pages, our provided snippets are going to help you to do this easily.
Note: WooCommerce Plugin must be configured in order to use these snippets.
Let’s check how it is working…
This snippet can be used to update product price on cart/checkout page, it doesn’t matter whatever the price is set. See line#6 to replace the value.
/**
* Update product price on cart/checkout pages
*/
function ldninjas_filter_product_price( $cart ) {
foreach ( $cart->get_cart() as $item ) {
$item['data']->set_price( 100 );
}
}
add_action( 'woocommerce_before_calculate_totals', 'ldninjas_filter_product_price' );
The snippet will help to update variable product price on cart/checkout page. You just need to replace the price value in line#7.
/**
* Update variable product price on cart/checkout pages
*/
function ldninjas_filter_variable_product_price( $cart ) {
foreach ( $cart->get_cart() as $item ) {
if( wc_get_product( $item['product_id'] )->is_type( 'variable' ) ) {
$item['data']->set_price( 100 );
}
}
}
add_action( 'woocommerce_before_calculate_totals', 'ldninjas_filter_variable_product_price' );
The snippet will help to update specific product price on cart/checkout page. Replace the price value in line#7.
/**
* Update specific product price on cart/checkout pages
*/
function ldninjas_filter_specific_product_price( $cart ) {
foreach ( $cart->get_cart() as $item ) {
if( $item['product_id'] == 12 ) {
$item['data']->set_price( 100 );
}
}
}
add_action( 'woocommerce_before_calculate_totals', 'ldninjas_filter_specific_product_price' );
So, All you need to add this code snippet to your theme functions.php file to update its product price on cart/checkout page on woocommerce sites. Enjoy!
Share This Post How to get admin User ID? It’s been really difficult for many to get back the admin user ID but it’s so
Share This Post Award GamiPress on RCPro Membership Renewal Do you think users can also be awarded points/badges/ranks while RCPro Membership renewal? Yes, you can
Share This Post Custom Message with myCRED Transfer MyCred assigns different points to the users but it’s been sometime noticed that the users want to
Once you send the details, we will be shortly back to you. Thanks!
This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.
Strictly Necessary Cookie should be enabled at all times so that we can save your preferences for cookie settings.
If you disable this cookie, we will not be able to save your preferences. This means that every time you visit this website you will need to enable or disable cookies again.