Checkbox is not being set

Question

isset not working. My goal is when the checkbox is checked I want to set a variable to a certain value but even when I check the checkbox the value of $mystring would be “no”. Please let me know what I am doing wrong

<form class="cart" enctype="multipart/form-data" method="post" action="#">
<!--more code -->
<input type="checkbox" name="mycheckbox"  />
<!--more code -->
</form> 
<?php
function my_add_cart_item_data( $cart_item, $product_id ) {
/* my problem is here */    
if ( isset( $_POST['mycheckbox'] )  ) {
    $mystring="yes";
 } else {
  $mystring="no";
 }
$cart_item['my_text'] = $mystring;
return $cart_item; 
}
add_filter( 'woocommerce_add_cart_item_data', 'my_add_cart_item_data', 10, 2 );     
?>
0
Yoonji 3 months 0 Answers 10 views 0

Leave an answer