Title: Checkbox snippet code
Last modified: November 3, 2021

---

# Checkbox snippet code

 *  Resolved [ghrana21](https://wordpress.org/support/users/ghrana21/)
 * (@ghrana21)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/checkbox-snippet-code/)
 * Please i need help.
    I have created a checkbox in the checkout page, so that 
   when clients clicked on the checkbox he will receive a gift so far everything
   goes well. Now i have decided to make validation on this checkbox, this validation
   occurs using the phone number of the client, which means if the client of a specific
   phone number (this is known through the comparison of the phone number inserted
   and that saved in the database) have received a gift (which is saved in the database
   where billing checkbox created is equal to 1) the client will not receive another
   gift. I have written a code and add an error in order to know if everything seems
   right but it is not working
 * add_action( ‘woocommerce_checkout_process’, ‘wc_remove_checkout_fields11′ );
   
   function wc_remove_checkout_fields11($current_user_id){ $current_user_id = get_current_user_id();
   $phone = get_user_meta($current_user_id ,’_billing_phone’,true); $billing1= get_user_meta(
   $current_user_id ,’_billing_checkbox’,true); $phone2=$_POST[‘_billing_phone’];
 *  if (isset( $_POST[‘billing_checkbox’]) ) {
 *  if($phone==$phone2 && $billing1==1){
 *  wc_add_notice( ‘we already have a user with the same mobile number and has recieved
   the gift’, ‘error’ );
    remove_action(‘woocommerce_after_checkout_validation’,‘
   place_test_request211’,10,1 );
 *  }
    elseif($phone==$phone2 && $billing1==0){ wc_add_notice(‘phone equal but not
   recieved a gift’,’error’); add_action( ‘woocommerce_after_checkout_validation’,‘
   place_test_request211’,10,1 );
 *  }
    } }
 * This is my code where i have added action inside the if clause in order not to
   stop the action of adding a gift, and remove action to stop the action of adding
   a gift. but it is not working. any advise and help please

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [ghrana21](https://wordpress.org/support/users/ghrana21/)
 * (@ghrana21)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/checkbox-snippet-code/#post-15036224)
 * Any help please!!!!!!!!!!
 *  [3 Sons Development](https://wordpress.org/support/users/3sonsdevelopment/)
 * (@3sonsdevelopment)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/checkbox-snippet-code/#post-15061933)
 * Hey [@ghrana21](https://wordpress.org/support/users/ghrana21/),
 * This is a fairly complex development topic. I’m going to leave it open for a 
   bit to see if anyone is able to chime in to help you out.
 * I can also recommend the following places for more development-oriented questions:
    - WooCommerce Slack Community: [https://woocommerce.com/community-slack/](https://woocommerce.com/community-slack/)
    - WooCommerce Community group on Facebook: [https://www.facebook.com/groups/advanced.woocommerce/](https://www.facebook.com/groups/advanced.woocommerce/)
 * \

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Checkbox snippet code’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce/assets/icon.svg?rev=3234504)
 * [WooCommerce](https://wordpress.org/plugins/woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [3 Sons Development](https://wordpress.org/support/users/3sonsdevelopment/)
 * Last activity: [4 years, 7 months ago](https://wordpress.org/support/topic/checkbox-snippet-code/#post-15061933)
 * Status: resolved