Admin Dashboard, Product Archive, Product Page

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.

100 WooCommerce Conversion Rate Optimisation Tips

This field is for validation purposes and should be left unchanged.

Let’s collaborate!

Need to outsource WordPress development?

Join forces with UnlimitedWP for an outsourced white label web development service you can truly rely on.

First Timer Here?

Sign up to receive 10% off on your first month with us.

26027
WELCOME OFFER