Alessio

Forum Replies Created

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • Alessio
    Participant

    I’m writing to provide an update on the order validation issue I reported. I found a temporary solution that unblocks order saving, and I wanted to share it with you.

    The problem stems from the browser’s native HTML5 validation on HPOS order edit pages. It triggers on <input type="number" /> fields with values that don’t conform to the min, max, or step rules set by your plugin. Because the fields are also “not focusable,” the browser completely blocks the save process.

    To work around this, I’ve injected a JavaScript script that removes the validation attributes from the quantity fields when the <b>”Update”</b> button is clicked. I added this code to my functions.php file to ensure it only runs on order edit pages:

    <hr />

    function fix_quantity_validation_issue() {
    $is_wc_order_page = (isset($_GET['page']) && $_GET['page'] === 'wc-orders' && isset($_GET['action']) && $_GET['action'] === 'edit' && isset($_GET['id']));
    
    if (!$is_wc_order_page) {
    return;
    }
    
    ?>
    <script type="text/javascript">
    jQuery(document).ready(function($) {
    $('.save_order').on('click', function(e) {
    $('input.quantity[type="number"]').each(function() {
    $(this).removeAttr('min');
    $(this).removeAttr('max');
    $(this).removeAttr('step');
    });
    });
    });
    </script>
    <?php
    }
    add_action('admin_footer', 'fix_quantity_validation_issue');

    <hr />

    This solution allows me to save existing orders and confirms that the issue is a client-side validation conflict, not a back-end error. I hope this helps you in developing a permanent patch for your plugin.

    Thanks again for your support.

    Best regards,

    Alessio

    • This reply was modified 1 year, 1 month ago by Alessio.
    • This reply was modified 1 year, 1 month ago by Alessio.
    Alessio
    Participant

    I tried the option you suggested, but it doesn’t work. Additionally, I noticed that if the minimum required quantity is 6 and the quantity step is 6, and the product has only 6 in stock, the input goes to <code data-start=”246″ data-end=”261″>type=”hidden” (in this case, it’s the input from a grouped product, with each child product having its own quantity input and add-to-cart button):

    <div class=”quantity”>
    <button type=”button” class=”plus”>+</button>
    <label class=”screen-reader-text” for=”quantity_67e69bb264ee2″>FILETTARE-LAMA FLEX 18 SUPRA quantity</label>
    <input type=”hidden” id=”quantity_67e69bb264ee2″ class=”input-text woosg-qty woosg_qty qty text” name=”woosg_qty_1″ value=”6″ aria-label=”Product quantity” min=”6″ max=”6″ step=”6″ placeholder=”” inputmode=”numeric” autocomplete=”off”>
    <button type=”button” class=”minus”>-</button>
    </div>
    <p class=”” data-start=”889″ data-end=”991″>If I click “Add to Cart,” it works, but I don’t see the quantity, because it goes to <code data-start=”974″ data-end=”990″>type=”hidden.”</p>

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