title: WooCommerce add to cart validation: prevent add to cart
body: <p>I have a probleme with woocommerce that im trying to fix for few days.</p>
  <p>I am creating a website for a guy and he wanted me to add a custom input on the product page, I couldn't do it myself so I used a freelancer online for it.</p>
  <p>On the product page I have an add-to-cart button, quantity input and date input.</p>
  <p>The &quot;date input&quot; is the freelancer did.</p>
  <p>The thing is that when the $_REQUEST['thedate'] is empty the custom error popup but the product still added to the cart.</p>
  <p>the code:(functions.php)</p>
  <pre class="lang-php prettyprint-override"><code>function add_the_date_validation() { 
    if ( empty( $_REQUEST['thedate'] )) {
      wc_add_notice( __( 'Please enter a date.', 'woocommerce' ), 'error' );
      return false;
    }
    return true;
  }
  add_action( 'woocommerce_add_to_cart_validation', 'add_the_date_validation', 10, 5 );    
  </code></pre>
  <p>the view:
  <a href="https://i.stack.imgur.com/a75P6.png" rel="nofollow noreferrer">http://i.stack.imgur.com/a75P6.png</a></p>
  <ul>
  <li>How can i prevent the product to add itslef to the cart?</li>
  </ul>
  <p>other codes the freelancer did:</p>
  <pre class="lang-php prettyprint-override"><code>function save_add_the_date_field( $cart_item_key, $product_id = null, $quantity= null, $variation_id= null, $variation= null ) {
    if( isset( $_REQUEST['thedate'] ) ) {
      WC()-&gt;session-&gt;set( $cart_item_key.'_the_date', $_REQUEST['thedate'] );
    }
  }
  
  add_action( 'woocommerce_add_to_cart', 'save_add_the_date_field', 1, 5 );
  
  function render_meta_on_checkout_order_review_item( $quantity = null, $cart_item = null, $cart_item_key = null ) {
    if( $cart_item_key &amp;&amp; WC()-&gt;session-&gt;__isset( $cart_item_key.'_the_date' ) ) {
      echo $quantity. '&lt;dl class=&quot;&quot;&gt;
                        &lt;dt class=&quot;&quot;&gt;Date: &lt;/dt&gt;
                        &lt;dd class=&quot;&quot;&gt;&lt;p&gt;'. WC()-&gt;session-&gt;get( $cart_item_key.'_the_date') .'&lt;/p&gt;&lt;/dd&gt;
                      &lt;/dl&gt;';
    }
  }
  
  add_filter( 'woocommerce_checkout_cart_item_quantity', 'render_meta_on_checkout_order_review_item', 1, 3 );
  
  function the_date_order_meta_handler( $item_id, $values, $cart_item_key ) {
    if( WC()-&gt;session-&gt;__isset( $cart_item_key.'_the_date' ) ) {
      wc_add_order_item_meta( $item_id, &quot;the_date&quot;, WC()-&gt;session-&gt;get( $cart_item_key.'_the_date') );
    }
  }
  
  add_action( 'woocommerce_add_order_item_meta', 'the_date_order_meta_handler', 1, 3 );
  
  function the_date_force_individual_cart_items($cart_item_data, $product_id) {
    $unique_cart_item_key = md5( microtime().rand() );
    $cart_item_data['unique_key'] = $unique_cart_item_key;
  
    return $cart_item_data;
  }
  
  add_filter( 'woocommerce_add_cart_item_data','the_date_force_individual_cart_items', 10, 2 );
  </code></pre>