Plugin Directory

Changeset 2700999


Ignore:
Timestamp:
03/29/2022 06:29:38 AM (4 years ago)
Author:
codup
Message:

updated files

Location:
codup-woocommerce-custom-fields/trunk
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • codup-woocommerce-custom-fields/trunk/assets/css/admin/wc-product-custom-fields.css

    r2031381 r2700999  
    11.cwcf_add_field_buttons{
    2     text-align: center;
    3     padding: 10px;
     2    text-align: center;
     3    padding: 10px;
    44}
    55
    66.cwcf_add_text_field{
    7     margin: 0px 5px 0px 5px;
     7    margin: 0px 5px 0px 5px;
    88}
    99
    1010.cwcf_field_container{
    11     border-bottom: 1px dashed #ccc;
    12     margin: 10px;
     11    border-bottom: 1px dashed #ccc;
     12    margin: 10px;
    1313}
    1414
    1515.cwcf_clear{
    16     clear: both;
     16    clear: both;
    1717}
    1818
    1919.cwcf_field_heading{
    20     float: left;
    21     width: 50%;
    22     margin-top: 10px;
    23     margin-bottom: 10px;
    24     font-weight: bold;
    25     font-size: 16px;
     20    float: left;
     21    width: 50%;
     22    margin-top: 10px;
     23    margin-bottom: 10px;
     24    font-weight: bold;
     25    font-size: 16px;
    2626}
    2727
    2828.cwcf_field_delete{
    29     float: right;
    30     width: 50%;
    31     margin-top: 10px;
    32     margin-bottom: 10px;
    33     font-weight: bold;
    34     font-size: 16px;
    35     text-align: right;
     29    float: right;
     30    width: 50%;
     31    margin-top: 10px;
     32    margin-bottom: 10px;
     33    font-weight: bold;
     34    font-size: 16px;
     35    text-align: right;
    3636}
    3737
    3838.cwcf_field_delete a{
    39     text-decoration: none;
     39    text-decoration: none;
    4040}
    4141
    4242#cwcf_wc_product_custom_fields{
    43     border-top: 1px dashed #ccc;
     43    border-top: 1px dashed #ccc;
    4444}
    4545
    4646.cwcf_option_label{
    47     float: left;
    48     width: 40%;
     47    float: left;
     48    width: 40%;
    4949}
    5050
    5151.cwcf_option_label .cwcf_name{
    52     width: 88% !important;
     52    width: 88% !important;
    5353}
    5454
    5555.cwcf_option_value{
    56     float: left;
    57     width: 40%;
     56    float: left;
     57    width: 40%;
    5858}
    5959
    6060.cwcf_option_value .cwcf_name{
    61     width: 88% !important;
     61    width: 88% !important;
    6262}
    6363
    6464.cwcf_option_row{
    65     width: 100%;
    66     list-style: none;
    67     margin: 3px 0px 3px 0px;
    68     float: left;
     65    width: 100%;
     66    list-style: none;
     67    margin: 3px 0px 3px 0px;
     68    float: left;
    6969}
    7070
    7171.cwcf_option_actions{
    72     float: left;
    73     width: 20%;
     72    float: left;
     73    width: 20%;
    7474}
    7575
    7676.cwcf_options_container{
    77     margin: 0px 0px 0px 10px;
    78     padding: 10px;
    79     width: 100%;
    80     float: left;
    81    
     77    margin: 0px 0px 0px 10px;
     78    padding: 10px;
     79    width: 100%;
     80    float: left;
     81
    8282}
    8383
    8484.cwcf_options_wrapper{
    85     border: 1px dashed #ccc;
    86     width: 100%;
    87     float: left;
     85    border: 1px dashed #ccc;
     86    width: 100%;
     87    float: left;
    8888}
    8989
    9090.cwcf_add_more_container{
    91     text-align: center;
    92     margin: 10px 0px 10px 0px;
    93     width: 100%;
    94     float: left;
     91    text-align: center;
     92    margin: 10px 0px 10px 0px;
     93    width: 100%;
     94    float: left;
    9595}
    9696
    9797.cwcf_option_row:first-child .delete_current_option{
    98     display: none;
     98    display: none;
    9999}
  • codup-woocommerce-custom-fields/trunk/assets/css/frontend/wc-product-custom-fields.css

    r2031381 r2700999  
    11.cwcf_product_fields{
    2     width: 100%;
     2    width: 100%;
    33}
    44
    55.cwcf_field_container{
    6     margin-bottom: 20px;
     6    margin-bottom: 20px;
    77}
    88
    99.cwcf_field_label label{
    10     font-weight: bold;
     10    font-weight: bold;
    1111}
    1212
    1313.cwcf_text_field{
    14     width: 100%;
     14    width: 100%;
    1515}
    1616
    1717.cwcf_field_description{
    18     font-size: small;
    19     font-style: italic;
    20     margin: 5px 0px 0px 0px;
     18    font-size: small;
     19    font-style: italic;
     20    margin: 5px 0px 0px 0px;
    2121}
    2222
    2323.cwcf_dropdown{
    24     min-width: 80%;
    25     padding: 5px;
     24    min-width: 80%;
     25    padding: 5px;
    2626}
  • codup-woocommerce-custom-fields/trunk/assets/js/front/wc-product-custom-fields-front.js

    r2031381 r2700999  
    1 jQuery(document).ready(function(){ 
    2     var field_id = [];
    3     jQuery('.hide_field').each(function(){
    4      field_id.push(jQuery(this).val());
    5     });
    6     var len = field_id.length;
    7     for(t=0; t<len; t++) {
    8        
    9     jQuery(document.body).on("change", "input.cb_custom_fields"+field_id[t], function(){
    10        
    11         var selector = jQuery(this);
    12         if(selector.prop("checked") == true) {
    13             selector.attr('required');
    14             selector.siblings().removeAttr("required");
    15        } else {
    16           selector.attr("required", "required");
    17           selector.siblings().attr("required", "required");
    18        }   
    19      
    20     });
    21    }
    22 });
     1jQuery( document ).ready(
     2    function(){
     3        var field_id = [];
     4        jQuery( '.hide_field' ).each(
     5            function(){
     6                field_id.push( jQuery( this ).val() );
     7            }
     8        );
     9        var len = field_id.length;
     10        for (t = 0; t < len; t++) {
     11
     12            jQuery( document.body ).on(
     13                "change",
     14                "input.cb_custom_fields" + field_id[t],
     15                function(){
     16
     17                    var selector = jQuery( this );
     18                    if (selector.prop( "checked" ) == true) {
     19                        selector.attr( 'required' );
     20                        selector.siblings().removeAttr( "required" );
     21                    } else {
     22                        selector.attr( "required", "required" );
     23                        selector.siblings().attr( "required", "required" );
     24                    }
     25
     26                }
     27            );
     28        }
     29    }
     30);
  • codup-woocommerce-custom-fields/trunk/codup-woocommerce-custom-fields.php

    r2388216 r2700999  
    44  Plugin Name: Codup Woocommerce Custom Fields
    55  Description: Add custom fields in Woocommerce Products
    6   Version:     1.1.1.11
     6  Version:     1.1.1.12
    77  Author:      codup.io
    88  Author URI:  http://codup.io/
     
    1111  Text Domain: codup-wc-custom-fields
    1212  WC requires at least: 3.0
    13   WC tested up to: 5.4
     13  WC tested up to: 6.3.1
     14  Tested up to: 5.9.2
    1415 */
    1516
    1617// prevent direct access
    17 if (!defined('ABSPATH'))
    18     exit;
     18if ( ! defined( 'ABSPATH' ) ) {
     19    exit;
     20}
    1921
    20 define('CWCF_NAME', 'Codup Woocommerce Custom Fields');
    21 define('CWCF_VERSION', '1.1.1.7');
    22 define('CWCF_SLUG', 'codup-wcf');
    23 define('CWCF_TEXT_DOMAIN', 'codup-wc-custom-fields');
    24 define('CWCF_PLUGIN_DIR', __DIR__);
    25 define('CWCF_PLUGIN_DIR_URL', plugin_dir_url(__FILE__));
    26 define('CWCF_PLUGIN_BASENAME', plugin_basename(__FILE__));
    27 define('CWCF_TEMPLATE_DIR', CWCF_PLUGIN_DIR . '/templates');
    28 define('CWCF_ASSETS_DIR_URL', CWCF_PLUGIN_DIR_URL . 'assets');
     22define( 'CWCF_NAME', 'Codup Woocommerce Custom Fields' );
     23define( 'CWCF_VERSION', '1.1.1.7' );
     24define( 'CWCF_SLUG', 'codup-wcf' );
     25define( 'CWCF_TEXT_DOMAIN', 'codup-wc-custom-fields' );
     26define( 'CWCF_PLUGIN_DIR', __DIR__ );
     27define( 'CWCF_PLUGIN_DIR_URL', plugin_dir_url( __FILE__ ) );
     28define( 'CWCF_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
     29define( 'CWCF_TEMPLATE_DIR', CWCF_PLUGIN_DIR . '/templates' );
     30define( 'CWCF_ASSETS_DIR_URL', CWCF_PLUGIN_DIR_URL . 'assets' );
    2931
    3032/*
    3133 * Include local dependencies.
    3234 */
    33 include(CWCF_PLUGIN_DIR . '/includes/helper.php');
    34 include(CWCF_PLUGIN_DIR . '/includes/class-codup-wc-custom-fields.php');
     35require CWCF_PLUGIN_DIR . '/includes/helper.php';
     36require CWCF_PLUGIN_DIR . '/includes/class-codup-wc-custom-fields.php';
    3537
    36 if (!class_exists('CodupAds')){
    37     include(CWCF_PLUGIN_DIR.'/lib/codupads/codupads.php');
     38if ( ! class_exists( 'CodupAds' ) ) {
     39    include CWCF_PLUGIN_DIR . '/lib/codupads/codupads.php';
    3840}
    39 new CodupAds(); 
     41new CodupAds();
    4042
    41 add_action("plugins_loaded", "cwcf_check_prerequisite");
     43add_action( 'plugins_loaded', 'cwcf_check_prerequisite' );
    4244
    4345/**
     
    4648 */
    4749function cwcf_check_prerequisite() {
    48     $error = false;
    49    
    50     if (!class_exists('WooCommerce')) {
    51         $error = true;
    52         add_action('admin_notices', 'cwcf_woocommerce_error');
    53     }
    54    
    55     if(!$error) {
    56         new CodupWoocommerceCustomFields();
    57     }
     50    $error = false;
     51
     52    if ( ! class_exists( 'WooCommerce' ) ) {
     53        $error = true;
     54        add_action( 'admin_notices', 'cwcf_woocommerce_error' );
     55    }
     56
     57    if ( ! $error ) {
     58        new CodupWoocommerceCustomFields();
     59    }
    5860}
    5961
     
    6264 */
    6365function cwcf_woocommerce_error() {
    64     echo '<div class="notice notice-error"><p><strong>Codup Wooccommerce Custom Fields</strong> requires <strong>WooCommerce</strong> to work. <strong>Please Activate or Install the Plugin</strong>.</p></div>';
     66    echo '<div class="notice notice-error"><p><strong>Codup Wooccommerce Custom Fields</strong> requires <strong>WooCommerce</strong> to work. <strong>Please Activate or Install the Plugin</strong>.</p></div>';
    6567}
  • codup-woocommerce-custom-fields/trunk/includes/class-codup-wc-custom-fields.php

    r2388216 r2700999  
    11<?php
    22
    3 if (!defined('ABSPATH'))
    4     exit; // Exit if accessed directly
    5 
    6 if (!class_exists('CodupWoocommerceCustomFields')) {
    7 
    8     class CodupWoocommerceCustomFields {
    9        
    10         /**
    11          * Constructor
    12          */
    13         public function __construct() {
    14             add_filter('woocommerce_product_data_tabs', array($this, 'product_custom_fields_tab'));
    15             add_action('woocommerce_product_data_panels', array($this, 'product_custom_fields_content'));
    16             add_action('admin_enqueue_scripts', array($this, 'admin_assets'));
    17             add_action('wp_enqueue_scripts', array($this, 'frontend_assets'));
    18             add_action('woocommerce_process_product_meta', array($this, 'save_product_custom_fields'), 50, 1);
    19             add_action('woocommerce_before_add_to_cart_button', array($this, 'add_custom_fields'), 10, 0);
    20             add_filter('woocommerce_add_cart_item_data', array($this, 'add_custom_field_data_to_cart_item'), 10, 3);
    21             add_action('woocommerce_checkout_create_order_line_item', array( $this, 'add_custom_field_to_order_items' ), 10, 4);
    22             add_filter('woocommerce_get_item_data', array($this, 'display_custom_fields_cart'), 10, 2);
    23             add_action('woocommerce_after_order_itemmeta', array($this, 'display_custom_fields_order'), 10, 3);
    24             add_action('admin_notices', array($this,'wccf_codup_ads_placement') );
    25             add_action('woocommerce_order_item_meta_start', array($this, 'show_custom_fields'), 10, 3);
    26         }
    27        
    28         /**
    29          * Register JS and CSS file in WP-Admin
    30          */
    31         public function admin_assets(){
    32             wp_enqueue_style('cwcf-wc-product-custom-fields-admin', CWCF_ASSETS_DIR_URL . '/css/admin/wc-product-custom-fields.css', false, '1.0.0');
    33             wp_enqueue_script('cwcf-wc-product-custom-fields-admin',CWCF_ASSETS_DIR_URL . '/js/admin/wc-product-custom-fields.js', array('jquery'), false, true);
    34         }
    35        
    36         /**
    37          * Register JS and CSS file
    38          */
    39         public function frontend_assets(){
    40             wp_enqueue_style('cwcf-wc-product-custom-fields', CWCF_ASSETS_DIR_URL . '/css/frontend/wc-product-custom-fields.css', false, '1.0.0');
    41             wp_enqueue_script('cwcf-wc-product-custom-fields-front',CWCF_ASSETS_DIR_URL . '/js/front/wc-product-custom-fields-front.js', array('jquery'), false, true);
    42         }
    43 
    44         public function wccf_codup_ads_placement() {
    45             $screen = get_current_screen();
    46             if( $screen->id == 'product' ) {
    47                 echo do_shortcode("[codup_ads_top]");
    48             }
    49         }
    50        
    51         /**
    52          * Add "Product Custom Fields" tab in woocommerce product add / edit page
    53          * @param type $tabs
    54          * @return array
    55          */
    56         public function product_custom_fields_tab($tabs){
    57            
    58             $tabs['cwcf_product_custom_fields_tab'] = array(
    59         'label' => __('Custom Fields', CWCF_TEXT_DOMAIN),
    60         'target' => 'cwcf_product_custom_fields',
    61             );
    62            
    63             return $tabs;
    64         }
    65        
    66         /**
    67          * Content of "Product Custom Fields" tab
    68          * @global type $woocommerce
    69          * @global type $post
    70          */
    71         public function product_custom_fields_content(){
    72             global $woocommerce, $post;
    73             $last_field_id = get_post_meta($post->ID, 'cwcf_last_field_id', false);     
    74             $last_field_id = count( $last_field_id[0] );           
    75             if(!$last_field_id){
    76                 $last_field_id = 0;
    77             } 
    78             $saved_custom_fields = get_post_meta($post->ID, 'cwcf_product_custom_fields', true);
    79             include(CWCF_TEMPLATE_DIR . '/admin/product-custom-fields.php');
    80         }
    81        
    82         /**
    83          * Save "Product Custom Fields" data
    84          * @param type $product_id
    85          */
    86         public function save_product_custom_fields($product_id){     
    87            
    88             delete_post_meta($product_id, 'cwcf_product_custom_fields');
    89             delete_post_meta($product_id, 'cwcf_last_field_id');           
    90             $field_data = array(); 
    91            
    92             if( isset( $_POST['cwcf_fields'] ) ) {             
    93             $nonce = sanitize_text_field( $_REQUEST['_cwcfnonce'] );
    94            
    95             if( ! wp_verify_nonce( $nonce, 'cwcf-nonce' ) ){
    96                 die();
    97             }   
    98             $cwcf_field = $_POST['cwcf_fields'];
    99            
    100                foreach($cwcf_field as $field_id => $field){             
    101                 $field['cwcf_field_label'] = sanitize_text_field( $field['cwcf_field_label'] );
    102                 $field['cwcf_field_description'] = sanitize_text_field( $field['cwcf_field_description'] );
    103                 $field['cwcf_field_required'] = sanitize_text_field( $field['cwcf_field_required'] );
    104                 $field['cwcf_field_type'] = sanitize_text_field( $field['cwcf_field_type'] );
    105              
    106                 foreach($field as $field_key => $field_value){                   
    107                     if(is_array($field_value)){   
    108                         $option_data = array();                     
    109                         foreach($field_value as $option_index => $option_array){
    110                             foreach($option_array as $option_array_key => $option_value){
    111                                 if($option_value == null)
    112                                 {
    113                                     unset($option_array_key);
    114                                 }
    115                                 else {                               
    116                                 $option_value = stripcslashes($option_value);
    117                                 $option_value = sanitize_text_field($option_value);
    118                                 $option_array[$option_array_key] = $option_value;
    119                                 }                               
    120                             }                                                       
    121                             $option_data[$option_index] = $option_array;                           
    122                             if($option_data[$option_index]['label'] == null || $option_data[$option_index]['value'] == null)
    123                             {
    124                                 unset( $option_data[$option_index] );
    125                             }
    126                         }                       
    127                         $field_data[$field_id][$field_key] = $option_data;                       
    128                     }else{
    129                         $field_value = stripcslashes($field_value);
    130                         $field_value = sanitize_text_field($field_value);
    131                         $field_data[$field_id][$field_key] = $field_value;
    132                     }
    133                 }               
    134              }
    135         }
    136             update_post_meta($product_id, 'cwcf_product_custom_fields', $field_data);
    137             update_post_meta($product_id, 'cwcf_last_field_id', $cwcf_field); 
    138         }
    139        
    140         /**
    141          * Show custom fields on wc product page before cart button
    142          * @global type $post
    143          */
    144         public function add_custom_fields(){
    145             global $post;
    146            
    147             if ( $post->post_type != 'product' ) return $format;
    148            
    149             $fields = get_post_meta($post->ID, 'cwcf_product_custom_fields', true);
    150                        
    151             include(CWCF_TEMPLATE_DIR . '/frontend/product-custom-fields.php');
    152                        
    153         }
    154        
    155         /**
    156          * Add custom fields in cart item meta
    157          * @param type $cart_item_data
    158          * @param type $product_id
    159          * @param type $variation_id
    160          * @return array
    161          */
    162         public function add_custom_field_data_to_cart_item($cart_item_data, $product_id, $variation_id){           
    163             if(isset($_POST['cwcf_fields'])){           
    164                
    165                 $product_custom_fields = get_post_meta($product_id, 'cwcf_product_custom_fields', true);
    166                
    167                 foreach($_POST['cwcf_fields'] as $field_id => $field){
    168                     $cart_item_data['cwcf_fields'][$field_id]['label'] = $product_custom_fields[$field_id]['cwcf_field_label'];
    169                    
    170                     if(is_array($field)){
    171                         $cart_item_data['cwcf_fields'][$field_id]['value'] = implode(",", $field);
    172                     }else{
    173                         $field = sanitize_text_field( $field );
    174                         $cart_item_data['cwcf_fields'][$field_id]['value'] = $field;
    175                     }
    176                 }                           
    177                 return $cart_item_data;
    178             }
    179            
    180             return $cart_item_data;
    181         }
    182        
    183         /**
    184          * Save custom field data in order item meta
    185          * @param type $item
    186          * @param type $cart_item_key
    187          * @param type $values
    188          * @param type $order         
    189          */
    190         public function add_custom_field_to_order_items($item, $cart_item_key, $values, $order){
    191             if ( empty( $values['cwcf_fields'] ) ) {
    192                 return;
    193             }
    194            
    195             $item->add_meta_data( 'cwcf_fields', $values['cwcf_fields'] );
    196         }
    197        
    198         /**
    199          * Display custom fields in cart line item
    200          * @param type $item_data
    201          * @param type $cart_item
    202          * @return array
    203          */
    204         public function display_custom_fields_cart($item_data, $cart_item){
    205             if ( empty( $cart_item['cwcf_fields'] ) ) {
    206         return $item_data;
    207             }                                   
    208                                    
    209            
    210             foreach($cart_item['cwcf_fields'] as $field_id => $field){
    211                 $item_data[] = array(
    212                     'key'     => __($field['label'], CWCF_TEXT_DOMAIN),
    213                     'value'   => wc_clean($field['value']),
    214                     'display' => '',
    215                 );
    216             }
    217            
    218             return $item_data;
    219         }
    220        
    221         /**
    222          * Display custom fields on admin order screen
    223          * @param type $item_id
    224          * @param type $item
    225          * @param type $product
    226          */
    227         public function display_custom_fields_order($item_id, $item, $product) {
    228             if($cwcf_fields = wc_get_order_item_meta($item_id, 'cwcf_fields', true)){               
    229                
    230                 include(CWCF_TEMPLATE_DIR . '/admin/custom-fields-item-meta.php');
    231                
    232             }
    233         }
    234        
    235         /**
    236          * Show custom field on email.
    237          * @param string $order_item_id
    238          * @param object $item
    239          * @param object $order
    240          */
    241         public function show_custom_fields($order_item_id, $item, $order) {
    242            if($cwcf_fields = wc_get_order_item_meta($order_item_id, 'cwcf_fields', true)){               
    243 
    244                 include(CWCF_TEMPLATE_DIR . '/admin/custom-fields-item-meta.php');
    245                
    246             }
    247        
    248         }
    249     }
    250    
     3if ( ! defined( 'ABSPATH' ) ) {
     4    exit; // Exit if accessed directly
    2515}
     6
     7if ( ! class_exists( 'CodupWoocommerceCustomFields' ) ) {
     8
     9    class CodupWoocommerceCustomFields {
     10
     11        /**
     12         * Constructor
     13         */
     14        public function __construct() {
     15            add_filter( 'woocommerce_product_data_tabs', array( $this, 'product_custom_fields_tab' ) );
     16            add_action( 'woocommerce_product_data_panels', array( $this, 'product_custom_fields_content' ) );
     17            add_action( 'admin_enqueue_scripts', array( $this, 'admin_assets' ) );
     18            add_action( 'wp_enqueue_scripts', array( $this, 'frontend_assets' ) );
     19            add_action( 'woocommerce_process_product_meta', array( $this, 'save_product_custom_fields' ), 50, 1 );
     20            add_action( 'woocommerce_before_add_to_cart_button', array( $this, 'add_custom_fields' ), 10, 0 );
     21            add_filter( 'woocommerce_add_cart_item_data', array( $this, 'add_custom_field_data_to_cart_item' ), 10, 3 );
     22            add_action( 'woocommerce_checkout_create_order_line_item', array( $this, 'add_custom_field_to_order_items' ), 10, 4 );
     23            add_filter( 'woocommerce_get_item_data', array( $this, 'display_custom_fields_cart' ), 10, 2 );
     24            add_action( 'woocommerce_after_order_itemmeta', array( $this, 'display_custom_fields_order' ), 10, 3 );
     25            add_action( 'admin_notices', array( $this, 'wccf_codup_ads_placement' ) );
     26            add_action( 'woocommerce_order_item_meta_start', array( $this, 'show_custom_fields' ), 10, 3 );
     27        }
     28
     29        /**
     30         * Register JS and CSS file in WP-Admin
     31         */
     32        public function admin_assets() {
     33            wp_enqueue_style( 'cwcf-wc-product-custom-fields-admin', CWCF_ASSETS_DIR_URL . '/css/admin/wc-product-custom-fields.css', false, '1.0.0' );
     34            wp_enqueue_script( 'cwcf-wc-product-custom-fields-admin', CWCF_ASSETS_DIR_URL . '/js/admin/wc-product-custom-fields.js', array( 'jquery' ), false, true );
     35        }
     36
     37        /**
     38         * Register JS and CSS file
     39         */
     40        public function frontend_assets() {
     41            wp_enqueue_style( 'cwcf-wc-product-custom-fields', CWCF_ASSETS_DIR_URL . '/css/frontend/wc-product-custom-fields.css', false, '1.0.0' );
     42            wp_enqueue_script( 'cwcf-wc-product-custom-fields-front', CWCF_ASSETS_DIR_URL . '/js/front/wc-product-custom-fields-front.js', array( 'jquery' ), false, true );
     43        }
     44
     45        public function wccf_codup_ads_placement() {
     46            $screen = get_current_screen();
     47            if ( $screen->id == 'product' ) {
     48                echo do_shortcode( '[codup_ads_top]' );
     49            }
     50        }
     51
     52        /**
     53         * Add "Product Custom Fields" tab in woocommerce product add / edit page
     54         *
     55         * @param type $tabs
     56         * @return array
     57         */
     58        public function product_custom_fields_tab( $tabs ) {
     59
     60            $tabs['cwcf_product_custom_fields_tab'] = array(
     61                'label'  => __( 'Custom Fields', CWCF_TEXT_DOMAIN ),
     62                'target' => 'cwcf_product_custom_fields',
     63            );
     64
     65            return $tabs;
     66        }
     67
     68        /**
     69         * Content of "Product Custom Fields" tab
     70         *
     71         * @global type $woocommerce
     72         * @global type $post
     73         */
     74        public function product_custom_fields_content() {
     75            global $woocommerce, $post;
     76            $last_field_id = get_post_meta( $post->ID, 'cwcf_last_field_id', false );
     77            $last_field_id = count( $last_field_id[0] );
     78            if ( ! $last_field_id ) {
     79                $last_field_id = 0;
     80            }
     81            $saved_custom_fields = get_post_meta( $post->ID, 'cwcf_product_custom_fields', true );
     82            include CWCF_TEMPLATE_DIR . '/admin/product-custom-fields.php';
     83        }
     84
     85        /**
     86         * Save "Product Custom Fields" data
     87         *
     88         * @param type $product_id
     89         */
     90        public function save_product_custom_fields( $product_id ) {
     91
     92            delete_post_meta( $product_id, 'cwcf_product_custom_fields' );
     93            delete_post_meta( $product_id, 'cwcf_last_field_id' );
     94            $field_data = array();
     95
     96            if ( isset( $_POST['cwcf_fields'] ) ) {
     97                $nonce = sanitize_text_field( $_REQUEST['_cwcfnonce'] );
     98
     99                if ( ! wp_verify_nonce( $nonce, 'cwcf-nonce' ) ) {
     100                    die();
     101                }
     102                $cwcf_field = $_POST['cwcf_fields'];
     103
     104                foreach ( $cwcf_field as $field_id => $field ) {
     105                    $field['cwcf_field_label']       = sanitize_text_field( $field['cwcf_field_label'] );
     106                    $field['cwcf_field_description'] = sanitize_text_field( $field['cwcf_field_description'] );
     107                    $field['cwcf_field_required']    = sanitize_text_field( $field['cwcf_field_required'] );
     108                    $field['cwcf_field_type']        = sanitize_text_field( $field['cwcf_field_type'] );
     109
     110                    foreach ( $field as $field_key => $field_value ) {
     111                        if ( is_array( $field_value ) ) {
     112                            $option_data = array();
     113                            foreach ( $field_value as $option_index => $option_array ) {
     114                                foreach ( $option_array as $option_array_key => $option_value ) {
     115                                    if ( $option_value == null ) {
     116                                          unset( $option_array_key );
     117                                    } else {
     118                                        $option_value                      = stripcslashes( $option_value );
     119                                        $option_value                      = sanitize_text_field( $option_value );
     120                                        $option_array[ $option_array_key ] = $option_value;
     121                                    }
     122                                }
     123                                $option_data[ $option_index ] = $option_array;
     124                                if ( $option_data[ $option_index ]['label'] == null || $option_data[ $option_index ]['value'] == null ) {
     125                                    unset( $option_data[ $option_index ] );
     126                                }
     127                            }
     128                            $field_data[ $field_id ][ $field_key ] = $option_data;
     129                        } else {
     130                            $field_value                           = stripcslashes( $field_value );
     131                            $field_value                           = sanitize_text_field( $field_value );
     132                            $field_data[ $field_id ][ $field_key ] = $field_value;
     133                        }
     134                    }
     135                }
     136            }
     137            update_post_meta( $product_id, 'cwcf_product_custom_fields', $field_data );
     138            update_post_meta( $product_id, 'cwcf_last_field_id', $cwcf_field );
     139        }
     140
     141        /**
     142         * Show custom fields on wc product page before cart button
     143         *
     144         * @global type $post
     145         */
     146        public function add_custom_fields() {
     147            global $post;
     148
     149            if ( $post->post_type != 'product' ) {
     150                return $format;
     151            }
     152
     153            $fields = get_post_meta( $post->ID, 'cwcf_product_custom_fields', true );
     154
     155            include CWCF_TEMPLATE_DIR . '/frontend/product-custom-fields.php';
     156
     157        }
     158
     159        /**
     160         * Add custom fields in cart item meta
     161         *
     162         * @param type $cart_item_data
     163         * @param type $product_id
     164         * @param type $variation_id
     165         * @return array
     166         */
     167        public function add_custom_field_data_to_cart_item( $cart_item_data, $product_id, $variation_id ) {
     168            if ( isset( $_POST['cwcf_fields'] ) ) {
     169
     170                $product_custom_fields = get_post_meta( $product_id, 'cwcf_product_custom_fields', true );
     171
     172                foreach ( $_POST['cwcf_fields'] as $field_id => $field ) {
     173                    $cart_item_data['cwcf_fields'][ $field_id ]['label'] = $product_custom_fields[ $field_id ]['cwcf_field_label'];
     174
     175                    if ( is_array( $field ) ) {
     176                        $cart_item_data['cwcf_fields'][ $field_id ]['value'] = implode( ',', $field );
     177                    } else {
     178                        $field = sanitize_text_field( $field );
     179                        $cart_item_data['cwcf_fields'][ $field_id ]['value'] = $field;
     180                    }
     181                }
     182                return $cart_item_data;
     183            }
     184
     185            return $cart_item_data;
     186        }
     187
     188        /**
     189         * Save custom field data in order item meta
     190         *
     191         * @param type $item
     192         * @param type $cart_item_key
     193         * @param type $values
     194         * @param type $order
     195         */
     196        public function add_custom_field_to_order_items( $item, $cart_item_key, $values, $order ) {
     197            if ( empty( $values['cwcf_fields'] ) ) {
     198                return;
     199            }
     200
     201            $item->add_meta_data( 'cwcf_fields', $values['cwcf_fields'] );
     202        }
     203
     204        /**
     205         * Display custom fields in cart line item
     206         *
     207         * @param type $item_data
     208         * @param type $cart_item
     209         * @return array
     210         */
     211        public function display_custom_fields_cart( $item_data, $cart_item ) {
     212            if ( empty( $cart_item['cwcf_fields'] ) ) {
     213                return $item_data;
     214            }
     215
     216            foreach ( $cart_item['cwcf_fields'] as $field_id => $field ) {
     217                $item_data[] = array(
     218                    'key'     => __( $field['label'], CWCF_TEXT_DOMAIN ),
     219                    'value'   => wc_clean( $field['value'] ),
     220                    'display' => '',
     221                );
     222            }
     223
     224            return $item_data;
     225        }
     226
     227        /**
     228         * Display custom fields on admin order screen
     229         *
     230         * @param type $item_id
     231         * @param type $item
     232         * @param type $product
     233         */
     234        public function display_custom_fields_order( $item_id, $item, $product ) {
     235            if ( $cwcf_fields = wc_get_order_item_meta( $item_id, 'cwcf_fields', true ) ) {
     236
     237                include CWCF_TEMPLATE_DIR . '/admin/custom-fields-item-meta.php';
     238
     239            }
     240        }
     241
     242        /**
     243         * Show custom field on email.
     244         *
     245         * @param string $order_item_id
     246         * @param object $item
     247         * @param object $order
     248         */
     249        public function show_custom_fields( $order_item_id, $item, $order ) {
     250            if ( $cwcf_fields = wc_get_order_item_meta( $order_item_id, 'cwcf_fields', true ) ) {
     251
     252                include CWCF_TEMPLATE_DIR . '/admin/custom-fields-item-meta.php';
     253
     254            }
     255
     256        }
     257    }
     258
     259}
  • codup-woocommerce-custom-fields/trunk/includes/helper.php

    r2031381 r2700999  
    22
    33/**
    4  * Replace unwanted attributes from field html and render on product add / edit page
     4 * Replace unwanted attributes from field html and render on product add / edit page
     5 *
    56 * @param type $saved_custom_fields
    67 */
    7 function cwcf_render_saved_fields($saved_custom_fields){
    8    
    9     foreach($saved_custom_fields as $field_id => $field){
    10        
    11         $field_html = cwcf_include_to_variable(CWCF_TEMPLATE_DIR . '/admin/product-custom-field-' . $field['cwcf_field_type'] . ".php", $field_id, $field);
    12        
     8function cwcf_render_saved_fields( $saved_custom_fields ) {
    139
    14         //Remove unwanted attributes
    15         $field_html = str_replace(' cwcf_name', '', $field_html);
    16         $field_html = str_replace('data-name="cwcf_field_label"', '', $field_html);
    17         $field_html = str_replace('data-name="cwcf_field_description"', '', $field_html);
    18         $field_html = str_replace('data-name="cwcf_field_required"', '', $field_html);
    19         $field_html = str_replace('data-name="cwcf_field_type"', '', $field_html);
    20        
    21         echo $field_html;
    22     }
    23    
     10    foreach ( $saved_custom_fields as $field_id => $field ) {
     11
     12        $field_html = cwcf_include_to_variable( CWCF_TEMPLATE_DIR . '/admin/product-custom-field-' . $field['cwcf_field_type'] . '.php', $field_id, $field );
     13
     14        // Remove unwanted attributes
     15        $field_html = str_replace( ' cwcf_name', '', $field_html );
     16        $field_html = str_replace( 'data-name="cwcf_field_label"', '', $field_html );
     17        $field_html = str_replace( 'data-name="cwcf_field_description"', '', $field_html );
     18        $field_html = str_replace( 'data-name="cwcf_field_required"', '', $field_html );
     19        $field_html = str_replace( 'data-name="cwcf_field_type"', '', $field_html );
     20
     21        echo $field_html;
     22    }
     23
    2424}
    2525
    2626/**
    2727 * Convert fields html template file into variable
     28 *
    2829 * @param type $file
    2930 * @param type $field_id
     
    3132 * @return string
    3233 */
    33 function cwcf_include_to_variable($file, $field_id, $field){
    34     ob_start();
    35     require($file);
    36     return ob_get_clean();
     34function cwcf_include_to_variable( $file, $field_id, $field ) {
     35    ob_start();
     36    require $file;
     37    return ob_get_clean();
    3738}
  • codup-woocommerce-custom-fields/trunk/lib/codupads/codupads.php

    r2031381 r2700999  
    11<?php
    2 if ( !class_exists('CodupAds') ) :
     2if ( ! class_exists( 'CodupAds' ) ) :
    33
    4     class CodupAds {
     4    class CodupAds {
    55
    6         public function __construct() {
    7             add_shortcode('codup_ads_top', array($this, 'codup_render_top_ads'));
    8             add_shortcode('codup_ads_right', array($this, 'codup_render_right_ads'));
    9             add_action('admin_init', array($this, 'add_style_scripts'));
    10             add_action('init', array($this, 'add_style_scripts'));
    11         }
     6        public function __construct() {
     7            add_shortcode( 'codup_ads_top', array( $this, 'codup_render_top_ads' ) );
     8            add_shortcode( 'codup_ads_right', array( $this, 'codup_render_right_ads' ) );
     9            add_action( 'admin_init', array( $this, 'add_style_scripts' ) );
     10            add_action( 'init', array( $this, 'add_style_scripts' ) );
     11        }
    1212
    13         function cwrf_get_woo_version_number() {
    14             if ( !function_exists('get_plugins') )
    15                 require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
     13        function cwrf_get_woo_version_number() {
     14            if ( ! function_exists( 'get_plugins' ) ) {
     15                require_once ABSPATH . 'wp-admin/includes/plugin.php';
     16            }
    1617
    17             $plugin_folder = get_plugins('/' . 'woocommerce');
    18             $plugin_file = 'woocommerce.php';
     18            $plugin_folder = get_plugins( '/' . 'woocommerce' );
     19            $plugin_file  = 'woocommerce.php';
    1920
    20             if ( isset($plugin_folder[$plugin_file]['Version']) ) {
    21                 return $plugin_folder[$plugin_file]['Version'];
    22             }
    23             else {
     21            if ( isset( $plugin_folder[ $plugin_file ]['Version'] ) ) {
     22                return $plugin_folder[ $plugin_file ]['Version'];
     23            } else {
    2424
    25                 return NULL;
    26             }
    27         }
     25                return null;
     26            }
     27        }
    2828
    29         function add_style_scripts() {
    30             $pluginConfig = array(
    31                   "pluginName" => CWCF_NAME,
    32                   "pluginVersion" => CWCF_VERSION,
    33                   "pageSlug" => CWCF_SLUG,
    34                   "wpVersion" => get_bloginfo('version'),
    35                   "wcVersion" => $this->cwrf_get_woo_version_number()
    36             );
    37             wp_enqueue_script(CWCF_NAME, plugin_dir_url(__FILE__) . 'scripts/adscript.js', array('jquery'), CWCF_VERSION, false);
    38             wp_enqueue_style(CWCF_NAME . '- codupads-styles', plugin_dir_url(__FILE__) . 'styles/style.css', array(), CWCF_VERSION, 'all');
    39             wp_localize_script(CWCF_NAME, 'PluginConfig', $pluginConfig);
    40         }
     29        function add_style_scripts() {
     30            $pluginConfig = array(
     31                'pluginName'    => CWCF_NAME,
     32                'pluginVersion' => CWCF_VERSION,
     33                'pageSlug'      => CWCF_SLUG,
     34                'wpVersion'     => get_bloginfo( 'version' ),
     35                'wcVersion'     => $this->cwrf_get_woo_version_number(),
     36            );
     37            wp_enqueue_script( CWCF_NAME, plugin_dir_url( __FILE__ ) . 'scripts/adscript.js', array( 'jquery' ), CWCF_VERSION, false );
     38            wp_enqueue_style( CWCF_NAME . '- codupads-styles', plugin_dir_url( __FILE__ ) . 'styles/style.css', array(), CWCF_VERSION, 'all' );
     39            wp_localize_script( CWCF_NAME, 'PluginConfig', $pluginConfig );
     40        }
    4141
    42         function codup_render_top_ads() {
    43             echo '<div id="codup-topad" class="wrap"></div>';
    44         }
     42        function codup_render_top_ads() {
     43            echo '<div id="codup-topad" class="wrap"></div>';
     44        }
    4545
    46         function codup_render_right_ads() {
    47             echo '<div id="codup-rightad" class="stick-to-right"></div>';
    48         }
     46        function codup_render_right_ads() {
     47            echo '<div id="codup-rightad" class="stick-to-right"></div>';
     48        }
    4949
    50     }
     50    }
    5151
    52    
     52
    5353
    5454endif;
    55        
    56            
    5755
    5856
     57
     58
  • codup-woocommerce-custom-fields/trunk/lib/codupads/scripts/adscript.js

    r2388216 r2700999  
    11(function($) {
    2    
    3     $.ajax({
    4         url: "http://wpads.coduplabs.com/",
    5        
    6         data: {
    7             pluginConfig: PluginConfig
    8         },
    9         type: 'GET',
    10         headers: {
    11             'X-Codup-Ads' : 'ae237uiew4222ghq'
    12         },
    13         success: appendAds
    14     });
    15    
    16     function appendAds(data) {
    172
    18         data = JSON.parse(data);
    19         $('#codup-topad').html(data.topad);
    20         $('#codup-rightad').html(data.rightad);
     3    $.ajax(
     4        {
     5            url: "http://wpads.coduplabs.com/",
    216
    22     }
    23    
    24 })(jQuery);
     7            data: {
     8                pluginConfig: PluginConfig
     9            },
     10            type: 'GET',
     11            headers: {
     12                'X-Codup-Ads' : 'ae237uiew4222ghq'
     13            },
     14            success: appendAds
     15        }
     16    );
     17
     18    function appendAds(data) {
     19
     20        data = JSON.parse( data );
     21        $( '#codup-topad' ).html( data.topad );
     22        $( '#codup-rightad' ).html( data.rightad );
     23
     24    }
     25
     26})( jQuery );
  • codup-woocommerce-custom-fields/trunk/lib/codupads/styles/style.css

    r2031381 r2700999  
    11.codup-settings-page {
    2     width : 68%;
    3     display: inline-block;
    4     float: left;
     2    width : 68%;
     3    display: inline-block;
     4    float: left;
    55}
    66
    77.stick-to-right {
    8     margin-top: 60px;
    9     display: inline-block;
     8    margin-top: 60px;
     9    display: inline-block;
    1010}
    1111
    1212#codup-topad{
    1313    box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
    14     background-color: white;
    15     margin-right: 0;
     14    background-color: white;
     15    margin-right: 0;
    1616}
    1717
    1818#codup-topad img{
    1919    vertical-align: middle;
    20     padding: 10px;
    21     height: 16px;
     20    padding: 10px;
     21    height: 16px;
    2222}
    2323#codup-topad a{
  • codup-woocommerce-custom-fields/trunk/readme.txt

    r2388216 r2700999  
    33Contributors: Codup
    44Tags: Woocommerce, Products, Custom Fields, Orders
    5 Tested up to: 5.5.1
     5Tested up to: 5.9.2
    66Requires PHP: 5.6 or later
    77License: GPLv2 or later
  • codup-woocommerce-custom-fields/trunk/templates/admin/custom-fields-item-meta.php

    r2031381 r2700999  
    11<div class="cwcf_custom_fields_item_meta">
    2    
    3     <?php
    4     foreach($cwcf_fields as $field_id => $field){
    5         ?>
    6         <p>
    7             <b><?php echo $field['label']; ?>:</b> <span class="cwcf_custom_fields_item_meta_value"><?php echo $field['value']; ?></span>
    8         </p>
    9         <?php
    10     }
    11     ?>
     2   
     3    <?php
     4    foreach ( $cwcf_fields as $field_id => $field ) {
     5        ?>
     6        <p>
     7            <b><?php echo $field['label']; ?>:</b> <span class="cwcf_custom_fields_item_meta_value"><?php echo $field['value']; ?></span>
     8        </p>
     9        <?php
     10    }
     11    ?>
    1212</div>
  • codup-woocommerce-custom-fields/trunk/templates/admin/product-custom-field-checkbox.php

    r2031381 r2700999  
    1 <div class="cwcf_checkbox_field cwcf_field_container <?php if(isset($field_id)) { echo 'field_'.$field_id; } ?>">           
    2     <div class="cwcf_field_heading">Checkbox Field</div>
    3     <div class="cwcf_field_delete"><a href="javascript:void(0);">X</a></div>
    4     <div class="cwcf_clear"></div>
     1<div class="cwcf_checkbox_field cwcf_field_container <?php if ( isset( $field_id ) ) {
     2    echo 'field_' . $field_id; } ?>">           
     3    <div class="cwcf_field_heading">Checkbox Field</div>
     4    <div class="cwcf_field_delete"><a href="javascript:void(0);">X</a></div>
     5    <div class="cwcf_clear"></div>
    56
    6     <p class="form-field">
    7         <label>Label</label>
    8         <input type="text" class="short cwcf_name" data-name="cwcf_field_label" <?php if(isset($field_id)) { echo 'name="cwcf_fields['.$field_id.'][cwcf_field_label]"'; } ?> value="<?php if(isset($field["cwcf_field_label"])){ echo $field["cwcf_field_label"]; } ?>">
    9     </p>
    10    
    11     <p>
    12         <b>Options</b>
    13         <div class="cwcf_options_wrapper">
    14             <ul class="cwcf_options_container" id="cb_cwcf_options_container">
    15                 <li class="cwcf_option_row">
    16                     <div class="cwcf_option_label"><input style="width: 85%;" type="text" class="cwcf_name" placeholder="Label" data-name-index="0" data-name-target="label" data-name="cwcf_option" <?php if(isset($field['cwcf_option'][0])) { echo 'name="cwcf_fields['.$field_id.'][cwcf_option][0][label]"'; } if(isset($field['cwcf_option'][0]['label'])){ echo 'value="'.$field['cwcf_option'][0]['label'].'"'; } ?>></div>
    17                     <div class="cwcf_option_value"><input style="width: 85%;" type="text" class="cwcf_name" placeholder="Value" data-name-index="0" data-name-target="value" data-name="cwcf_option" <?php if(isset($field['cwcf_option'][0])) { echo 'name="cwcf_fields['.$field_id.'][cwcf_option][0][value]"'; } if(isset($field['cwcf_option'][0]['value'])){ echo 'value="'.$field['cwcf_option'][0]['value'].'"'; } ?>></div>
    18                     <div class="cwcf_option_actions"><img class="delete_current_option" src="<?php echo CWCF_ASSETS_DIR_URL . '/images/admin/delete.png'; ?>" width="24" height="24"></div>
    19                 </li>
    20                
    21                 <?php
    22                 if(isset($field['cwcf_option'])){
    23                     $temp_options = $field['cwcf_option'];
    24                     unset($temp_options[0]);
     7    <p class="form-field">
     8        <label>Label</label>
     9        <input type="text" class="short cwcf_name" data-name="cwcf_field_label"
     10        <?php
     11        if ( isset( $field_id ) ) {
     12            echo 'name="cwcf_fields[' . $field_id . '][cwcf_field_label]"'; }
     13        ?>
     14         value="
     15        <?php
     16        if ( isset( $field['cwcf_field_label'] ) ) {
     17                echo $field['cwcf_field_label']; }
     18        ?>
     19">
     20    </p>
     21   
     22    <p>
     23        <b>Options</b>
     24        <div class="cwcf_options_wrapper">
     25            <ul class="cwcf_options_container" id="cb_cwcf_options_container">
     26                <li class="cwcf_option_row">
     27                    <div class="cwcf_option_label"><input style="width: 85%;" type="text" class="cwcf_name" placeholder="Label" data-name-index="0" data-name-target="label" data-name="cwcf_option"
     28                    <?php
     29                    if ( isset( $field['cwcf_option'][0] ) ) {
     30                        echo 'name="cwcf_fields[' . $field_id . '][cwcf_option][0][label]"';
     31                    } if ( isset( $field['cwcf_option'][0]['label'] ) ) {
     32                        echo 'value="' . $field['cwcf_option'][0]['label'] . '"'; }
     33                    ?>
     34                    ></div>
     35                    <div class="cwcf_option_value"><input style="width: 85%;" type="text" class="cwcf_name" placeholder="Value" data-name-index="0" data-name-target="value" data-name="cwcf_option"
     36                    <?php
     37                    if ( isset( $field['cwcf_option'][0] ) ) {
     38                                                                                                                                                                                                     echo 'name="cwcf_fields[' . $field_id . '][cwcf_option][0][value]"';
     39                    } if ( isset( $field['cwcf_option'][0]['value'] ) ) {
     40                        echo 'value="' . $field['cwcf_option'][0]['value'] . '"'; }
     41                    ?>
     42                    ></div>
     43                    <div class="cwcf_option_actions"><img class="delete_current_option" src="<?php echo CWCF_ASSETS_DIR_URL . '/images/admin/delete.png'; ?>" width="24" height="24"></div>
     44                </li>
     45               
     46                <?php
     47                if ( isset( $field['cwcf_option'] ) ) {
     48                    $temp_options = $field['cwcf_option'];
     49                    unset( $temp_options[0] );
    2550
    26                     foreach($temp_options as $index => $temp_option){                       
    27                         ?>
    28                         <li class="cwcf_option_row">
    29                             <div class="cwcf_option_label"><input style="width: 85%;" type="text" class="cwcf_name" placeholder="Label" data-name-index="<?php echo $index; ?>" data-name-target="label" data-name="cwcf_option" <?php if(isset($field['cwcf_option'][$index])) { echo 'name="cwcf_fields['.$field_id.'][cwcf_option]['.$index.'][label]"'; } if(isset($temp_option['label'])){ echo 'value="'.$temp_option['label'].'"'; } ?>></div>
    30                             <div class="cwcf_option_value"><input style="width: 85%;" type="text" class="cwcf_name" placeholder="Value" data-name-index="<?php echo $index; ?>" data-name-target="value" data-name="cwcf_option" <?php if(isset($field['cwcf_option'][$index])) { echo 'name="cwcf_fields['.$field_id.'][cwcf_option]['.$index.'][value]"'; } if(isset($temp_option['value'])){ echo 'value="'.$temp_option['value'].'"'; } ?>></div>
    31                             <div class="cwcf_option_actions"><img class="delete_current_option" src="<?php echo CWCF_ASSETS_DIR_URL . '/images/admin/delete.png'; ?>" width="24" height="24"></div>
    32                         </li>
    33                         <?php
    34                     }
    35                 }
    36                 ?>
    37             </ul>
    38            
    39             <div class="cwcf_add_more_container"><img <?php if(isset($field_id)) { echo 'data-field-id="'.$field_id.'"'; } ?> class="add_more_option" id="cb_add_more_option" src="<?php echo CWCF_ASSETS_DIR_URL . '/images/admin/add.png'; ?>" width="24" height="24"></div>
    40         </div>   
    41    
    42         <div class="cwcf_clear"></div>
    43     </p>
    44    
    45     <div class="cwcf_clear"></div>
    46    
    47     <p class="form-field">
    48         <label>Description</label>
    49         <input type="text" class="short cwcf_name" data-name="cwcf_field_description" <?php if(isset($field_id)) { echo 'name="cwcf_fields['.$field_id.'][cwcf_field_description]"'; } ?> value="<?php if(isset($field["cwcf_field_description"])){ echo $field["cwcf_field_description"]; } ?>">
    50     </p>
     51                    foreach ( $temp_options as $index => $temp_option ) {
     52                        ?>
     53                        <li class="cwcf_option_row">
     54                            <div class="cwcf_option_label"><input style="width: 85%;" type="text" class="cwcf_name" placeholder="Label" data-name-index="<?php echo $index; ?>" data-name-target="label" data-name="cwcf_option"
     55                                                                                                                                                                    <?php
     56                                                                                                                                                                    if ( isset( $field['cwcf_option'][ $index ] ) ) {
     57                                                                                                                                                                        echo 'name="cwcf_fields[' . $field_id . '][cwcf_option][' . $index . '][label]"';
     58                                                                                                                                                                    } if ( isset( $temp_option['label'] ) ) {
     59                                                                                                                                                                        echo 'value="' . $temp_option['label'] . '"'; }
     60                                                                                                                                                                    ?>
     61                            ></div>
     62                            <div class="cwcf_option_value"><input style="width: 85%;" type="text" class="cwcf_name" placeholder="Value" data-name-index="<?php echo $index; ?>" data-name-target="value" data-name="cwcf_option"
     63                                                                                                                                                                    <?php
     64                                                                                                                                                                    if ( isset( $field['cwcf_option'][ $index ] ) ) {
     65                                                                                                                                                                                                                                                                                                 echo 'name="cwcf_fields[' . $field_id . '][cwcf_option][' . $index . '][value]"';
     66                                                                                                                                                                    } if ( isset( $temp_option['value'] ) ) {
     67                                                                                                                                                                        echo 'value="' . $temp_option['value'] . '"'; }
     68                                                                                                                                                                    ?>
     69                            ></div>
     70                            <div class="cwcf_option_actions"><img class="delete_current_option" src="<?php echo CWCF_ASSETS_DIR_URL . '/images/admin/delete.png'; ?>" width="24" height="24"></div>
     71                        </li>
     72                        <?php
     73                    }
     74                }
     75                ?>
     76            </ul>
     77           
     78            <div class="cwcf_add_more_container"><img
     79            <?php
     80            if ( isset( $field_id ) ) {
     81                echo 'data-field-id="' . $field_id . '"'; }
     82            ?>
     83             class="add_more_option" id="cb_add_more_option" src="<?php echo CWCF_ASSETS_DIR_URL . '/images/admin/add.png'; ?>" width="24" height="24"></div>
     84        </div>   
     85   
     86        <div class="cwcf_clear"></div>
     87    </p>
     88   
     89    <div class="cwcf_clear"></div>
     90   
     91    <p class="form-field">
     92        <label>Description</label>
     93        <input type="text" class="short cwcf_name" data-name="cwcf_field_description"
     94        <?php
     95        if ( isset( $field_id ) ) {
     96            echo 'name="cwcf_fields[' . $field_id . '][cwcf_field_description]"'; }
     97        ?>
     98         value="
     99        <?php
     100        if ( isset( $field['cwcf_field_description'] ) ) {
     101                echo $field['cwcf_field_description']; }
     102        ?>
     103">
     104    </p>
    51105
    52     <p class="form-field">
    53         <label>Required?</label>
    54         <input type="checkbox" class="cwcf_name" data-name="cwcf_field_required" value="1" <?php if(isset($field_id)) { echo 'name="cwcf_fields['.$field_id.'][cwcf_field_required]"'; } ?> <?php if( $field["cwcf_field_required"] != null ){ echo 'checked'; } ?>>
    55     </p>
    56    
    57     <input type="hidden" data-name="cwcf_row_counter" class="cwcf_name cwcf_row_counter" <?php if(isset($field_id)) { echo 'name="cwcf_fields['.$field_id.'][cwcf_row_counter]"'; } ?> <?php if(isset($field["cwcf_row_counter"])){ echo 'value="'.$field["cwcf_row_counter"].'"'; }else { echo 'value="0"'; } ?>>
    58    
    59     <input type="hidden" class="cwcf_name" data-name="cwcf_field_type" <?php if(isset($field_id)) { echo 'name="cwcf_fields['.$field_id.'][cwcf_field_type]"'; } ?> value="checkbox">
     106    <p class="form-field">
     107        <label>Required?</label>
     108        <input type="checkbox" class="cwcf_name" data-name="cwcf_field_required" value="1"
     109        <?php
     110        if ( isset( $field_id ) ) {
     111            echo 'name="cwcf_fields[' . $field_id . '][cwcf_field_required]"'; }
     112        ?>
     113         <?php
     114            if ( $field['cwcf_field_required'] != null ) {
     115                    echo 'checked'; }
     116            ?>
     117>
     118    </p>
     119   
     120    <input type="hidden" data-name="cwcf_row_counter" class="cwcf_name cwcf_row_counter"
     121    <?php
     122    if ( isset( $field_id ) ) {
     123        echo 'name="cwcf_fields[' . $field_id . '][cwcf_row_counter]"'; }
     124    ?>
     125     <?php
     126        if ( isset( $field['cwcf_row_counter'] ) ) {
     127            echo 'value="' . $field['cwcf_row_counter'] . '"';
     128        } else {
     129            echo 'value="0"'; }
     130        ?>
     131>
     132   
     133    <input type="hidden" class="cwcf_name" data-name="cwcf_field_type"
     134    <?php
     135    if ( isset( $field_id ) ) {
     136        echo 'name="cwcf_fields[' . $field_id . '][cwcf_field_type]"'; }
     137    ?>
     138     value="checkbox">
    60139</div>
     140
  • codup-woocommerce-custom-fields/trunk/templates/admin/product-custom-field-dropdown.php

    r2031381 r2700999  
    1 <div class="cwcf_dropdown_field cwcf_field_container <?php if(isset($field_id)) { echo 'field_'.$field_id; } ?>">           
    2     <div class="cwcf_field_heading">Dropdown Field</div>
    3     <div class="cwcf_field_delete"><a href="javascript:void(0);">X</a></div>
     1<div class="cwcf_dropdown_field cwcf_field_container <?php if ( isset( $field_id ) ) {
     2    echo 'field_' . $field_id; } ?>">           
     3    <div class="cwcf_field_heading">Dropdown Field</div>
     4    <div class="cwcf_field_delete"><a href="javascript:void(0);">X</a></div>
    45
    5     <div class="cwcf_clear"></div>
     6    <div class="cwcf_clear"></div>
    67
    7     <p class="form-field">
    8         <label>Label</label>
    9         <input type="text" class="short cwcf_name" data-name="cwcf_field_label" <?php if(isset($field_id)) { echo 'name="cwcf_fields['.$field_id.'][cwcf_field_label]"'; } ?> value="<?php if(isset($field["cwcf_field_label"])){ echo $field["cwcf_field_label"]; } ?>">
    10     </p>
    11    
    12     <p>
    13         <b>Options</b>
    14         <div class="cwcf_options_wrapper">
    15             <ul class="cwcf_options_container" id="dd_cwcf_options_container">
    16                 <li class="cwcf_option_row">
    17                     <div class="cwcf_option_label"><input style="width: 85%;" type="text" class="cwcf_name" placeholder="Label" data-name-index="0" data-name-target="label" data-name="cwcf_option" <?php if(isset($field['cwcf_option'][0])) { echo 'name="cwcf_fields['.$field_id.'][cwcf_option][0][label]"'; } if(isset($field['cwcf_option'][0]['label'])){ echo 'value="'.$field['cwcf_option'][0]['label'].'"'; } ?>></div>
    18                     <div class="cwcf_option_value"><input style="width: 85%;" type="text" class="cwcf_name" placeholder="Value" data-name-index="0" data-name-target="value" data-name="cwcf_option" <?php if(isset($field['cwcf_option'][0])) { echo 'name="cwcf_fields['.$field_id.'][cwcf_option][0][value]"'; } if(isset($field['cwcf_option'][0]['value'])){ echo 'value="'.$field['cwcf_option'][0]['value'].'"'; } ?>></div>
    19                     <div class="cwcf_option_actions"><img class="delete_current_option" src="<?php echo CWCF_ASSETS_DIR_URL . '/images/admin/delete.png'; ?>" width="24" height="24"></div>
    20                 </li>
    21                
    22                 <?php
    23                 if(isset($field['cwcf_option'])){                   
    24                     $temp_options = $field['cwcf_option'];
    25                    
    26                     unset($temp_options[0]);
     8    <p class="form-field">
     9        <label>Label</label>
     10        <input type="text" class="short cwcf_name" data-name="cwcf_field_label"
     11        <?php
     12        if ( isset( $field_id ) ) {
     13            echo 'name="cwcf_fields[' . $field_id . '][cwcf_field_label]"'; }
     14        ?>
     15         value="
     16        <?php
     17        if ( isset( $field['cwcf_field_label'] ) ) {
     18                echo $field['cwcf_field_label']; }
     19        ?>
     20">
     21    </p>
     22   
     23    <p>
     24        <b>Options</b>
     25        <div class="cwcf_options_wrapper">
     26            <ul class="cwcf_options_container" id="dd_cwcf_options_container">
     27                <li class="cwcf_option_row">
     28                    <div class="cwcf_option_label"><input style="width: 85%;" type="text" class="cwcf_name" placeholder="Label" data-name-index="0" data-name-target="label" data-name="cwcf_option"
     29                    <?php
     30                    if ( isset( $field['cwcf_option'][0] ) ) {
     31                        echo 'name="cwcf_fields[' . $field_id . '][cwcf_option][0][label]"';
     32                    } if ( isset( $field['cwcf_option'][0]['label'] ) ) {
     33                        echo 'value="' . $field['cwcf_option'][0]['label'] . '"'; }
     34                    ?>
     35                    ></div>
     36                    <div class="cwcf_option_value"><input style="width: 85%;" type="text" class="cwcf_name" placeholder="Value" data-name-index="0" data-name-target="value" data-name="cwcf_option"
     37                    <?php
     38                    if ( isset( $field['cwcf_option'][0] ) ) {
     39                                                                                                                                                                                                     echo 'name="cwcf_fields[' . $field_id . '][cwcf_option][0][value]"';
     40                    } if ( isset( $field['cwcf_option'][0]['value'] ) ) {
     41                        echo 'value="' . $field['cwcf_option'][0]['value'] . '"'; }
     42                    ?>
     43                    ></div>
     44                    <div class="cwcf_option_actions"><img class="delete_current_option" src="<?php echo CWCF_ASSETS_DIR_URL . '/images/admin/delete.png'; ?>" width="24" height="24"></div>
     45                </li>
     46               
     47                <?php
    2748
    28                     foreach($temp_options as $index => $temp_option){   
    29                         ?>
    30                         <li class="cwcf_option_row">
    31                             <div class="cwcf_option_label"><input style="width: 85%;" type="text" class="cwcf_name" placeholder="Label" data-name-index="<?php echo $index; ?>" data-name-target="label" data-name="cwcf_option" <?php if(isset($field['cwcf_option'][$index])) { echo 'name="cwcf_fields['.$field_id.'][cwcf_option]['.$index.'][label]"'; } if(isset($temp_option['label'])){ echo 'value="'.$temp_option['label'].'"'; } ?>></div>
    32                             <div class="cwcf_option_value"><input style="width: 85%;" type="text" class="cwcf_name" placeholder="Value" data-name-index="<?php echo $index; ?>" data-name-target="value" data-name="cwcf_option" <?php if(isset($field['cwcf_option'][$index])) { echo 'name="cwcf_fields['.$field_id.'][cwcf_option]['.$index.'][value]"'; } if(isset($temp_option['value'])){ echo 'value="'.$temp_option['value'].'"'; } ?>></div>
    33                             <div class="cwcf_option_actions"><img class="delete_current_option" src="<?php echo CWCF_ASSETS_DIR_URL . '/images/admin/delete.png'; ?>" width="24" height="24"></div>
    34                         </li>
    35                         <?php
    36                     }
    37                 }
    38                 ?>
    39             </ul>
    40            
    41             <div class="cwcf_add_more_container"><img <?php if(isset($field_id)) { echo 'data-field-id="'.$field_id.'"'; } ?> class="add_more_option" id="dd_add_more_option" src="<?php echo CWCF_ASSETS_DIR_URL . '/images/admin/add.png'; ?>" width="24" height="24"></div>
    42         </div>   
    43    
    44         <div class="cwcf_clear"></div>
    45     </p>
    46    
    47     <div class="cwcf_clear"></div>
    48    
    49     <p class="form-field">
    50         <label>Description</label>
    51         <input type="text" class="short cwcf_name" data-name="cwcf_field_description" <?php if(isset($field_id)) { echo 'name="cwcf_fields['.$field_id.'][cwcf_field_description]"'; } ?> value="<?php if(isset($field["cwcf_field_description"])){ echo $field["cwcf_field_description"]; } ?>">
    52     </p>
     49                if ( isset( $field['cwcf_option'] ) ) {
     50                    $temp_options = $field['cwcf_option'];
    5351
    54     <p class="form-field">
    55         <label>Required?</label>
    56         <input type="checkbox" class="cwcf_name" data-name="cwcf_field_required" value="1" <?php if(isset($field_id)) { echo 'name="cwcf_fields['.$field_id.'][cwcf_field_required]"'; } ?> <?php if( $field["cwcf_field_required"] != null ){ echo 'checked'; } ?>>
    57     </p>
    58    
    59     <input type="hidden" data-name="cwcf_row_counter" class="cwcf_name cwcf_row_counter" <?php if(isset($field_id)) { echo 'name="cwcf_fields['.$field_id.'][cwcf_row_counter]"'; } ?> <?php if(isset($field["cwcf_row_counter"])){ echo 'value="'.$field["cwcf_row_counter"].'"'; }else { echo 'value="0"'; } ?>>
    60    
    61     <input type="hidden" class="cwcf_name" data-name="cwcf_field_type" <?php if(isset($field_id)) { echo 'name="cwcf_fields['.$field_id.'][cwcf_field_type]"'; } ?> value="dropdown">
     52                    unset( $temp_options[0] );
     53
     54                    foreach ( $temp_options as $index => $temp_option ) {
     55
     56                        ?>
     57                        <li class="cwcf_option_row">
     58                            <div class="cwcf_option_label"><input style="width: 85%;" type="text" class="cwcf_name" placeholder="Label" data-name-index="<?php echo $index; ?>" data-name-target="label" data-name="cwcf_option"
     59                                                                                                                                                                    <?php
     60                                                                                                                                                                    if ( isset( $field['cwcf_option'][ $index ] ) ) {
     61                                                                                                                                                                        echo 'name="cwcf_fields[' . $field_id . '][cwcf_option][' . $index . '][label]"';
     62                                                                                                                                                                    } if ( isset( $temp_option['label'] ) ) {
     63                                                                                                                                                                        echo 'value="' . $temp_option['label'] . '"'; }
     64                                                                                                                                                                    ?>
     65                            ></div>
     66                            <div class="cwcf_option_value"><input style="width: 85%;" type="text" class="cwcf_name" placeholder="Value" data-name-index="<?php echo $index; ?>" data-name-target="value" data-name="cwcf_option"
     67                                                                                                                                                                    <?php
     68                                                                                                                                                                    if ( isset( $field['cwcf_option'][ $index ] ) ) {
     69                                                                                                                                                                                                                                                                                                 echo 'name="cwcf_fields[' . $field_id . '][cwcf_option][' . $index . '][value]"';
     70                                                                                                                                                                    } if ( isset( $temp_option['value'] ) ) {
     71                                                                                                                                                                        echo 'value="' . $temp_option['value'] . '"'; }
     72                                                                                                                                                                    ?>
     73                            ></div>
     74                            <div class="cwcf_option_actions"><img class="delete_current_option" src="<?php echo CWCF_ASSETS_DIR_URL . '/images/admin/delete.png'; ?>" width="24" height="24"></div>
     75                        </li>
     76                        <?php
     77                    }
     78                }
     79                ?>
     80            </ul>
     81           
     82            <div class="cwcf_add_more_container"><img
     83            <?php
     84            if ( isset( $field_id ) ) {
     85                echo 'data-field-id="' . $field_id . '"'; }
     86            ?>
     87             class="add_more_option" id="dd_add_more_option" src="<?php echo CWCF_ASSETS_DIR_URL . '/images/admin/add.png'; ?>" width="24" height="24"></div>
     88        </div>   
     89   
     90        <div class="cwcf_clear"></div>
     91    </p>
     92   
     93    <div class="cwcf_clear"></div>
     94   
     95    <p class="form-field">
     96        <label>Description</label>
     97        <input type="text" class="short cwcf_name" data-name="cwcf_field_description"
     98        <?php
     99        if ( isset( $field_id ) ) {
     100            echo 'name="cwcf_fields[' . $field_id . '][cwcf_field_description]"'; }
     101        ?>
     102         value="
     103        <?php
     104        if ( isset( $field['cwcf_field_description'] ) ) {
     105                echo $field['cwcf_field_description']; }
     106        ?>
     107">
     108    </p>
     109
     110    <p class="form-field">
     111        <label>Required?</label>
     112        <input type="checkbox" class="cwcf_name" data-name="cwcf_field_required" value="1"
     113        <?php
     114        if ( isset( $field_id ) ) {
     115            echo 'name="cwcf_fields[' . $field_id . '][cwcf_field_required]"'; }
     116        ?>
     117         <?php
     118            if ( $field['cwcf_field_required'] != null ) {
     119                    echo 'checked'; }
     120            ?>
     121>
     122    </p>
     123   
     124    <input type="hidden" data-name="cwcf_row_counter" class="cwcf_name cwcf_row_counter"
     125    <?php
     126    if ( isset( $field_id ) ) {
     127        echo 'name="cwcf_fields[' . $field_id . '][cwcf_row_counter]"'; }
     128    ?>
     129     <?php
     130        if ( isset( $field['cwcf_row_counter'] ) ) {
     131            echo 'value="' . $field['cwcf_row_counter'] . '"';
     132        } else {
     133            echo 'value="0"'; }
     134        ?>
     135>
     136   
     137    <input type="hidden" class="cwcf_name" data-name="cwcf_field_type"
     138    <?php
     139    if ( isset( $field_id ) ) {
     140        echo 'name="cwcf_fields[' . $field_id . '][cwcf_field_type]"'; }
     141    ?>
     142     value="dropdown">
    62143</div>
     144
  • codup-woocommerce-custom-fields/trunk/templates/admin/product-custom-field-radio.php

    r2031381 r2700999  
    1 <div class="cwcf_radio_field cwcf_field_container <?php if(isset($field_id)) { echo 'field_'.$field_id; } ?>">           
    2     <div class="cwcf_field_heading">Radio Field</div>
    3     <div class="cwcf_field_delete"><a href="javascript:void(0);">X</a></div>
     1<div class="cwcf_radio_field cwcf_field_container <?php if ( isset( $field_id ) ) {
     2    echo 'field_' . $field_id; } ?>">           
     3    <div class="cwcf_field_heading">Radio Field</div>
     4    <div class="cwcf_field_delete"><a href="javascript:void(0);">X</a></div>
    45
    5     <div class="cwcf_clear"></div>
     6    <div class="cwcf_clear"></div>
    67
    7     <p class="form-field">
    8         <label>Label</label>
    9         <input type="text" class="short cwcf_name" data-name="cwcf_field_label" <?php if(isset($field_id)) { echo 'name="cwcf_fields['.$field_id.'][cwcf_field_label]"'; } ?> value="<?php if(isset($field["cwcf_field_label"])){ echo $field["cwcf_field_label"]; } ?>">
    10     </p>
    11    
    12     <p>
    13         <b>Options</b>
    14         <div class="cwcf_options_wrapper">
    15             <ul class="cwcf_options_container" id="rd_cwcf_options_container">
    16                 <li class="cwcf_option_row">
    17                     <div class="cwcf_option_label"><input style="width: 85%;" type="text" class="cwcf_name" placeholder="Label" data-name-index="0" data-name-target="label" data-name="cwcf_option" <?php if(isset($field['cwcf_option'][0])) { echo 'name="cwcf_fields['.$field_id.'][cwcf_option][0][label]"'; } if(isset($field['cwcf_option'][0]['label'])){ echo 'value="'.$field['cwcf_option'][0]['label'].'"'; } ?>></div>
    18                     <div class="cwcf_option_value"><input style="width: 85%;" type="text" class="cwcf_name" placeholder="Value" data-name-index="0" data-name-target="value" data-name="cwcf_option" <?php if(isset($field['cwcf_option'][0])) { echo 'name="cwcf_fields['.$field_id.'][cwcf_option][0][value]"'; } if(isset($field['cwcf_option'][0]['value'])){ echo 'value="'.$field['cwcf_option'][0]['value'].'"'; } ?>></div>
    19                     <div class="cwcf_option_actions"><img class="delete_current_option" src="<?php echo CWCF_ASSETS_DIR_URL . '/images/admin/delete.png'; ?>" width="24" height="24"></div>
    20                 </li>
    21                
    22                 <?php
    23                 if(isset($field['cwcf_option'])){
    24                     $temp_options = $field['cwcf_option'];                   
    25                     unset($temp_options[0]);
    26                     foreach($temp_options as $index => $temp_option){                       
    27                         ?>
    28                         <li class="cwcf_option_row">
    29                             <div class="cwcf_option_label"><input style="width: 85%;" type="text" class="cwcf_name" placeholder="Label" data-name-index="<?php echo $index; ?>" data-name-target="label" data-name="cwcf_option" <?php if(isset($field['cwcf_option'][$index])) { echo 'name="cwcf_fields['.$field_id.'][cwcf_option]['.$index.'][label]"'; } if(isset($temp_option['label'])){ echo 'value="'.$temp_option['label'].'"'; } ?>></div>
    30                             <div class="cwcf_option_value"><input style="width: 85%;" type="text" class="cwcf_name" placeholder="Value" data-name-index="<?php echo $index; ?>" data-name-target="value" data-name="cwcf_option" <?php if(isset($field['cwcf_option'][$index])) { echo 'name="cwcf_fields['.$field_id.'][cwcf_option]['.$index.'][value]"'; } if(isset($temp_option['value'])){ echo 'value="'.$temp_option['value'].'"'; } ?>></div>
    31                             <div class="cwcf_option_actions"><img class="delete_current_option" src="<?php echo CWCF_ASSETS_DIR_URL . '/images/admin/delete.png'; ?>" width="24" height="24"></div>
    32                         </li>
    33                         <?php
    34                     }
    35                 }
    36                 ?>
    37             </ul>
    38            
    39             <div class="cwcf_add_more_container"><img <?php if(isset($field_id)) { echo 'data-field-id="'.$field_id.'"'; } ?> class="add_more_option" id="rd_add_more_option" src="<?php echo CWCF_ASSETS_DIR_URL . '/images/admin/add.png'; ?>" width="24" height="24"></div>
    40         </div>   
    41    
    42         <div class="cwcf_clear"></div>
    43     </p>
    44    
    45     <div class="cwcf_clear"></div>
    46    
    47     <p class="form-field">
    48         <label>Description</label>
    49         <input type="text" class="short cwcf_name" data-name="cwcf_field_description" <?php if(isset($field_id)) { echo 'name="cwcf_fields['.$field_id.'][cwcf_field_description]"'; } ?> value="<?php if(isset($field["cwcf_field_description"])){ echo $field["cwcf_field_description"]; } ?>">
    50     </p>
     8    <p class="form-field">
     9        <label>Label</label>
     10        <input type="text" class="short cwcf_name" data-name="cwcf_field_label"
     11        <?php
     12        if ( isset( $field_id ) ) {
     13            echo 'name="cwcf_fields[' . $field_id . '][cwcf_field_label]"'; }
     14        ?>
     15         value="
     16        <?php
     17        if ( isset( $field['cwcf_field_label'] ) ) {
     18                echo $field['cwcf_field_label']; }
     19        ?>
     20">
     21    </p>
     22   
     23    <p>
     24        <b>Options</b>
     25        <div class="cwcf_options_wrapper">
     26            <ul class="cwcf_options_container" id="rd_cwcf_options_container">
     27                <li class="cwcf_option_row">
     28                    <div class="cwcf_option_label"><input style="width: 85%;" type="text" class="cwcf_name" placeholder="Label" data-name-index="0" data-name-target="label" data-name="cwcf_option"
     29                    <?php
     30                    if ( isset( $field['cwcf_option'][0] ) ) {
     31                        echo 'name="cwcf_fields[' . $field_id . '][cwcf_option][0][label]"';
     32                    } if ( isset( $field['cwcf_option'][0]['label'] ) ) {
     33                        echo 'value="' . $field['cwcf_option'][0]['label'] . '"'; }
     34                    ?>
     35                    ></div>
     36                    <div class="cwcf_option_value"><input style="width: 85%;" type="text" class="cwcf_name" placeholder="Value" data-name-index="0" data-name-target="value" data-name="cwcf_option"
     37                    <?php
     38                    if ( isset( $field['cwcf_option'][0] ) ) {
     39                                                                                                                                                                                                     echo 'name="cwcf_fields[' . $field_id . '][cwcf_option][0][value]"';
     40                    } if ( isset( $field['cwcf_option'][0]['value'] ) ) {
     41                        echo 'value="' . $field['cwcf_option'][0]['value'] . '"'; }
     42                    ?>
     43                    ></div>
     44                    <div class="cwcf_option_actions"><img class="delete_current_option" src="<?php echo CWCF_ASSETS_DIR_URL . '/images/admin/delete.png'; ?>" width="24" height="24"></div>
     45                </li>
     46               
     47                <?php
     48                if ( isset( $field['cwcf_option'] ) ) {
     49                    $temp_options = $field['cwcf_option'];
     50                    unset( $temp_options[0] );
     51                    foreach ( $temp_options as $index => $temp_option ) {
     52                        ?>
     53                        <li class="cwcf_option_row">
     54                            <div class="cwcf_option_label"><input style="width: 85%;" type="text" class="cwcf_name" placeholder="Label" data-name-index="<?php echo $index; ?>" data-name-target="label" data-name="cwcf_option"
     55                                                                                                                                                                    <?php
     56                                                                                                                                                                    if ( isset( $field['cwcf_option'][ $index ] ) ) {
     57                                                                                                                                                                                                                                                                                                              echo 'name="cwcf_fields[' . $field_id . '][cwcf_option][' . $index . '][label]"';
     58                                                                                                                                                                    } if ( isset( $temp_option['label'] ) ) {
     59                                                                                                                                                                                                                                                                                                             echo 'value="' . $temp_option['label'] . '"'; }
     60                                                                                                                                                                    ?>
     61                                                                                                                                                                    ></div>
     62                            <div class="cwcf_option_value"><input style="width: 85%;" type="text" class="cwcf_name" placeholder="Value" data-name-index="<?php echo $index; ?>" data-name-target="value" data-name="cwcf_option"
     63                                                                                                                                                                    <?php
     64                                                                                                                                                                    if ( isset( $field['cwcf_option'][ $index ] ) ) {
     65                                                                                                                                                                                                                                                                                                                            echo 'name="cwcf_fields[' . $field_id . '][cwcf_option][' . $index . '][value]"';
     66                                                                                                                                                                    } if ( isset( $temp_option['value'] ) ) {
     67                                                                                                                                                                                                                                                                                                              echo 'value="' . $temp_option['value'] . '"'; }
     68                                                                                                                                                                    ?>
     69                                                                                                                                                                    ></div>
     70                            <div class="cwcf_option_actions"><img class="delete_current_option" src="<?php echo CWCF_ASSETS_DIR_URL . '/images/admin/delete.png'; ?>" width="24" height="24"></div>
     71                        </li>
     72                        <?php
     73                    }
     74                }
     75                ?>
     76            </ul>
     77           
     78            <div class="cwcf_add_more_container"><img
     79            <?php
     80            if ( isset( $field_id ) ) {
     81                echo 'data-field-id="' . $field_id . '"'; }
     82            ?>
     83             class="add_more_option" id="rd_add_more_option" src="<?php echo CWCF_ASSETS_DIR_URL . '/images/admin/add.png'; ?>" width="24" height="24"></div>
     84        </div>   
     85   
     86        <div class="cwcf_clear"></div>
     87    </p>
     88   
     89    <div class="cwcf_clear"></div>
     90   
     91    <p class="form-field">
     92        <label>Description</label>
     93        <input type="text" class="short cwcf_name" data-name="cwcf_field_description"
     94        <?php
     95        if ( isset( $field_id ) ) {
     96            echo 'name="cwcf_fields[' . $field_id . '][cwcf_field_description]"'; }
     97        ?>
     98         value="
     99        <?php
     100        if ( isset( $field['cwcf_field_description'] ) ) {
     101                echo $field['cwcf_field_description']; }
     102        ?>
     103">
     104    </p>
    51105
    52     <p class="form-field">
    53         <label>Required?</label>
    54         <input type="checkbox" class="cwcf_name" data-name="cwcf_field_required" value="1" <?php if(isset($field_id)) { echo 'name="cwcf_fields['.$field_id.'][cwcf_field_required]"'; } ?> <?php if( $field["cwcf_field_required"] != null ){ echo 'checked'; } ?>>
    55     </p>
    56    
    57     <input type="hidden" data-name="cwcf_row_counter" class="cwcf_name cwcf_row_counter" <?php if(isset($field_id)) { echo 'name="cwcf_fields['.$field_id.'][cwcf_row_counter]"'; } ?> <?php if(isset($field["cwcf_row_counter"])){ echo 'value="'.$field["cwcf_row_counter"].'"'; }else { echo 'value="0"'; } ?>>
    58    
    59     <input type="hidden" class="cwcf_name" data-name="cwcf_field_type" <?php if(isset($field_id)) { echo 'name="cwcf_fields['.$field_id.'][cwcf_field_type]"'; } ?> value="radio">
     106    <p class="form-field">
     107        <label>Required?</label>
     108        <input type="checkbox" class="cwcf_name" data-name="cwcf_field_required" value="1"
     109        <?php
     110        if ( isset( $field_id ) ) {
     111            echo 'name="cwcf_fields[' . $field_id . '][cwcf_field_required]"'; }
     112        ?>
     113         <?php
     114            if ( $field['cwcf_field_required'] != null ) {
     115                    echo 'checked'; }
     116            ?>
     117>
     118    </p>
     119   
     120    <input type="hidden" data-name="cwcf_row_counter" class="cwcf_name cwcf_row_counter"
     121    <?php
     122    if ( isset( $field_id ) ) {
     123        echo 'name="cwcf_fields[' . $field_id . '][cwcf_row_counter]"'; }
     124    ?>
     125     <?php
     126        if ( isset( $field['cwcf_row_counter'] ) ) {
     127            echo 'value="' . $field['cwcf_row_counter'] . '"';
     128        } else {
     129            echo 'value="0"'; }
     130        ?>
     131>
     132   
     133    <input type="hidden" class="cwcf_name" data-name="cwcf_field_type"
     134    <?php
     135    if ( isset( $field_id ) ) {
     136        echo 'name="cwcf_fields[' . $field_id . '][cwcf_field_type]"'; }
     137    ?>
     138     value="radio">
    60139</div>
     140
  • codup-woocommerce-custom-fields/trunk/templates/admin/product-custom-field-text.php

    r2031381 r2700999  
    1 <div class="cwcf_text_field cwcf_field_container <?php if(isset($field_id)) { echo 'field_'.$field_id; } ?>">           
    2     <div class="cwcf_field_heading">Text Field</div>
    3     <div class="cwcf_field_delete"><a href="javascript:void(0);">X</a></div>
     1<div class="cwcf_text_field cwcf_field_container <?php if ( isset( $field_id ) ) {
     2    echo 'field_' . $field_id; } ?>">           
     3    <div class="cwcf_field_heading">Text Field</div>
     4    <div class="cwcf_field_delete"><a href="javascript:void(0);">X</a></div>
    45
    5     <div class="cwcf_clear"></div>
     6    <div class="cwcf_clear"></div>
    67
    7     <p class="form-field">
    8         <label>Label</label>
    9         <input type="text" class="short cwcf_name" data-name="cwcf_field_label" <?php if(isset($field_id)) { echo 'name="cwcf_fields['.$field_id.'][cwcf_field_label]"'; } ?> value="<?php if(isset($field["cwcf_field_label"])){ echo $field["cwcf_field_label"]; } ?>">
    10     </p>
     8    <p class="form-field">
     9        <label>Label</label>
     10        <input type="text" class="short cwcf_name" data-name="cwcf_field_label"
     11        <?php
     12        if ( isset( $field_id ) ) {
     13            echo 'name="cwcf_fields[' . $field_id . '][cwcf_field_label]"'; }
     14        ?>
     15         value="
     16        <?php
     17        if ( isset( $field['cwcf_field_label'] ) ) {
     18                echo $field['cwcf_field_label']; }
     19        ?>
     20">
     21    </p>
    1122
    12     <p class="form-field">
    13         <label>Description</label>
    14         <input type="text" class="short cwcf_name" data-name="cwcf_field_description" <?php if(isset($field_id)) { echo 'name="cwcf_fields['.$field_id.'][cwcf_field_description]"'; } ?> value="<?php if(isset($field["cwcf_field_description"])){ echo $field["cwcf_field_description"]; } ?>">
    15     </p>
     23    <p class="form-field">
     24        <label>Description</label>
     25        <input type="text" class="short cwcf_name" data-name="cwcf_field_description"
     26        <?php
     27        if ( isset( $field_id ) ) {
     28            echo 'name="cwcf_fields[' . $field_id . '][cwcf_field_description]"'; }
     29        ?>
     30         value="
     31        <?php
     32        if ( isset( $field['cwcf_field_description'] ) ) {
     33                echo $field['cwcf_field_description']; }
     34        ?>
     35">
     36    </p>
    1637
    17     <p class="form-field">
    18         <label>Required?</label>
    19         <input type="checkbox" class="cwcf_name" data-name="cwcf_field_required" value="1" <?php if(isset($field_id)) { echo 'name="cwcf_fields['.$field_id.'][cwcf_field_required]"'; } ?> <?php if( $field["cwcf_field_required"] != null ){ echo 'checked'; } ?>>
    20     </p>
     38    <p class="form-field">
     39        <label>Required?</label>
     40        <input type="checkbox" class="cwcf_name" data-name="cwcf_field_required" value="1"
     41        <?php
     42        if ( isset( $field_id ) ) {
     43            echo 'name="cwcf_fields[' . $field_id . '][cwcf_field_required]"'; }
     44        ?>
     45         <?php
     46            if ( $field['cwcf_field_required'] != null ) {
     47                    echo 'checked'; }
     48            ?>
     49>
     50    </p>
    2151
    22     <input type="hidden" class="cwcf_name" data-name="cwcf_field_type" <?php if(isset($field_id)) { echo 'name="cwcf_fields['.$field_id.'][cwcf_field_type]"'; } ?> value="text">
     52    <input type="hidden" class="cwcf_name" data-name="cwcf_field_type"
     53    <?php
     54    if ( isset( $field_id ) ) {
     55        echo 'name="cwcf_fields[' . $field_id . '][cwcf_field_type]"'; }
     56    ?>
     57     value="text">
    2358</div>
     59
  • codup-woocommerce-custom-fields/trunk/templates/admin/product-custom-field-textarea.php

    r2388216 r2700999  
    1 <div class="cwcf_textarea_field cwcf_field_container <?php if(isset($field_id)) { echo 'field_'.$field_id; } ?>">           
    2     <div class="cwcf_field_heading">Textarea Field</div>
    3     <div class="cwcf_field_delete"><a href="javascript:void(0);">X</a></div>
    4    
    5     <div class="cwcf_clear"></div>
     1<div class="cwcf_textarea_field cwcf_field_container <?php if ( isset( $field_id ) ) {
     2    echo 'field_' . $field_id; } ?>">           
     3    <div class="cwcf_field_heading">Textarea Field</div>
     4    <div class="cwcf_field_delete"><a href="javascript:void(0);">X</a></div>
     5   
     6    <div class="cwcf_clear"></div>
    67
    7     <p class="form-field">
    8         <label>Label</label>
    9         <input type="text" class="short cwcf_name" data-name="cwcf_field_label" <?php if(isset($field_id)) { echo 'name="cwcf_fields['.$field_id.'][cwcf_field_label]"'; } ?> value="<?php if(isset($field["cwcf_field_label"])){ echo $field["cwcf_field_label"]; } ?>">
    10     </p>
     8    <p class="form-field">
     9        <label>Label</label>
     10        <input type="text" class="short cwcf_name" data-name="cwcf_field_label"
     11        <?php
     12        if ( isset( $field_id ) ) {
     13            echo 'name="cwcf_fields[' . $field_id . '][cwcf_field_label]"'; }
     14        ?>
     15         value="
     16        <?php
     17        if ( isset( $field['cwcf_field_label'] ) ) {
     18                echo $field['cwcf_field_label']; }
     19        ?>
     20">
     21    </p>
    1122
    12     <p class="form-field">
    13         <label>Description</label>
    14         <input type="text" class="short cwcf_name" data-name="cwcf_field_description" <?php if(isset($field_id)) { echo 'name="cwcf_fields['.$field_id.'][cwcf_field_description]"'; } ?> value="<?php if(isset($field["cwcf_field_description"])){ echo $field["cwcf_field_description"]; } ?>">
    15     </p>
     23    <p class="form-field">
     24        <label>Description</label>
     25        <input type="text" class="short cwcf_name" data-name="cwcf_field_description"
     26        <?php
     27        if ( isset( $field_id ) ) {
     28            echo 'name="cwcf_fields[' . $field_id . '][cwcf_field_description]"'; }
     29        ?>
     30         value="
     31        <?php
     32        if ( isset( $field['cwcf_field_description'] ) ) {
     33                echo $field['cwcf_field_description']; }
     34        ?>
     35">
     36    </p>
    1637
    17     <p class="form-field">
    18         <label>Required?</label>
    19         <input type="checkbox" class="cwcf_name" data-name="cwcf_field_required" value="1" <?php if(isset($field_id)) { echo 'name="cwcf_fields['.$field_id.'][cwcf_field_required]"'; } ?> <?php if( $field["cwcf_field_required"] != null ){ echo 'checked'; } ?>>
    20     </p>
     38    <p class="form-field">
     39        <label>Required?</label>
     40        <input type="checkbox" class="cwcf_name" data-name="cwcf_field_required" value="1"
     41        <?php
     42        if ( isset( $field_id ) ) {
     43            echo 'name="cwcf_fields[' . $field_id . '][cwcf_field_required]"'; }
     44        ?>
     45         <?php
     46            if ( $field['cwcf_field_required'] != null ) {
     47                    echo 'checked'; }
     48            ?>
     49>
     50    </p>
    2151
    22     <input type="hidden" class="cwcf_name" data-name="cwcf_field_type" <?php if(isset($field_id)) { echo 'name="cwcf_fields['.$field_id.'][cwcf_field_type]"'; } ?>  value="textarea">
     52    <input type="hidden" class="cwcf_name" data-name="cwcf_field_type"
     53    <?php
     54    if ( isset( $field_id ) ) {
     55        echo 'name="cwcf_fields[' . $field_id . '][cwcf_field_type]"'; }
     56    ?>
     57      value="textarea">
    2358</div>
     59
  • codup-woocommerce-custom-fields/trunk/templates/admin/product-custom-fields.php

    r2388216 r2700999  
    11<div id="cwcf_product_custom_fields" class="panel woocommerce_options_panel">   
    2     <div class="cwcf_add_field_buttons">
    3         <a href="javascript:void(0);" data-action="text" class="cwcf_field_button button button-primary">Single Text</a>
    4         <a href="javascript:void(0);" data-action="textarea" class="cwcf_field_button button button-primary">Textarea</a>
    5         <a href="javascript:void(0);" data-action="dropdown" class="cwcf_field_button button button-primary">Dropdown</a>
    6         <a href="javascript:void(0);" data-action="checkbox" class="cwcf_field_button button button-primary">Checkbox</a>
    7         <a href="javascript:void(0);" data-action="radio" class="cwcf_field_button button button-primary">Radio</a>
    8     </div>
     2    <div class="cwcf_add_field_buttons">
     3        <a href="javascript:void(0);" data-action="text" class="cwcf_field_button button button-primary">Single Text</a>
     4        <a href="javascript:void(0);" data-action="textarea" class="cwcf_field_button button button-primary">Textarea</a>
     5        <a href="javascript:void(0);" data-action="dropdown" class="cwcf_field_button button button-primary">Dropdown</a>
     6        <a href="javascript:void(0);" data-action="checkbox" class="cwcf_field_button button button-primary">Checkbox</a>
     7        <a href="javascript:void(0);" data-action="radio" class="cwcf_field_button button button-primary">Radio</a>
     8    </div>
    99
    10     <div id="cwcf_wc_product_custom_fields">
    11         <?php
    12         if($saved_custom_fields){
    13             if(is_array($saved_custom_fields)){
    14                 cwcf_render_saved_fields($saved_custom_fields);
    15             }
    16         }
    17         ?>
    18     </div>
     10    <div id="cwcf_wc_product_custom_fields">
     11        <?php
     12        if ( $saved_custom_fields ) {
     13            if ( is_array( $saved_custom_fields ) ) {
     14                cwcf_render_saved_fields( $saved_custom_fields );
     15            }
     16        }
     17        ?>
     18    </div>
    1919
    20     <?php $nonce = wp_create_nonce('cwcf-nonce'); ?>
    21     <input type="hidden" id="_cwcfnonce" name="_cwcfnonce" value="<?php echo $nonce; ?>" />
    22     <input type="hidden" id="cwcf_last_field_id" name="cwcf_last_field_id" value="<?php echo $last_field_id; ?>">
    23    
    24     <div class="cwcf_models" style="display: none;">
    25         <?php
    26         include(CWCF_TEMPLATE_DIR . '/admin/product-custom-field-text.php');
    27         include(CWCF_TEMPLATE_DIR . '/admin/product-custom-field-textarea.php');
    28         include(CWCF_TEMPLATE_DIR . '/admin/product-custom-field-dropdown.php');
    29         include(CWCF_TEMPLATE_DIR . '/admin/product-custom-field-checkbox.php');
    30         include(CWCF_TEMPLATE_DIR . '/admin/product-custom-field-radio.php');
    31         ?>       
    32     </div>
     20    <?php $nonce = wp_create_nonce( 'cwcf-nonce' ); ?>
     21    <input type="hidden" id="_cwcfnonce" name="_cwcfnonce" value="<?php echo $nonce; ?>" />
     22    <input type="hidden" id="cwcf_last_field_id" name="cwcf_last_field_id" value="<?php echo $last_field_id; ?>">
     23   
     24    <div class="cwcf_models" style="display: none;">
     25        <?php
     26        require CWCF_TEMPLATE_DIR . '/admin/product-custom-field-text.php';
     27        require CWCF_TEMPLATE_DIR . '/admin/product-custom-field-textarea.php';
     28        require CWCF_TEMPLATE_DIR . '/admin/product-custom-field-dropdown.php';
     29        require CWCF_TEMPLATE_DIR . '/admin/product-custom-field-checkbox.php';
     30        require CWCF_TEMPLATE_DIR . '/admin/product-custom-field-radio.php';
     31        ?>
     32               
     33    </div>
    3334</div>
  • codup-woocommerce-custom-fields/trunk/templates/frontend/product-custom-fields.php

    r2031381 r2700999  
    1 <?php 
    2 if($fields){ 
    3  ksort($fields);
    4 ?>
     1<?php
     2if ( $fields ) {
     3    ksort( $fields );
     4    ?>
    55
    6     <div class="cwcf_field_container">
    7         <?php foreach($fields as $field_id => $field){ ?>
    8            
    9             <?php
    10             $required = null;
    11            
    12             if($field['cwcf_field_required'] == 1){
    13                 $required = 'required';
    14             }
    15             ?>
    16        
    17             <div class="cwcf_field_label">           
    18                 <label><?php echo $field['cwcf_field_label']; ?></label>
    19             </div>
    20        
    21             <div class="cwcf_product_fields">
    22                 <?php               
    23                 switch ($field['cwcf_field_type']){
    24                    
    25                     case 'text':
    26                         echo '<input '.$required.' class="cwcf_text_field" type="text" value="" name="cwcf_fields['.$field_id.']">';
    27                         break;
    28                    
    29                     case 'textarea':
    30                         echo '<textarea '.$required.' class="cwcf_textarea_field" name="cwcf_fields['.$field_id.']"></textarea>';
    31                         break;
    32                    
    33                     case 'dropdown':
    34                         if($field['cwcf_option']){
    35                             echo '<select '.$required.' class="cwcf_dropdown" name="cwcf_fields['.$field_id.']">';
    36                                 foreach($field['cwcf_option'] as $option){
    37                                     echo '<option value="'.$option['value'].'">'.$option['label'].'</option>';
    38                                 }
    39                             echo '</select>';
    40                         }
    41                         break;
    42                     case 'checkbox':
    43                         if($field['cwcf_option']){
    44                             echo '<input type="hidden" value='.$field_id.' class="hide_field" />';                                       
    45                             foreach($field['cwcf_option'] as $option)
    46                             {                                 
    47                                 echo '<input '.$required.' name="cwcf_fields['.$field_id.'][]" type="checkbox" class="cb_custom_fields'.$field_id.'" value="'.$option['value'].'">';
    48                                 echo '<label>'.$option['label'].'</label>';
    49                                 echo '<br>';
    50                                
    51                             }                           
    52                         }
    53                         break;
    54                     case 'radio':
    55                         if($field['cwcf_option']){                           
    56                             foreach($field['cwcf_option'] as $option){
    57                                 echo '<input '.$required.' name="cwcf_fields['.$field_id.']" type="radio" value="'.$option['value'].'">';
    58                                 echo '<label>'.$option['label'].'</label>';
    59                                 echo '<br>';
    60                             }                           
    61                         }
    62                         break;
    63                 }
    64                 ?>
    65             </div>
    66        
    67             <div class="cwcf_field_description"><?php echo $field['cwcf_field_description']; ?></div>
    68         <?php } ?>
    69     </div>
     6    <div class="cwcf_field_container">
     7        <?php foreach ( $fields as $field_id => $field ) { ?>
     8           
     9            <?php
     10            $required = null;
    7011
    71 <?php }  ?>
     12            if ( $field['cwcf_field_required'] == 1 ) {
     13                $required = 'required';
     14            }
     15            ?>
     16       
     17            <div class="cwcf_field_label">           
     18                <label><?php echo $field['cwcf_field_label']; ?></label>
     19            </div>
     20       
     21            <div class="cwcf_product_fields">
     22                <?php
     23                switch ( $field['cwcf_field_type'] ) {
     24
     25                    case 'text':
     26                        echo '<input ' . $required . ' class="cwcf_text_field" type="text" value="" name="cwcf_fields[' . $field_id . ']">';
     27                        break;
     28
     29                    case 'textarea':
     30                        echo '<textarea ' . $required . ' class="cwcf_textarea_field" name="cwcf_fields[' . $field_id . ']"></textarea>';
     31                        break;
     32
     33                    case 'dropdown':
     34                        if ( $field['cwcf_option'] ) {
     35                            echo '<select ' . $required . ' class="cwcf_dropdown" name="cwcf_fields[' . $field_id . ']">';
     36                            foreach ( $field['cwcf_option'] as $option ) {
     37                                echo '<option value="' . $option['value'] . '">' . $option['label'] . '</option>';
     38                            }
     39                            echo '</select>';
     40                        }
     41                        break;
     42                    case 'checkbox':
     43                        if ( $field['cwcf_option'] ) {
     44                            echo '<input type="hidden" value=' . $field_id . ' class="hide_field" />';
     45                            foreach ( $field['cwcf_option'] as $option ) {
     46                                echo '<input ' . $required . ' name="cwcf_fields[' . $field_id . '][]" type="checkbox" class="cb_custom_fields' . $field_id . '" value="' . $option['value'] . '">';
     47                                echo '<label>' . $option['label'] . '</label>';
     48                                echo '<br>';
     49
     50                            }
     51                        }
     52                        break;
     53                    case 'radio':
     54                        if ( $field['cwcf_option'] ) {
     55                            foreach ( $field['cwcf_option'] as $option ) {
     56                                echo '<input ' . $required . ' name="cwcf_fields[' . $field_id . ']" type="radio" value="' . $option['value'] . '">';
     57                                echo '<label>' . $option['label'] . '</label>';
     58                                echo '<br>';
     59                            }
     60                        }
     61                        break;
     62                }
     63                ?>
     64            </div>
     65       
     66            <div class="cwcf_field_description"><?php echo $field['cwcf_field_description']; ?></div>
     67        <?php } ?>
     68    </div>
     69
     70<?php } ?>
Note: See TracChangeset for help on using the changeset viewer.