• 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){

    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)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Checkbox snippet code’ is closed to new replies.