Prevent Duplicate Orders

If you sell a product that only needs to be purchased once, you can prevent the possibility of accidental duplicate orders by adding the code below to your theme’s functions.php file. This code will prevent customers from purchasing a product more than once using the same email.

Add The Following Code To Your Theme’s Functions.php File

You can access your theme’s functions.php file from Appearance in your WordPress dashboard or from your hosting provider’s file manager.

 function mytheme_limit_sales_by_email() {
  $args = array(
  'post_type' => 'sc_order',
  'post_status' => 'paid',
  'posts_per_page' => 1,

$product_id = intval($_POST['sc_product_id']);


$order_email = sanitize_email($_POST['email']);
  $args['meta_query'] = array(
  'key' => '_sc_product_id',
  'value' => $product_id,
  'key' => '_sc_email',
  'value' => $order_email,

$posts = get_posts($args);
 if (!empty($posts)) {
  echo json_encode(array(
  'error' => "Sorry, you have already purchased this product!",