Advertisement
designerken

Original Class

Dec 29th, 2014
440
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.95 KB | None | 0 0
  1. <?php
  2.  
  3. class WC_Swatch_Picker {
  4.  
  5.     private $size;
  6.     private $attributes;
  7.     private $selected_attributes;
  8.     private $swatch_type_options;
  9.  
  10.     public function __construct( $product_id, $attributes, $selected_attributes ) {
  11.         $this->swatch_type_options = maybe_unserialize( get_post_meta( $product_id, '_swatch_type_options', true ) );
  12.  
  13.         if ( !$this->swatch_type_options ) {
  14.             $this->swatch_type_options = array();
  15.         }
  16.  
  17.         $product_configured_size = get_post_meta( $product_id, '_swatch_size', true );
  18.         if ( !$product_configured_size ) {
  19.             $this->size = 'swatches_image_size';
  20.         } else {
  21.             $this->size = $product_configured_size;
  22.         }
  23.  
  24.         $this->attributes = $attributes;
  25.         $this->selected_attributes = $selected_attributes;
  26.     }
  27.  
  28.     public function picker() {
  29.         ?>
  30.  
  31.         <table class="variations-table" cellspacing="0">
  32.             <tbody>
  33.                 <?php
  34.                 $loop = 0;
  35.                 foreach ( $this->attributes as $name => $options ) : $loop++;
  36.                     $st_name = sanitize_title( $name );
  37.                     $hashed_name = md5( $st_name );
  38.                     $lookup_name = '';
  39.                     if ( isset( $this->swatch_type_options[$hashed_name] ) ) {
  40.                         $lookup_name = $hashed_name;
  41.                     } elseif ( isset( $this->swatch_type_options[$st_name] ) ) {
  42.                         $lookup_name = $st_name;
  43.                     }
  44.                     ?>
  45.                     <tr>
  46.                         <td class="label"><label for="<?php echo $st_name; ?>"><?php echo WC_Swatches_Compatibility::wc_attribute_label( $name ); ?></label></td>
  47.                         <td>
  48.                             <?php
  49.                             if ( isset( $this->swatch_type_options[$lookup_name] ) ) {
  50.                                 $picker_type = $this->swatch_type_options[$lookup_name]['type'];
  51.                                 if ( $picker_type == 'default' ) {
  52.                                     $this->render_default( $st_name, $options );
  53.                                 } else {
  54.                                     $this->render_picker( $st_name, $options, $name );
  55.                                 }
  56.                             } else {
  57.                                 $this->render_default( $st_name, $options );
  58.                             }
  59.                             ?>
  60.                         </td>
  61.                     </tr>
  62.                 <?php endforeach; ?>
  63.             </tbody>
  64.         </table>
  65.         <?php
  66.     }
  67.  
  68. //More public_funtions here....
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement