In this post, we discuss how you can change the price of a woocommerce product, temporarily, during the checkout process. There are lots of tutorials and free plugins which can be used to learn how to add additional prices to a product. Examples or documentation for changing the actual product price is hard to find.
This article explains woocommerce limitations as well as whats possible. Specifically in this article, we will show you demo code where we allow a html form, to accept payment via woocommerce. To accomplish this, the price calculated by that form, will be the new price of the product.
WHAT CANT BE DONE
Its important to understand your limitations. It can save you hours of research and testing. Lets begin with a few important points, you cannot
- change the name of the product
- have multiple prices for the same product, in the shopping cart multiple times
Understanding these limitations are key. WooCommerce can be tricked short term to display certain things; However, once the page refreshes, it gets the information directly from the database.
More specifically, while building the cart display, woocommerce will only take product information from the database. At the same time, it will not pass cart information while retrieving the data. That means its impossible to link a cart item to specific criteria. You can only link the product ID.
WHAT IS POSSIBLE
We have take a close look at the code base and created a few test case scenarios. In short, here is a list of things you can do
- Assign sub heading/text to the product in the cart
- Change the price of the product in the shopping cart
- Calculate the price based on various criteria during the “add to cart” process
- Total cart price can still be affected by coupons and other discount addons
Ultimately, this means that it’s possible to use an existing product and alter a few of its characteristics during the “add to cart” process. The reasons for changing the value are unimportant. What is important is that whatever your reason, you can make multiple changes to the product price before checkout.
As a developer, woocommerce is one of the best plugins to work with, regardless of genre. Its well thought out with lots of wordpress hooks and filters. With such a large codebase, it may be unreasonable to expect them to document everything. The ability to do dynamic features with their product is definitely not documented anywhere. This post covers options regarding how to manipulate products during checkout.