Advertisement
helgatheviki

check posted data for array and string

Jun 27th, 2024
763
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.66 KB | None | 0 0
  1. $posted_field_name   = 'mnm_quantity';
  2.  
  3. $child_item_quantity = ! empty( $_REQUEST[ $posted_field_name ] ) && ! empty( $_REQUEST[ $posted_field_name ][ $child_product_id ] ) ? intval( $_REQUEST[ $posted_field_name ][ $child_product_id ] ) : 0;
  4.  
  5. // One more check for inputs that are not arrays. Ajax add to cart will frequently not handle array inputs well (esp in themes) so as a last resort let's check for a single string key: ie: "mnm_quantity[99]".
  6. if ( $child_item_quantity <= 0 ) {
  7.     $posted_field_name   .= '[' . $child_product_id . ']';
  8.     $child_item_quantity = ! empty( $_REQUEST[ $posted_field_name ] ) ? intval( $_REQUEST[ $posted_field_name ] ) : 0;
  9. }
  10.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement