WooCommerce Remove Prices From Product Automatically After They Are Ordered

Pre-Requisites

There are no pre-requisites in order for you to be able to implement this solution.

How To Implement This Solution?

Simply copy the pre-coded solution to your active theme’s functions.php or preferably the Code Snippets Plugin.

About this Solution

This snippet was requested by one of the members from the WooCommerce Facebook Snippets Community.

This snippet will automatically remove product prices when the product is ordered making it non-purchasable.

This snippet is useful if you are not making use of the stock management feature and require products to become non-purchasable only after they are ordered.

Keep in mind, the price is completely removed from the back-end, hiding both the price and add-to-cart button.

				
					/**
 * Snippet Name:	WooCommerce Remove Prices From Product Automatically After They Are Ordered
 * Snippet Author:	ecommercehints.com
 */ 

add_action( 'woocommerce_thankyou', 'ecommercehints_remove_product_prices_post_purchase' );
function ecommercehints_remove_product_prices_post_purchase ($order_id) {
	$order = wc_get_order($order_id);
    $items = $order->get_items(); 
    foreach ($order->get_items() as $item) {
        $product_id = $item->get_product_id();
        $product = wc_get_product($product_id);
        $product->set_regular_price (''); // Here we set the price to an empty string
        $product->save();
    }
}
				
			

Snippet Benefits

  • Remove admin overhead of manually updating products post-purchase.
  • Programatically update products when they are ordered.
WooCommerce Conversion Rate Optimisation (CRO) eBook
100 WooCommerce Conversion Rate Optimisation Tips

Leave a Reply

If you are going to write code in the comments, please wrap it between code tags.

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

Other Recent Guides

Subscribe To Emails

Get exclusive WooCommerce tips that I only share with email subscribers

Join hundreds of other subscribers