Advertisement
sparkweb

FoxyShop: Quantity Range Dropdown

Feb 28th, 2013
683
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.79 KB | None | 0 0
  1. //Ranged dropdowns - put this in your functions.php file
  2. add_action('foxyshop_admin_product_details','my_custom_product_details');
  3. function my_custom_product_details($post_id) {
  4.  
  5.     $fieldname = "_dropdown_qty"; //has to start with _
  6.     $fieldescription = "Qty Groups";
  7.     ?>
  8.     <div style="clear:both"></div>
  9.     <div class="foxyshop_field_control">
  10.         <label for="<?php echo $fieldname; ?>"><?php echo htmlspecialchars($fieldescription); ?></label>
  11.         <input type="text" name="<?php echo $fieldname; ?>" id="<?php echo $fieldname; ?>" value="<?php echo htmlspecialchars(get_post_meta($post_id, $fieldname, 1)); ?>" />
  12.     </div>
  13.     <div style="clear:both"></div>
  14.     <?php
  15.  
  16.  
  17.  
  18.  
  19. }
  20. add_action('foxyshop_save_product','my_save_custom_product_details');
  21. function my_save_custom_product_details($post_id) {
  22.  
  23.     //Enter All of Your Field Names in an array
  24.     $fieldnames = array('_dropdown_qty');
  25.  
  26.     foreach ($fieldnames as $fieldname) {
  27.         $fieldvalue = isset($_POST[$fieldname]) ? $_POST[$fieldname] : '';
  28.         foxyshop_save_meta_data($fieldname, $fieldvalue);
  29.     }
  30.  
  31.     return $post_id;
  32. }
  33. function my_foxyshop_qty() {
  34.     global $product;
  35.     $dropdown_qty = get_post_meta($product['id'], '_dropdown_qty', 1);
  36.     if (!$dropdown_qty) {
  37.         foxyshop_quantity();
  38.         return;
  39.     }
  40.  
  41.     $arr_dropdown = explode(",", $dropdown_qty);
  42.  
  43.     $quantity_title = apply_filters("foxyshop_quantity_title", "Quantity");
  44.     echo '<label class="foxyshop_quantity" for="quantity_' . $product['id'] . '">' . $quantity_title . '</label>'."\n";
  45.     echo '<select class="foxyshop_quantity" name="quantity">';
  46.     for ($i = 0; $i < count($arr_dropdown); $i++) {
  47.         $val = trim($arr_dropdown[$i]);
  48.         echo '<option value="' . $val . foxyshop_get_verification('quantity',$val) . '">' . $val . '</option>' . "\n";
  49.     }
  50.     echo '</select>'."\n";
  51.     echo '<div class="clr"></div>';
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement