Code-Snippets-Functions/Execute a function on a child site/WooCommerce/hide-add-to-cart-if-product-purchased.txt

8 lines
327 B
Text

add_filter( 'woocommerce_is_purchasable', 'wc_hide_add_cart_if_already_purchased', 9999, 2 );
function wc_hide_add_cart_if_already_purchased( $is_purchasable, $product ) {
if ( wc_customer_bought_product( '', get_current_user_id(), $product->get_id() ) ) {
$is_purchasable = false;
}
return $is_purchasable;
}