diff --git a/readme.txt b/readme.txt index aed0d3346f5e13a87ecbb5825f6b2d941a6ebf0e..d356d17fbac19f2682a4dd8d8aa578785bcd0578 100644 --- a/readme.txt +++ b/readme.txt @@ -146,4 +146,7 @@ Yes, the plugin has been tested with the latest WordPress release and PHP 8.2. * Bug fix: admin can edit the custom fields = 1.7.9 (13.01.2025) = -* Bug fix: css fix on user edit page \ No newline at end of file +* Bug fix: css fix on user edit page + += 1.7.10 (05.02.2025) = +* Bug fix: the product can only be purchased once \ No newline at end of file diff --git a/src/classes/class-exprdawc-product-page-fronted.php b/src/classes/class-exprdawc-product-page-fronted.php index 2de63070f3ec9ad4f7ce71207318a3f229b4b127..1ef49cae5196d42a8e83f2c414edeef0ad246b8a 100644 --- a/src/classes/class-exprdawc-product-page-fronted.php +++ b/src/classes/class-exprdawc-product-page-fronted.php @@ -269,9 +269,20 @@ class Exprdawc_Product_Page_Fronted { if ( ! $product ) { return $passed; } + $custom_fields = $product->get_meta( '_extra_product_fields', true ); if ( ! empty( $custom_fields ) ) { + + // Check if the product can only be purchased once. + if ( $product->get_sold_individually() ) { + foreach ( WC()->cart->get_cart() as $cart_item ) { + if ( $cart_item['product_id'] == $product_id ) { + wc_add_notice( __( 'This product can only be purchased once.', 'extra-product-data-for-woocommerce' ), 'error' ); + return false; + } + } + } foreach ( $custom_fields as $index_num => $input_field_array ) { // Actual label lowercase and without spaces and _ are -.