Forum Replies Created

Viewing 4 replies - 31 through 34 (of 34 total)
  • Thread Starter pablopaul

    (@pablopaul)

    Hi Jeroen,

    The latest change you made to the plugin you posted for me have fixed the issue. Thank you for this awesome plugin and your fast response to all support questions.

    Best,
    Paul

    Thread Starter pablopaul

    (@pablopaul)

    Hi Jeroen,

    Thank you for being so quick to respond.

    I apologize, I forgot to mention that I installed the version you posted earlier, and I’m still having the same problem.

    Please let me know if there is anything I can provide to help you troubleshoot this issue.

    Thank you,
    Paul

    Thread Starter pablopaul

    (@pablopaul)

    Hi Jeroen,

    I think I have narrowed down my issue to the “local pickup” setting. Before WooCommerce 3.6.2, the validation worked perfectly, even without including a “local pickup” condition. Since 3.6.2, I have tried it with and without the additional “local pickup” condition. It seems to ignore it. If the customer selects “Local Pickup”, the validator still checks their zip code, and if it’s out of range, it won’t let them complete the order.

    Here’s a link to some screenshots of my settings. I’ve also created a clone of the website, but I would need to privately share that link with you if you are interested.

    screenshots of validation settings and order options

    Thread Starter pablopaul

    (@pablopaul)

    Hi Jeroen,

    I tried the updated plugin from the link you provided me a couple weeks ago, but I am still having the same problem. I have the same rule as @mikaelz describes above, and the same problem where the rule always fires and the customer cannot complete their order.

    For now, I’ve removed that rule, and I was able to write a function to deal with our specific zip code validation requirement: it prevents orders from being completed if the customer tries to have any items in the “floral” category delivered outside of our zip code range. I’m including the code below, thinking there’s a small chance it might help you troubleshoot the zip code issue, or might help someone else come up with their own workaround until that problem is resolved.

    Thank you,
    Paul

    
    add_action( 'woocommerce_after_checkout_validation', 'fg_floral_validate', 10, 2 );
    function fg_floral_validate($data, $errors) {
        // Order is valid unless it fails to meet criteria
    
        // Check for floral category
        // Set our flag to be false until we find a product in that category
        $cat_check = false;
                
        // Check each cart item for our category
        foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
                    
            $product = $cart_item['data'];
    
            if ( has_term( 'floral', 'product_cat', $cart_item['product_id']) ) {
                $cat_check = true;
                break;
            }
        }
    
        // if there are any floral items, check the shipping method and zip code
        if ( $cat_check ) {
    
            $ship_method = substr($data['shipping_method'][0], 0, 12);
    
            // if the shipping method is not local pickup, check zip code
            if ($ship_method !== "local_pickup") {
    
                $valid_zips = ["97123", "97124", "97116", "97113"];
                $ship_zip = $data['shipping_postcode'];
    
                // if the customer zip code is not amongst the floral shipping zip codes, then prevent the order and display a message to the customer
                if (!in_array($ship_zip, $valid_zips)) {
                    $errors->add('validation', 'Sorry, we can only deliver floral items to the following zip codes: 97123, 97124, 97116, 97113.' . "<br/>");
                }
            }
        }
    }
    
Viewing 4 replies - 31 through 34 (of 34 total)