skip to Main Content

i have created some custom woocommerce fields and i’m changing the value of a checkbox using javascript based on some criteria.

var setborder = document.getElementById("setborder");
setborder.disabled = true;
setborder.checked = true;

in the frontend it works perfect, however i’m passing the value of this checkbox in the cart using:

add_filter( 'woocommerce_cart_item_name', 'cart_item_name', 10, 3 );
function cart_item_name( $name, $cart_item, $cart_item_key ) {
 if ($cart_item['setborder'] == 'on') {
        $setborder = __('with border','conditional-single-product');
    }
 return $setborder;
}

When the value is set to checked through Javascript, the if condition is NOT met.
of course if a user clicks the button the if condition is met.
it doesn’t make sense to mee.
do you have any clues?

2

Answers


  1. Chosen as BEST ANSWER

    For some really wierd reason the issue is resolved if i remove

    setborder.disabled = true;
    

    i found a workaround by adding

    setborder.style.display = "none";
    

    Some insight on this would be really helpful.


  2. your question is not clear enough and your code snippets are somewhat confusing. However, you should make changes to the checkbox attributes (in this case the value attribute of the checkbox) using keypress or click event of the your search criteria element then update your display to visualize behavior. Then pass your value to PHP via ajax call

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search