Hide add to cart if the product has already been purchased in WooCommerce

Hide add to cart if the product has already been purchased in WooCommerce on child sites.

Snippet Type

Execute on Child Sites

Snippet

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;
}
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.