• Is there an efficient way to add custom validations to custom_checkout_field_process function?

    By default:

    /**
     * Process the checkout
     **/
    add_action('woocommerce_checkout_process', 'my_custom_checkout_field_process');
    
    function my_custom_checkout_field_process() {
        global $woocommerce;
    
        // Check if set, if its not set add an error.
        if (!$_POST['my_field_name'])
             $woocommerce->add_error( __('Please enter something into this new shiny field.') );

    The following method seems to a bad practice (case-sensitive, have to add all special characters/symbols). But at least it works for me:

    if ($_POST['my_field_name'] == "basic")
             $woocommerce->add_error( __('<b>Basic</b> already exists.', 'woocommerce') );
        if ($_POST['my_field_name'] == "standard")
             $woocommerce->add_error( __('<b>Standard</b> already exists.', 'woocommerce') );
        if ($_POST['my_field_name'] == "premium")
             $woocommerce->add_error( __('<b>Premium</b> already exists.', 'woocommerce') );

    So today I’ve been trying to figure out how arrays work. I.e.

    $taken = array ('basic", "standard", "premium", "premium1", "premium2", "etc");

    Unfortunately, I’ve been stuck on that part for hours. Could anyone at least point me into the right direction?

  • The topic ‘[Plugin: Woocommerce] Adding custom validations to checkout process’ is closed to new replies.