Another request I see a lot of inquiries about as I read more WooCommerce Facebook group posts is how to include additional product information on the Checkout page. Mostly, it’s the product description, short description, or thumbnail that store owners want to include. However, as a better learning experience for me, I’ll target other information and limit the functionality to a specific product. Learn how with me in this article.
The Newsletter for PHP and MySQL Developers
Receive a copy of my ebook, “10 MySQL Tips For Everyone”, absolutely free when you subscribe to the OpenLampTech newsletter.
Note: All of the examples in this post are part of a development/learning WooCommerce install using the default Storefront theme. PHP code is placed in the child themeβs function.php file.
Suppose I want to include a last-minute upsell (for lack of a better word?) for a particular product on the Checkout page. One of my favorite bass fishing lures, the jig, is a great example. (I know I can always use more of my favorite lures and baits π)
If there is only one jig added to the cart and the stock level is less than 5 remaining, we can provide a message that the stock levels are low.
The code below will accomplish this:
add_filter( 'woocommerce_cart_item_name', 'woo_custom_checkout_additional_info', 9999, 3 );
function woo_custom_checkout_additional_info( $name, $cart_item, $cart_item_key ) {
if ( ! is_checkout() ) return $name;
$product = $cart_item['data'];
$quantity = $cart_item['quantity'];
if ( 'football-jig' == $product->slug && $product->get_stock_quantity() <= 5 && $quantity == 1 ) {
$mini_upsell = ' (Grab more now, only '.$product->get_stock_quantity().' left in stock!) ';
return $name . $mini_upsell;
}
}
As shown in the screenshot below, I’ve added 1 Football Jig to the cart:
Now on the Checkout page, we see the message letting the customer know that stock levels are low and it would be an excellent time to buy more:
On the other hand, this custom message will not display for any other products that do not have the slug, ‘football-jig’, nor so if the Football Jig product in the cart has a quantity greater than 1:
I realize this example has some flaws and may not even be feasible in a live shop. However, it was a great learning experience for me with WooCommerce and I hope it was for you also.
Credit Resources
Like always, fantastic existing resources and content online helped me in coming up with a working solution. Be sure and visit these articles below. π
- https://www.businessbloomer.com/woocommerce-easily-get-product-info-title-sku-desc-product-object/
- https://www.businessbloomer.com/woocommerce-show-product-images-checkout-page/
If you see any mistake(s) in the code or know of a better working solution, please share freely in the comments section.
Thank you for reading this post. Please share it with someone else who would enjoy it as well.
Josh Otwell has a passion to grow as a PHP Developer, SQL expert, and technical blogger/writer.
Disclaimer: The majority of examples in this post, are performed in a personal development/learning workstation environment and should not be considered production quality or ready. Your particular goals and needs may vary. Like always, just because you can do something doesn’t mean you should. My opinions are my own.
More ways I can help
- Any of the Web Squadron Mastery Modules can help you with your online web entrepreneurial endeavor(s).
- Get a handle on Google Analytics with this course by the folks over at The Content Technologist.
- Need hosting for your next web application or WordPress site? I highly recommend Hostinger and use them to host my niche bass fishing site. The service is second to none.
- π5 Truths I’ve Come To Realize As a Self-taught Developer
- Mobile wallpapers, digital downloads, photos, development services, and content – all on one Kofi Shop Page. Find your next digital purchase today!
Disclosure: Some of this blog post’s services and product links are affiliate links. At no additional cost to you, should you make a purchase by clicking through one of them, I will receive a commission.
The Newsletter for PHP and MySQL Developers
Receive a copy of my ebook, “10 MySQL Tips For Everyone”, absolutely free when you subscribe to the OpenLampTech newsletter.
π° Get your brand, product, or service the attention it deserves with affordable classified ad placement in the OpenLampTech newsletter. I appreciate your support!