WooCommerce
May 27, 2020

Change cart item prices in WooCommerce

WooCommerce Set Custom Product Price When Adding To Cart – In this article, we’ll see how we can override the price of product when adding the product into cart.

With WooCommerce version 3.0+ you need:

  • To use woocommerce_before_calculate_totals hook instead.
  • To use WC_Cart get_cart() method instead
  • To use WC_product set_price() method instead

Here is the code:

The Code goes in function.php file of your active child theme (or theme) or also in any plugin file.

Note: you can increase the hook priority from 20 to 1000 ( or even 2000 ) when using some few specific plugins or others customizations.

Resource


Related Post


How Create Custom Order in Woocommerce

Paste the code where you can get the customer data Here is the function for creating the order

How to Add Custom Product Fields in WooCommerce

For add custom fields in woocommerce use following code in your current themes functions.php file. This will display at admin product page. This will display at single Product Page. This will display at Cart and Checkout Page. This will display at order received and admin order Page.

Get Currency symbol WooCommerce

You can get current currency in woocommerce using get_woocommerce_currency_symbol(); function.

Add Product to Cart Programmatically Woocommerce

We can add product to WooCommerce cart using add_to_cart() function with $product_id. Code goes in function.php file of your active child theme (or active theme).

WooCommerce Redirect to Custom Thank you Page

The below code allows you to redirect to a custom page after the user has successfully completed a purchase when using WooCommerce plugin. Simply add the below code to the active child theme function.php and replace the URL in the function wp_redirect() to the desired page.

Only Allow 1 Product in the Cart WooCommerce

We can set add to cart limit on WooCommerce cart using woocommerce_add_to_cart_validation filter. Add below code on functions.php file to limit your WooCommerce Cart to just 1 product.


Leave a Reply

Your email address will not be published. Required fields are marked *