Created
October 16, 2020 02:35
-
-
Save jennlee20/745c700471723f654efac60459051f92 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function jennsup_custom_checkout_product_validation() { | |
global $woocommerce; | |
$cart_items = $woocommerce->cart->cart_contents; | |
$restrict_product_id = 9787; //your restricted product id | |
foreach ( $cart_items as $key => $item ) { | |
$product_id = $item['product_id'] == 0 ? $item['variation_id']: $item['product_id']; | |
$product_qty = $item['quantity']; | |
if($product_id == $restrict_product_id) { | |
if ($product_qty > 1) | |
wc_add_notice("Sorry, you only can purchase 1 quantity for this item.", 'error'); | |
$customer_email = sanitize_text_field($_POST['billing_email']); | |
//check email purchase before? | |
$repeat_order = wc_customer_bought_product( $customer_email, get_current_user_id(), $product_id ); | |
if($repeat_order) | |
wc_add_notice("Sorry, you had purchased this special item before.", 'error'); | |
} | |
} | |
} | |
add_action('woocommerce_checkout_process','jennsup_custom_checkout_product_validation'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment