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();
}
}