Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

FoxyShop: Customize Product Details Box

sparkweb Jan 17th, 2012 838 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. //Code to Allow Featured Product Checkbox or Other Special Custom Fields in Product Details
  2. //Place this in your functions.php file
  3. //Edit the field names and descriptions in the first function
  4. //Then put your field names in the array in the second function
  5.  
  6. //Show New Field in Admin
  7. add_action('foxyshop_admin_product_details','my_custom_product_details');
  8. function my_custom_product_details($post_id) {
  9.        
  10.         //Checkbox Example
  11.         $fieldname = "_is_featured"; //has to start with _
  12.         $fieldescription = "Featured Product";
  13.         ?>
  14.         <div style="clear:both"></div>
  15.         <div class="foxyshop_field_control">
  16.                 <input type="checkbox" name="<?php echo $fieldname; ?>" id="<?php echo $fieldname; ?>" style="float: left; margin: 5px 0 0 10px;"<?php echo checked(get_post_meta($post_id, $fieldname, 1),"on"); ?> />
  17.                 <label style="width: 210px; margin-top: 4px;" for="<?php echo $fieldname; ?>"><?php echo htmlspecialchars($fieldescription); ?></label>
  18.         </div>
  19.         <div style="clear:both"></div>
  20.         <?php
  21.  
  22.  
  23.         //Text Entry Example
  24.         $fieldname = "_special_price"; //has to start with _
  25.         $fieldescription = "Special Price";
  26.         ?>
  27.         <div style="clear:both"></div>
  28.         <div class="foxyshop_field_control">
  29.                 <label for="<?php echo $fieldname; ?>"><?php echo htmlspecialchars($fieldescription); ?></label>
  30.                 <input type="text" name="<?php echo $fieldname; ?>" id="<?php echo $fieldname; ?>" value="<?php echo htmlspecialchars(get_post_meta($post_id, $fieldname, 1)); ?>" />
  31.         </div>
  32.         <div style="clear:both"></div>
  33.         <?php
  34.  
  35.  
  36.  
  37.  
  38. }
  39.  
  40. //Save New Field
  41. add_action('foxyshop_save_product','my_save_custom_product_details');
  42. function my_save_custom_product_details($post_id) {
  43.        
  44.         //Enter All of Your Field Names in an array
  45.         $fieldnames = array('_is_featured', '_special_price');
  46.        
  47.         foreach ($fieldnames as $fieldname) {
  48.                 $fieldvalue = isset($_POST[$fieldname]) ? $_POST[$fieldname] : '';
  49.                 foxyshop_save_meta_data($fieldname, $fieldvalue);
  50.         }
  51.  
  52.         return $post_id;
  53. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top