• Resolved ghrana21

    (@ghrana21)


    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){
    			remove_action( 'woocommerce_after_checkout_validation', 'place_test_request211',10 );
    			   wc_add_notice( 'we already have a user with the same mobile number and has recieved the gift', 'error' );
    			
    		}
    	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 );
    	}
    	elseif($phone!=$phone2 && $billing1==1){
    		wc_add_notice('phone not equal but recieved a gift','error');
    	 add_action(  'woocommerce_after_checkout_validation', 'place_test_request211',10,1 );
    	}
    	  elseif($phone!=$phone2 && $billing1==0){
    		 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 4 replies - 1 through 4 (of 4 total)
  • Abiola Ogodo

    (@oaoyadeyi)

    @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 WooCommerce Developer Resources Portal for resources on developing for WooCommerce.

    You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Hi @ghrana21

    We haven’t heard back from you in a while, so I’m going to mark this as resolved – we’ll be here if and/or when you are ready to continue.

    Thread Starter ghrana21

    (@ghrana21)

    NOT SOLVED YET.
    ANY HELP!!

    Igor H

    (@ihereira)

    Hello there,

    We understand what you are saying.

    Please be advised that custom coding goes beyond the scope of support we are able to provide in this forum.

    If you do require more help with the actual coding, we’d recommend hiring a developer or one of the customization experts listed at https://woocommerce.com/customizations/.

    Thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Make validation on the phone number not to recieve agift when clicking checkbox’ is closed to new replies.