Plugin Directory

Changeset 3004043


Ignore:
Timestamp:
12/01/2023 04:37:35 AM (2 years ago)
Author:
artiosmedia
Message:

Update to version 1.4.5

Location:
product-code-for-woocommerce
Files:
54 added
13 edited

Legend:

Unmodified
Added
Removed
  • product-code-for-woocommerce/trunk/classes/class-pcfw-admin-settings.php

    r3000925 r3004043  
    33namespace Artiosmedia\WC_Product_Code;
    44
    5 class PCFW_Admin_settings {
     5class PCFW_Admin_Settings {
    66
    77    public function actions() {
     
    2626
    2727        // add_action( 'woocommerce_product_quick_edit_end', [ $this, 'add_quick_edit_field' ] );
    28         add_action("admin_notices", array($this, "admin_notice"));
    29         add_action("wp_ajax_product_code_dismiss_notice", array($this, "dismiss_notice"));
     28        add_action('admin_notices', array($this, 'admin_notice'));
     29        add_action('wp_ajax_product_code_dismiss_notice', array($this, 'dismiss_notice'));
    3030
    3131        // Will be removed in next update
    32         add_action("wp_ajax_product_code_update_database", array($this, "update_database"));
     32        add_action('wp_ajax_product_code_update_database', array($this, 'update_database'));
    3333
    3434        //add product code to admin column
    35         add_action("manage_edit-product_columns", array($this, 'product_column'));
    36         add_action("manage_posts_custom_column", array($this, 'product_column_value'));
     35        add_action('manage_edit-product_columns', array($this, 'product_column'));
     36        add_action('manage_posts_custom_column', array($this, 'product_column_value'));
    3737
    3838        //add product code to quick edit
    39         add_action('woocommerce_product_quick_edit_start',  array($this, 'pcfw_woocommerce_product_quick_edit_start'));
    40         add_action('woocommerce_product_quick_edit_save',  array($this, 'pcfw_woocommerce_product_quick_edit_save'));
     39        add_action('woocommerce_product_quick_edit_start', array($this, 'pcfw_woocommerce_product_quick_edit_start'));
     40        add_action('woocommerce_product_quick_edit_save', array($this, 'pcfw_woocommerce_product_quick_edit_save'));
    4141
    4242
     
    5050    public function enqueue() {
    5151        $screen = get_current_screen();
    52         wp_enqueue_script("product-code-admin-generic", sprintf(
    53             "%s/assets/js/generic_admin.js",
     52        wp_enqueue_script('product-code-admin-generic', sprintf(
     53            '%s/assets/js/generic_admin.js',
    5454            PRODUCT_CODE_URL
    55         ), array("jquery"), PRODUCT_CODE_VERSION);
    56 
    57         wp_localize_script("product-code-admin-generic", "PRODUCT_CODE_ADMIN", array("ajax" =>
    58         admin_url("admin-ajax.php")));
     55        ), array('jquery'), PRODUCT_CODE_VERSION);
     56
     57        wp_localize_script('product-code-admin-generic', 'PRODUCT_CODE_ADMIN', array('ajax' => admin_url('admin-ajax.php')));
    5958
    6059        if ($screen && 'product' === $screen->post_type) {
     
    6261            wp_enqueue_script('wc_product_code_admin', PRODUCT_CODE_URL . '/assets/js/' .
    6362                'stl_admin_custom.js', ['jquery'], PRODUCT_CODE_VERSION);
    64             wp_localize_script("wc_product_code_admin", "i18n", array("product_code_title" =>  __('Product code', 'product-code-for-woocommerce')));
     63            wp_localize_script('wc_product_code_admin', 'i18n', array('product_code_title' =>  __('Product code', 'product-code-for-woocommerce')));
    6564
    6665            add_action('admin_footer', array($this, 'inline_javascript'));
     
    6968
    7069    public function update_database() {
    71         if (current_user_can("manage_options")) {
     70        if (current_user_can('manage_options')) {
    7271            global $wpdb;
    73             $query = "UPDATE " . $wpdb->prefix . "postmeta
    74         SET meta_key = '_product_code'
    75         WHERE meta_key = '_product_code_variant'";
    76             $results = $wpdb->get_results($query, ARRAY_A);
    77             $query = "UPDATE " . $wpdb->prefix . "postmeta
    78         SET meta_key = '_product_code_second'
    79         WHERE meta_key = '_product_code_variant_second'";
    80             $results2 = $wpdb->get_results($query, ARRAY_A);
     72
     73            $results = $wpdb->get_results("UPDATE {$wpdb->prefix}postmeta SET meta_key = '_product_code' WHERE meta_key = '_product_code_variant'", ARRAY_A);
     74            $results2 = $wpdb->get_results("UPDATE {$wpdb->prefix}postmeta SET meta_key = '_product_code_second' WHERE meta_key = '_product_code_variant_second'", ARRAY_A);
     75
    8176            if (is_array($results) && is_array($results2)) {
    82                 _e("Successfully Updated Redirecting back....", 'product-code-for-woocommerce');
    83                 $query = "DELETE FROM " . $wpdb->prefix . "postmeta
    84         WHERE meta_key = '_product_code_variant'";
    85                 $results2 = $wpdb->get_results($query, ARRAY_A);
     77                esc_html_e('Successfully Updated Redirecting back....', 'product-code-for-woocommerce');
     78                $results2 = $wpdb->get_results("DELETE FROM {$wpdb->prefix}postmeta WHERE meta_key = '_product_code_variant'", ARRAY_A);
    8679                update_option('product_code_db_updated', true);
    8780            } else {
    88                 _e(
    89                     "Failed to update please retry later, Redirecting back... ",
     81                esc_html_e(
     82                    'Failed to update please retry later, Redirecting back... ',
    9083                    'product-code-for-woocommerce'
    9184                );
     
    9487            echo "<script>
    9588              window.setTimeout(function() {
    96                   window.location.replace('" . admin_url('admin.php?page=wc-settings&tab=products&section=product_code_settings') .
     89                  window.location.replace('" . esc_url_raw(admin_url('admin.php?page=wc-settings&tab=products&section=product_code_settings')) .
    9790                "');
    9891              }, 3000);
     
    10497
    10598    public function dismiss_notice() {
    106         if (current_user_can("manage_options")) {
    107             if (!empty($_POST["dismissed_final"])) {
    108                 update_option("product_code_notice_dismiss", null);
    109             } else {
    110                 update_option("product_code_notice_dismiss", date('Y-m-d', strtotime('+30 days')));
    111             }
    112             wp_send_json(array("status" => true));
     99        $post_data = filter_input_array(INPUT_POST, FILTER_SANITIZE_SPECIAL_CHARS);
     100
     101        if (current_user_can('manage_options')) {
     102            if (!empty(sanitize_text_field($post_data['dismissed_final']))) {
     103                update_option('product_code_notice_dismiss', null);
     104            } else {
     105                update_option('product_code_notice_dismiss', gmdate('Y-m-d', strtotime('+30 days')));
     106            }
     107            wp_send_json(array('status' => true));
    113108        }
    114109    }
    115110    public function admin_notice() {
    116         $last_dismissed = get_option("product_code_notice_dismiss");
     111        $last_dismissed = get_option('product_code_notice_dismiss');
    117112
    118113        if ($last_dismissed && current_time('timestamp') >= strtotime($last_dismissed)) {
     
    137132                'label' => $label,
    138133                'desc_tip' => true,
    139                 'description' => sprintf(__('%s refers to a company’s unique internal product identifier, needed for online product fulfillment.', 'product-code-for-woocommerce'), $label),
     134                'description' => sprintf(
     135                    /* translators: 1 for label */
     136                    __('%s refers to a company’s unique internal product identifier, needed for online product fulfillment.', 'product-code-for-woocommerce'),
     137                    $label
     138                ),
    140139                'value' => get_post_meta($post->ID, PRODUCT_CODE_FIELD_NAME, true)
    141140            ]);
    142141
    143             if ($displaySecond == 'yes') {
     142            if ('yes' == $displaySecond) {
    144143
    145144                $html .= woocommerce_wp_text_input([
     
    147146                    'label' => $label_second,
    148147                    'desc_tip' => true,
    149                     'description' => sprintf(__('%s refers to a company’s unique internal product identifier, needed for online product fulfillment.', 'product-code-for-woocommerce'), $label_second),
     148                    'description' => sprintf(
     149                        /* translators: 1 for label */
     150                        __('%s refers to a company’s unique internal product identifier, needed for online product fulfillment.', 'product-code-for-woocommerce'),
     151                        $label_second
     152                    ),
    150153                    'value' => get_post_meta($post->ID, PRODUCT_CODE_FIELD_NAME_SECOND, true)
    151154                ]);
     
    156159
    157160    public function save_product_code_meta() {
     161        $post_data = filter_input_array(INPUT_POST, FILTER_SANITIZE_SPECIAL_CHARS);
    158162        global $post;
    159163
    160164        if (
    161             $post->post_type == 'product' && !empty($_POST['woocommerce_meta_nonce']) &&
    162             wp_verify_nonce($_POST['woocommerce_meta_nonce'], 'woocommerce_save_data')
     165            'product' == $post->post_type && !empty($post_data['woocommerce_meta_nonce']) &&
     166            wp_verify_nonce($post_data['woocommerce_meta_nonce'], 'woocommerce_save_data')
    163167        ) {
    164168            $field_name = PRODUCT_CODE_FIELD_NAME;
    165169
    166             if (!empty($_POST[$field_name])) {
    167                 $code = sanitize_text_field($_POST[$field_name]);
    168                 if (!add_post_meta($post->ID, $field_name, $code, true))
     170            if (!empty($post_data[$field_name])) {
     171                $code = sanitize_text_field($post_data[$field_name]);
     172
     173                $add_meta_result = add_post_meta($post->ID, $field_name, $code, true);
     174                if (!$add_meta_result) {
    169175                    update_post_meta($post->ID, $field_name, $code);
     176                }
    170177            } else {
    171178                delete_post_meta($post->ID, $field_name);
     
    175182            $field_name = PRODUCT_CODE_FIELD_NAME_SECOND;
    176183            if (!empty($_POST[$field_name])) {
    177                 $code = sanitize_text_field($_POST[$field_name]);
    178                 if (!add_post_meta($post->ID, $field_name, $code, true))
     184                $code = sanitize_text_field($post_data[$field_name]);
     185                if (!add_post_meta($post->ID, $field_name, $code, true)) {
    179186                    update_post_meta($post->ID, $field_name, $code);
     187                }
    180188            } else {
    181189                delete_post_meta($post->ID, $field_name);
     
    196204
    197205    public function save_variation_field($variation_id, $i) {
     206        $post_data = filter_input_array(INPUT_POST, FILTER_SANITIZE_SPECIAL_CHARS);
    198207
    199208        $field_name = PRODUCT_CODE_FIELD_NAME;
    200209        $form_field_name = sprintf('%s_%d', PRODUCT_CODE_FIELD_NAME, $i);
    201210
    202         if (!empty($_POST[$form_field_name])) {
    203             $code = sanitize_text_field($_POST[$form_field_name]);
    204             if (!add_post_meta($variation_id, $field_name, $code, true))
     211        if (!empty($post_data[$form_field_name])) {
     212            $code = sanitize_text_field($post_data[$form_field_name]);
     213            if (!add_post_meta($variation_id, $field_name, $code, true)) {
    205214                update_post_meta($variation_id, $field_name, $code);
     215            }
    206216        } else {
    207217            delete_post_meta($variation_id, $field_name);
     
    212222        $form_field_name = sprintf('%s_%d', PRODUCT_CODE_FIELD_NAME_SECOND, $i);
    213223
    214         if (!empty($_POST[$form_field_name])) {
    215             $code = sanitize_text_field($_POST[$form_field_name]);
    216             if (!add_post_meta($variation_id, $field_name, $code, true))
     224        if (!empty($post_data[$form_field_name])) {
     225            $code = sanitize_text_field($post_data[$form_field_name]);
     226            if (!add_post_meta($variation_id, $field_name, $code, true)) {
    217227                update_post_meta($variation_id, $field_name, $code);
     228            }
    218229        } else {
    219230            delete_post_meta($variation_id, $field_name);
     
    224235
    225236    public function add_quick_edit_field() {
    226 
    227         /* $field_name = PRODUCT_CODE_FIELD_NAME;
    228         $code = get_post_meta( $post->ID, $field_name, true ); */
    229237        require_once(PRODUCT_CODE_TEMPLATE_PATH . '/quick-edit-text-field.php');
    230         return;
    231238    }
    232239
     
    236243
    237244    public function get_field_title_text() {
    238         $field_title = get_option("product_code_text");
     245        $field_title = get_option('product_code_text');
    239246        if ($field_title) {
    240247            return $field_title;
    241         } else {
    242             return __('Product code', 'product-code-for-woocommerce');
    243         }
     248        }
     249
     250        return __('Product code', 'product-code-for-woocommerce');
    244251    }
    245252
    246253    public function get_second_field_title_text() {
    247         $field_title = get_option("product_code_text_second");
     254        $field_title = get_option('product_code_text_second');
    248255        if ($field_title) {
    249256            return $field_title;
    250         } else {
    251             return __('Product code 2', 'product-code-for-woocommerce');
    252         }
     257        }
     258
     259        return __('Product code 2', 'product-code-for-woocommerce');
    253260    }
    254261
    255262    public function get_edit_field_title_text() {
    256         $field_title = get_option("product_code_quik_edit_text");
     263        $field_title = get_option('product_code_quik_edit_text');
    257264        if ($field_title) {
    258265            return $field_title;
    259         } else {
    260             return __('Code', 'product-code-for-woocommerce');
    261         }
     266        }
     267
     268        return __('Code', 'product-code-for-woocommerce');
    262269    }
    263270
    264271    public function get_second_edit_field_title_text() {
    265         $field_title = get_option("product_code_quik_edit_text_second");
     272        $field_title = get_option('product_code_quik_edit_text_second');
    266273        if ($field_title) {
    267274            return $field_title;
    268         } else {
    269             return __('Code 2', 'product-code-for-woocommerce');
    270         }
     275        }
     276
     277        return __('Code 2', 'product-code-for-woocommerce');
    271278    }
    272279
     
    282289            $new_columns[$key] = $value;
    283290
    284             if ($key === 'sku') {
     291            if ('sku' === $key) {
    285292
    286293                $label = $this->get_edit_field_title_text();
     
    288295
    289296                $new_columns['pcw_product_code'] = $label;
    290                 if (get_option('product_code_second_show') == 'yes') {
     297                if ('yes' == get_option('product_code_second_show')) {
    291298                    $new_columns['pcw_product_code_2'] =  $label_second;
    292299                }
     
    300307        global $post;
    301308
    302         if (is_object($post) && isset($post->post_type) && $post->post_type === 'product' && $column_name === 'pcw_product_code') {
     309        if (is_object($post) && isset($post->post_type) && 'product' === $post->post_type && 'pcw_product_code' === $column_name) {
    303310
    304311            $product = wc_get_product($post->ID);
    305312            $type = $product->get_type();
    306             if ($type === 'variable') {
     313            if ('variable' === $type) {
    307314                $product_code = '';
    308315            } else {
     
    313320                echo '-';
    314321            } else {
    315                 echo $product_code;
    316             }
    317 ?>
    318             <div style="display:none;" class="hidden" id="pcfw_woocommerce_inline_<?php echo $post->ID; ?>">
    319                 <div class="product_code_val"><?php echo get_post_meta($post->ID, PRODUCT_CODE_FIELD_NAME, true); ?></div>
    320                 <div class="product_code_2_val"><?php echo get_post_meta($post->ID, PRODUCT_CODE_FIELD_NAME_SECOND, true); ?></div>
     322                echo esc_html($product_code);
     323            }
     324            ?>
     325            <div style="display:none;" class="hidden" id="pcfw_woocommerce_inline_<?php echo absint($post->ID); ?>">
     326                <div class="product_code_val"><?php echo esc_html(get_post_meta($post->ID, PRODUCT_CODE_FIELD_NAME, true)); ?></div>
     327                <div class="product_code_2_val"><?php echo esc_html(get_post_meta($post->ID, PRODUCT_CODE_FIELD_NAME_SECOND, true)); ?></div>
    321328            <?php
    322329        }
    323330
    324         if (is_object($post) && isset($post->post_type) && $post->post_type === 'product' && $column_name === 'pcw_product_code_2') {
     331        if (is_object($post) && isset($post->post_type) && 'product' === $post->post_type && 'pcw_product_code_2' === $column_name) {
    325332
    326333            $product = wc_get_product($post->ID);
    327334            $type = $product->get_type();
    328             if ($type === 'variable') {
     335            if ('variable' === $type) {
    329336                $product_code = '';
    330337            } else {
     
    335342                echo '-';
    336343            } else {
    337                 echo $product_code;
     344                echo esc_html($product_code);
    338345            }
    339346        }
     
    341348
    342349    public function inline_javascript() {
    343             ?>
     350        ?>
    344351            <script>
    345352                jQuery(function() {
     
    350357                        if (jQuery('body').hasClass('post-type-product')) {
    351358                            if (jQuery('input#pcw_product_code-hide').length > 0) {
    352                                 document.getElementById('pcw_product_code-hide').parentNode.childNodes[1].textContent = '<?php echo __('Product code', 'product-code-for-woocommerce'); ?>';
     359                                document.getElementById('pcw_product_code-hide').parentNode.childNodes[1].textContent = '<?php esc_html_e('Product code', 'product-code-for-woocommerce'); ?>';
    353360                            }
    354361                        }
     
    356363                        if (jQuery('body').hasClass('post-type-product')) {
    357364                            if (jQuery('input#pcw_product_code_2-hide').length > 0) {
    358                                 document.getElementById('pcw_product_code_2-hide').parentNode.childNodes[1].textContent = '<?php echo __('Product code 2', 'product-code-for-woocommerce'); ?>';
     365                                document.getElementById('pcw_product_code_2-hide').parentNode.childNodes[1].textContent = '<?php esc_html_e('Product code 2', 'product-code-for-woocommerce'); ?>';
    359366                            }
    360367                        }
     
    378385        ?>
    379386            <label class="product_code_1_label">
    380                 <span class="title product_code_title"><?php echo $label; ?></span>
     387                <span class="title product_code_title"><?php echo esc_html($label); ?></span>
    381388                <span class="input-text-wrap">
    382                     <input style="<?php echo $product_one_input_style; ?>" type="text" name="<?php echo PRODUCT_CODE_FIELD_NAME; ?>" class="text product_code_field" value="">
     389                    <input style="<?php echo esc_attr($product_one_input_style); ?>" type="text" name="<?php echo esc_html(PRODUCT_CODE_FIELD_NAME); ?>" class="text product_code_field" value="">
    383390                </span>
    384391            </label>
    385392            <?php if ($show_product_code_2) { ?>
    386393                <label class="product_code_2_label">
    387                     <span class="title product_code_title_2">&nbsp; <?php echo $label_second; ?>&nbsp;</span>
     394                    <span class="title product_code_title_2">&nbsp; <?php echo esc_html($label_second); ?>&nbsp;</span>
    388395                    <span class="input-text-wrap">
    389                         <input type="text" name="<?php echo PRODUCT_CODE_FIELD_NAME_SECOND; ?>" class="text product_code_field" value="">
     396                        <input type="text" name="<?php echo esc_attr(PRODUCT_CODE_FIELD_NAME_SECOND); ?>" class="text product_code_field" value="">
    390397                    </span>
    391398                </label>
     
    396403
    397404    public function pcfw_woocommerce_product_quick_edit_save($product) {
     405        $post_data = filter_input_array(INPUT_POST, FILTER_SANITIZE_SPECIAL_CHARS);
    398406
    399407        $product_id = $product->get_id();
    400408
    401409        $field_name = PRODUCT_CODE_FIELD_NAME;
    402         if (!empty($_POST[$field_name])) {
    403             $code = sanitize_text_field($_POST[$field_name]);
    404             if (!add_post_meta($product_id, $field_name, $code, true))
     410        if (!empty($post_data[$field_name])) {
     411            $code = sanitize_text_field($post_data[$field_name]);
     412            if (!add_post_meta($product_id, $field_name, $code, true)) {
    405413                update_post_meta($product_id, $field_name, $code);
     414            }
    406415        } else {
    407416            delete_post_meta($product_id, $field_name);
     
    410419        // Saving Second Field Product Meta
    411420        $field_name = PRODUCT_CODE_FIELD_NAME_SECOND;
    412         if (!empty($_POST[$field_name])) {
    413             $code = sanitize_text_field($_POST[$field_name]);
    414             if (!add_post_meta($product_id, $field_name, $code, true))
     421        if (!empty($post_data[$field_name])) {
     422            $code = sanitize_text_field($post_data[$field_name]);
     423            if (!add_post_meta($product_id, $field_name, $code, true)) {
    415424                update_post_meta($product_id, $field_name, $code);
     425            }
    416426        } else {
    417427            delete_post_meta($product_id, $field_name);
     
    420430
    421431    public function admin_enqueue_scripts() {
    422         if (get_current_screen()->id != 'woocommerce_page_wc-settings' || !isset($_GET['section']) || $_GET['section'] !== 'product_code_settings') {
     432        if ('woocommerce_page_wc-settings' != get_current_screen()->id || !isset($_GET['section']) || 'product_code_settings' !== $_GET['section']) {
    423433            return;
    424434        }
     
    429439    /**
    430440     * Make product code column sortable
     441     *
    431442     * @since 1.4.3
    432443     * @return array
     
    440451    /**
    441452     * Sortable product table
     453     *
    442454     * @since 1.4.3
    443455     * @return void
     
    452464        }
    453465
    454         if (isset($_GET['orderby']) && ($_GET['orderby'] == 'product_code' || $_GET['orderby'] == 'product_code_2')) {
    455             $meta_key = $_GET['orderby'] == 'product_code_2' ? '_product_code_second' : '_product_code';
     466        if (isset($_GET['orderby']) && ( 'product_code' == $_GET['orderby'] || 'product_code_2' == $_GET['orderby'] )) {
     467            $meta_key = 'product_code_2' == $_GET['orderby'] ? '_product_code_second' : '_product_code';
    456468
    457469            $meta_query = array(
  • product-code-for-woocommerce/trunk/classes/class-pcfw-services.php

    r2967261 r3004043  
    77    private $admin_settings;
    88    public function __construct() {
    9         $this->admin_settings = new PCFW_Admin_settings();
     9        $this->admin_settings = new PCFW_Admin_Settings();
    1010        $this->actions();
    1111    }
     
    3030        add_action('woocommerce_admin_field_file', [$this, 'add_admin_field_file']);
    3131        add_action('woocommerce_admin_field_button', [$this, 'add_admin_field_button']);
    32         add_action("admin_menu", array($this, "add_to_wc_submenu"), 90);
     32        add_action('admin_menu', array($this, 'add_to_wc_submenu'), 90);
    3333        add_filter('plugin_row_meta', [$this, 'plugin_row_filter'], 10, 3);
    3434        add_action('wp_ajax_product_code', [$this, 'ajax_get_product_code']);
     
    4343
    4444    public function PCFW_add_body_class($classes) {
    45         if (get_option('product_code_hide_empty_field') == "yes")
     45        if ('yes' == get_option('product_code_hide_empty_field')) {
    4646            $classes[] = 'hide_pcode';
     47        }
     48
    4749        return $classes;
    4850    }
     
    6365    public function enqueue() {
    6466        global $post;
    65         if ((!empty($post) && $post->post_type == 'product') || is_wc_endpoint_url('order-pay') || is_wc_endpoint_url('order-received') || is_wc_endpoint_url('view-order')) :
     67        if (( !empty($post) && 'product' == $post->post_type ) || is_wc_endpoint_url('order-pay') || is_wc_endpoint_url('order-received') || is_wc_endpoint_url('view-order')) :
    6668
    6769            //wp_enqueue_script( 'product-code-frontend', PRODUCT_CODE_URL . '/assets/js/stl_custom.js', [ 'wc-add-to-cart-variation', 'jquery' ]);
     
    129131    public function retrieve_product_code_in_cart($cart_item_data, $cart_item) {
    130132        $simple_field_name = PRODUCT_CODE_FIELD_NAME;
    131         $txt = get_option("product_code_text", '');
     133        $txt = get_option('product_code_text', '');
    132134        $cart_data = [];
    133         if (get_option('product_code') == 'yes') :
     135        if ('yes' == get_option('product_code')) :
    134136            if (isset($cart_item[$simple_field_name])) {
    135137                $cart_data[] = array(
     
    141143
    142144        // Second product
    143         if (get_option('product_code_second') == 'yes' && get_option('product_code_second_show') == 'yes') :
     145        if ('yes' == get_option('product_code_second') && 'yes' == get_option('product_code_second_show')) :
    144146            $simple_field_name = PRODUCT_CODE_FIELD_NAME_SECOND;
    145             $txt = get_option("product_code_text_second", '');
     147            $txt = get_option('product_code_text_second', '');
    146148
    147149            // $cart_data = [];
     
    159161    public function process_order_item($item, $cart_item_key, $values, $order) {
    160162        $simple_field_name   = PRODUCT_CODE_FIELD_NAME;
    161         $txt             = get_option("product_code_text", '');
     163        $txt             = get_option('product_code_text', '');
    162164        if (isset($values[$simple_field_name])) {
    163             $item->add_meta_data(($txt ? $txt : __('Product Code', 'product-code-for-woocommerce')), $values[$simple_field_name], false);
     165            $item->add_meta_data(( $txt ? $txt : __('Product Code', 'product-code-for-woocommerce') ), $values[$simple_field_name], false);
    164166        }
    165167        $simple_field_name   = PRODUCT_CODE_FIELD_NAME_SECOND;
    166         $txt             = get_option("product_code_text_second", '');
     168        $txt             = get_option('product_code_text_second', '');
    167169        if (isset($values[$simple_field_name])) {
    168             $item->add_meta_data(($txt ? $txt : __('Product Code', 'product-code-for-woocommerce')), $values[$simple_field_name], false);
     170            $item->add_meta_data(( $txt ? $txt : __('Product Code', 'product-code-for-woocommerce') ), $values[$simple_field_name], false);
    169171        }
    170172    }
     
    173175        $field_name  = PRODUCT_CODE_FIELD_NAME;
    174176
    175         $txt         = get_option("product_code_text", '');
     177        $txt         = get_option('product_code_text', '');
    176178
    177179        foreach ($formatted_meta as $idx => $meta) {
     
    196198        // Second Product Item Meta
    197199        $field_name  = PRODUCT_CODE_FIELD_NAME_SECOND;
    198         $txt         = get_option("product_code_text_second", '');
     200        $txt         = get_option('product_code_text_second', '');
    199201        foreach ($formatted_meta as $idx => $meta) {
    200202            if ($meta->key === $field_name) {
     
    218220
    219221    public function get_order_item_meta_display_key($display_key, $meta, $item) {
    220         if ($meta->key === PRODUCT_CODE_FIELD_NAME) {
    221             $txt = get_option("product_code_text", '');
     222        if (PRODUCT_CODE_FIELD_NAME === $meta->key) {
     223            $txt = get_option('product_code_text', '');
    222224            return $txt ? $txt : __('Product Code', 'product-code-for-woocommerce');
    223225        }
    224226
    225         if ($meta->key === PRODUCT_CODE_FIELD_NAME_SECOND) {
    226             $txt = get_option("product_code_text_second", '');
     227        if (PRODUCT_CODE_FIELD_NAME_SECOND === $meta->key) {
     228            $txt = get_option('product_code_text_second', '');
    227229            return $txt ? $txt : __('Product Code', 'product-code-for-woocommerce');
    228230        }
     
    230232    }
    231233    public function display_product_code() {
    232         if (get_option('product_code') == 'yes') {
     234        if ('yes' == get_option('product_code')) {
    233235            $post    = get_post();
    234236            $value   = get_post_meta($post->ID, PRODUCT_CODE_FIELD_NAME, true);
    235             $text    = get_option("product_code_text", "");
     237            $text    = get_option('product_code_text', '');
    236238            $value_second    = get_post_meta($post->ID, PRODUCT_CODE_FIELD_NAME_SECOND, true);
    237239
    238             $text_second     = get_option("product_code_text_second", "");
     240            $text_second     = get_option('product_code_text_second', '');
    239241            include_once(PRODUCT_CODE_TEMPLATE_PATH . '/product-meta-row.php');
    240             return;
    241242        }
    242243    }
     
    248249
    249250    public function add_to_wc_submenu() {
    250         add_submenu_page("woocommerce", __("Product Code", "product-code-for-woocommerce"), __("Product Code", "product-code-for-woocommerce"), "manage_options", "wc_product_code", function () {
    251             printf("<script>window.location='%s'</script>", admin_url("admin.php?page=wc-settings&tab=products&section=product_code_settings"));
     251        add_submenu_page('woocommerce', __('Product Code', 'product-code-for-woocommerce'), __('Product Code', 'product-code-for-woocommerce'), 'manage_options', 'wc_product_code', function () {
     252            printf("<script>window.location='%s'</script>", esc_url_raw(admin_url('admin.php?page=wc-settings&tab=products&section=product_code_settings')));
    252253        });
    253 
    254 
    255 
    256254    }
    257255
    258256    public function add_product_code_settings($settings, $current_section) {
    259         if ($current_section == 'product_code_settings') {
     257        if ('product_code_settings' == $current_section) {
    260258            $settings_slider     = array();
    261259
     
    289287                'id'         => 'product_code_text',
    290288                'type'       => 'text',
    291                 'default'    => "Product Code",
     289                'default'    => 'Product Code',
    292290                'desc'       => __('Field title can be edited to read anything, no longer than 12 characters including spaces.', 'product-code-for-woocommerce'),
    293291            );
     
    298296                'id'         => 'product_code_quik_edit_text',
    299297                'type'       => 'text',
    300                 'default'    => "Code",
     298                'default'    => 'Code',
    301299                'desc'       => __('Admin products column title can be edited to read anything, no longer than 12 characters including spaces.', 'product-code-for-woocommerce'),
    302300            );
     
    331329                'id'         => 'product_code_text_second',
    332330                'type'       => 'text',
    333                 'default'    => "Product Code 2",
     331                'default'    => 'Product Code 2',
    334332                'desc'       => __('Field title can be edited to read anything, no longer than 14 characters including spaces.', 'product-code-for-woocommerce'),
    335333            );
     
    340338                'id'         => 'product_code_quik_edit_text_second',
    341339                'type'       => 'text',
    342                 'default'    => "Code 2",
     340                'default'    => 'Code 2',
    343341                'desc'       => __('Admin second products column title can be edited to read anything, no longer than 14 characters including spaces.', 'product-code-for-woocommerce'),
    344342            );
     
    386384
    387385    public function add_admin_field_file($value) {
    388 ?>
     386        ?>
    389387
    390388        <tr valign="top">
     
    392390                <label for="<?php echo esc_attr($value['id']); ?>"><?php echo esc_html($value['title']); ?></label>
    393391            </th>
    394             <td class="forminp forminp-<?php echo sanitize_title($value['type']) ?>">
     392            <td class="forminp forminp-<?php echo esc_attr($value['type']); ?>">
    395393                <input name="<?php echo esc_attr($value['name']); ?>" id="<?php echo esc_attr($value['id']); ?>" type="file" style="<?php echo esc_attr($value['css']); ?>" value="<?php echo esc_attr($value['name']); ?>" class="<?php echo esc_attr($value['class']); ?>" />
    396394            </td>
     
    400398    }
    401399    public function add_admin_field_button($value) {
    402     ?>
     400        ?>
    403401
    404402        <tr valign="top">
     
    406404                <label for="<?php echo esc_attr($value['id']); ?>"><?php echo esc_html($value['title']); ?></label>
    407405            </th>
    408             <td class="forminp forminp-<?php echo sanitize_title($value['type']) ?>">
     406            <td class="forminp forminp-<?php echo esc_attr($value['type']); ?>">
    409407                <a target="_blank" href="<?php echo esc_attr($value['href']); ?>" name="<?php echo esc_attr($value['name']); ?>" id="<?php echo esc_attr($value['id']); ?>" style="<?php echo esc_attr($value['css']); ?>" value="<?php echo esc_attr($value['name']); ?>" class="<?php echo esc_attr($value['class']); ?>"><?php echo esc_attr($value['name']); ?></a>
    410408            </td>
     
    415413
    416414    public function ajax_get_product_code() {
     415        $post_data = filter_input_array(INPUT_POST, FILTER_SANITIZE_SPECIAL_CHARS);
    417416        $simple_field_name   = PRODUCT_CODE_FIELD_NAME;
    418         if ($_POST['code_num'] == 'second')
     417        if ('second' == $post_data['code_num']) {
    419418            $simple_field_name   = PRODUCT_CODE_FIELD_NAME_SECOND;
    420 
    421         $value = get_post_meta((int) $_POST['product_code_id'], $simple_field_name, true);
     419        }
     420
     421        $value = get_post_meta((int) $post_data['product_code_id'], $simple_field_name, true);
    422422
    423423        echo json_encode([
     
    432432    public function show_woocommerce_missing_notice() {
    433433        echo '<div class="notice notice-error is-dismissible">
    434             <p>' . __('Product Code for WooCommerce Add-on requires Woocommerce plugin to be installed and activated.', 'product-code-for-woocommerce') . '</p>
    435             </div>';
     434            <p>' . esc_html__('Product Code for WooCommerce Add-on requires Woocommerce plugin to be installed and activated.', 'product-code-for-woocommerce') . '</p>
     435        </div>';
    436436    }
    437437
    438438    /**
    439439     * Add the product code to structured data.
     440     *
    440441     * @param $data
    441      *
    442442     * @return mixed
    443443     */
     
    445445
    446446        // Applies only when enable
    447         if (get_option('pcfw_structure_data') == 'yes') {
     447        if ('yes' == get_option('pcfw_structure_data')) {
    448448            $property        = apply_filters('pcfw_structured_data_property', get_option('pcfw_structured_data_field', 'gtin'), $product);
    449449            $product_code = get_post_meta($product->get_id(), '_product_code');
     
    451451            //$product_code_second = get_post_meta( $product->get_id(), '_product_code_second' );
    452452
    453             $data[$property]     = !empty($product_code) ? $product_code : "N/A";
     453            $data[$property]     = !empty($product_code) ? $product_code : 'N/A';
    454454
    455455            //$data[ $property ][]   = ! empty( $product_code_second )? $product_code_second : "N/A";
     
    458458        return $data;
    459459    }
    460 
    461 
    462     /**
    463      * @param $atts array
    464      * @return string
    465      */
    466460
    467461    public function product_code_shortcode($atts) {
     
    470464        $atts = shortcode_atts(array(
    471465            'id'            => '',
    472             'pc_label'      => get_option('product_code_text', __("Product Code:", 'product-code-for-woocommerce')),
    473             'pcs_label' => get_option('product_code_text_second', __("Product Code Second:", 'product-code-for-woocommerce')),
     466            'pc_label'      => get_option('product_code_text', __('Product Code:', 'product-code-for-woocommerce')),
     467            'pcs_label' => get_option('product_code_text_second', __('Product Code Second:', 'product-code-for-woocommerce')),
    474468            'wrapper'       => is_shop() ? 'div' : 'span',
    475469            'wrapper_code'  => 'span',
     
    498492        $is_product_code = $product->get_meta('_product_code');
    499493        $is_product_code_second = $product->get_meta('_product_code_second');
    500         $product_code = (!empty($is_product_code)) ? $is_product_code : "N/A";
    501         $product_code_second = (!empty($is_product_code_second)) ? $is_product_code_second : "N/A";
     494        $product_code = !empty($is_product_code) ? $is_product_code : 'N/A';
     495        $product_code_second = !empty($is_product_code_second) ? $is_product_code_second : 'N/A';
    502496
    503497        ob_start();
    504498
    505         if ($product_code || (get_option('product_code_hide_empty_field') != 'yes' && !$product_code) || (is_single() && $product->is_type('variable'))) :
    506         //echo sprintf('<%1$s class="%3$s">%2$s: <%4$s class="%5$s" data-product-id="%7$s">%6$s</%4$s></%1$s>', $atts['wrapper'], $atts['pc_label'], esc_attr($atts['class_wrapper']), $atts['wrapper_code'], esc_attr($atts['class']), $product_code, $product->get_id());
     499        if ($product_code || ( 'yes' != get_option('product_code_hide_empty_field') && !$product_code ) || ( is_single() && $product->is_type('variable') )) :
     500            echo wp_kses_post(sprintf('<%1$s class="%3$s">%2$s: <%4$s class="%5$s" data-product-id="%7$s">%6$s</%4$s></%1$s>', esc_html($atts['wrapper']), esc_html($atts['pc_label']), esc_attr($atts['class_wrapper']), esc_html($atts['wrapper_code']), esc_attr($atts['class']), esc_html($product_code), $product->get_id()));
    507501        endif;
    508502
    509         var_dump($product_code_second);
    510 
    511         if (get_option('product_code_second') == 'yes') {
    512             if ($product_code_second || (get_option('product_code_hide_empty_field') != 'yes' && !$product_code_second) || (is_single() && $product->is_type('variable'))) :
    513                 echo sprintf('<%1$s class="%3$s">%2$s: <%4$s class="%5$s" data-product-id="%7$s">%6$s</%4$s></%1$s>', $atts['wrapper'], $atts['pcs_label'], esc_attr($atts['class_wrapper']), $atts['wrapper_code'], esc_attr($atts['class']), $product_code_second, $product->get_id());
     503        if ('yes' == get_option('product_code_second')) {
     504            if ($product_code_second || ( 'yes' != get_option('product_code_hide_empty_field') && !$product_code_second ) || ( is_single() && $product->is_type('variable') )) :
     505                echo wp_kses_post(sprintf('<br><%1$s class="%3$s">%2$s: <%4$s class="%5$s" data-product-id="%7$s">%6$s</%4$s></%1$s>', esc_html($atts['wrapper']), esc_html($atts['pcs_label']), esc_attr($atts['class_wrapper']), esc_html($atts['wrapper_code']), esc_attr($atts['class']), esc_html($product_code_second), $product->get_id()));
    514506            endif;
    515507        }
  • product-code-for-woocommerce/trunk/modules/export/pcfw-export-support.php

    r2933587 r3004043  
    11<?php
    22
    3 /**
    4 
    5  *
    6 
    7  */
    83
    94if (!defined('ABSPATH')) {
     
    127}
    138
    14 class PCFW_wc_export_filter {
     9class PCFW_Wc_Export_Filter {
    1510
    1611
     
    8277}
    8378
    84 return new PCFW_wc_export_filter();
     79return new PCFW_Wc_Export_Filter();
  • product-code-for-woocommerce/trunk/modules/search/pcfw-filter-search.php

    r2588140 r3004043  
    11<?php
     2
    23/**
    34 * Remove method for an hook when, it's a class method used and class don't have global for instanciation !
    45 */
    5 function pcfw_remove_filters_with_method_name( $hook_name = '', $method_name = '', $priority = 0 ) {
     6function pcfw_remove_filters_with_method_name($hook_name = '', $method_name = '', $priority = 0) {
    67    global $wp_filter;
    7    
     8
    89    // Take only filters on right hook name and priority
    9     if ( !isset($wp_filter[$hook_name][$priority]) || !is_array($wp_filter[$hook_name][$priority]) )
     10    if (!isset($wp_filter[$hook_name][$priority]) || !is_array($wp_filter[$hook_name][$priority])) {
    1011        return false;
    11    
     12    }
     13
    1214    // Loop on filters registered
    13     foreach( (array) $wp_filter[$hook_name][$priority] as $unique_id => $filter_array ) {
    14         if ( isset($filter_array['function']) && is_array($filter_array['function']) ) {
    15             if ( is_object($filter_array['function'][0]) && get_class($filter_array['function'][0]) && $filter_array['function'][1] == $method_name ) {
     15    foreach ( (array) $wp_filter[$hook_name][$priority] as $unique_id => $filter_array) {
     16        if (isset($filter_array['function']) && is_array($filter_array['function'])) {
     17            if (is_object($filter_array['function'][0]) && get_class($filter_array['function'][0]) && $filter_array['function'][1] == $method_name) {
    1618                unset($wp_filter[$hook_name][$priority][$unique_id]);
    1719            }
    18         }       
    19     }   
     20        }
     21    }
    2022    return false;
    2123}
     
    2426 * Allow to remove method for an hook when, it's a class method used and class don't have variable, but you know the class name :)
    2527 */
    26 function pcfw_remove_filters_for_anonymous_class( $hook_name = '', $class_name ='', $method_name = '', $priority = 0 ) {
     28function pcfw_remove_filters_for_anonymous_class($hook_name = '', $class_name = '', $method_name = '', $priority = 0) {
    2729    global $wp_filter;
    2830    // Take only filters on right hook name and priority
    29     if ( !isset($wp_filter[$hook_name][$priority]) || !is_array($wp_filter[$hook_name][$priority]) )
     31    if (!isset($wp_filter[$hook_name][$priority]) || !is_array($wp_filter[$hook_name][$priority])) {
    3032        return false;
    31    
     33    }
     34
    3235    // Loop on filters registered
    33     foreach( (array) $wp_filter[$hook_name][$priority] as $unique_id => $filter_array ) {
    34         if ( isset($filter_array['function']) && is_array($filter_array['function']) ) {
    35             if ( is_object($filter_array['function'][0]) && get_class($filter_array['function'][0]) && get_class($filter_array['function'][0]) == $class_name && $filter_array['function'][1] == $method_name ) {
     36    foreach ((array) $wp_filter[$hook_name][$priority] as $unique_id => $filter_array) {
     37        if (isset($filter_array['function']) && is_array($filter_array['function'])) {
     38            if (is_object($filter_array['function'][0]) && get_class($filter_array['function'][0]) && get_class($filter_array['function'][0]) == $class_name && $filter_array['function'][1] == $method_name) {
    3639                unset($wp_filter[$hook_name][$priority][$unique_id]);
    3740            }
    38         }       
    39     }   
     41        }
     42    }
    4043    return false;
    4144}
  • product-code-for-woocommerce/trunk/modules/search/pcfw-product-code-search.php

    r2588140 r3004043  
    44 * Replacement of WC_Admin_Post_Types::product_search()
    55 */
    6 add_filter('posts_search', 'pcfw_product_code_search',9);
     6add_filter('posts_search', 'pcfw_product_code_search', 9);
    77function pcfw_product_code_search($where) {
    8     global $pagenow, $wpdb, $wp;
    9     $type = array('product', 'product_variation');
    10     if ((is_admin() && 'edit.php' != $pagenow)
    11             || !is_search() 
    12             || !isset($wp->query_vars['s'])
    13             //post_types can also be arrays..
    14             || (isset($wp->query_vars['post_type']) && 'product' != $wp->query_vars['post_type'])
    15             || (isset($wp->query_vars['post_type']) && is_array($wp->query_vars['post_type']) && !in_array('product', $wp->query_vars['post_type']) )
    16             ) {
    17         return $where;
    18     }
    19     $search_ids = array();
    20     $terms = explode(',', $wp->query_vars['s']);
     8    global $pagenow, $wpdb, $wp;
     9    $type = array('product', 'product_variation');
     10    if (( is_admin() && 'edit.php' != $pagenow )
     11        || !is_search()
     12        || !isset($wp->query_vars['s'])
     13        //post_types can also be arrays..
     14        || ( isset($wp->query_vars['post_type']) && 'product' != $wp->query_vars['post_type'] )
     15        || ( isset($wp->query_vars['post_type']) && is_array($wp->query_vars['post_type']) && !in_array('product', $wp->query_vars['post_type']) )
     16    ) {
     17        return $where;
     18    }
     19    $search_ids = array();
     20    $terms = explode(',', $wp->query_vars['s']);
    2121
    22     foreach ($terms as $term) {
    23         //Include search by id if admin area.
    24         if (is_admin() && is_numeric($term)) {
    25             $search_ids[] = $term;
    26         }
    27         // search variations with a matching product code and return the parent.
     22    foreach ($terms as $term) {
     23        //Include search by id if admin area.
     24        if (is_admin() && is_numeric($term)) {
     25            $search_ids[] = $term;
     26        }
     27        // search variations with a matching product code and return the parent.
     28        $term_like = '%' . $wpdb->esc_like($term) . '%';
     29        $product_code_to_parent_id = $wpdb->get_col($wpdb->prepare("SELECT p.post_parent as post_id FROM {$wpdb->posts} as p join {$wpdb->postmeta} pm on p.ID = pm.post_id and pm.meta_key IN('_product_code', '_product_code_second' ) and pm.meta_value LIKE %s where p.post_parent <> 0 group by p.post_parent", $term_like));
    2830
    29         $product_code_to_parent_id = $wpdb->get_col($wpdb->prepare("SELECT p.post_parent as post_id FROM {$wpdb->posts} as p join {$wpdb->postmeta} pm on p.ID = pm.post_id and pm.meta_key IN('_product_code', '_product_code_second' ) and pm.meta_value LIKE '%%%s%%' where p.post_parent <> 0 group by p.post_parent", wc_clean($term)));
     31        //Search a regular product that matches the product code.
     32        $product_code_to_id = $wpdb->get_col($wpdb->prepare("SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key IN ('_product_code', '_product_code_second' ) AND meta_value LIKE %s;", $term_like));
    3033
    31         //Search a regular product that matches the product code.
    32         $product_code_to_id = $wpdb->get_col($wpdb->prepare("SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key IN ('_product_code', '_product_code_second' ) AND meta_value LIKE '%%%s%%';", wc_clean($term)));
     34        $search_ids = array_merge($search_ids, $product_code_to_id, $product_code_to_parent_id);
     35    }
    3336
    34         $search_ids = array_merge($search_ids, $product_code_to_id, $product_code_to_parent_id);
    35     }
     37    $search_ids = array_filter(array_map('absint', $search_ids));
    3638
    37     $search_ids = array_filter(array_map('absint', $search_ids));
     39    if (count($search_ids) > 0) {
     40        $where = str_replace(')))', ") OR ({$wpdb->posts}.ID IN (" . implode(',', $search_ids) . '))))', $where);
     41    }
    3842
    39     if (sizeof($search_ids) > 0) {
    40         $where = str_replace(')))', ") OR ({$wpdb->posts}.ID IN (" . implode(',', $search_ids) . "))))", $where);
    41     }
    42    
    43     pcfw_remove_filters_for_anonymous_class('posts_search', 'WC_Admin_Post_Types', 'product_search', 10);
    44     return $where;
     43    pcfw_remove_filters_for_anonymous_class('posts_search', 'WC_Admin_Post_Types', 'product_search', 10);
     44    return $where;
    4545}
    4646
     
    4848 * Search products by product code via administartor product list page
    4949 */
    50 add_filter( 'request', 'pcfw_product_code_admin_search', 20 );
    51 function pcfw_product_code_admin_search( $query_vars ) {
     50add_filter('request', 'pcfw_product_code_admin_search', 20);
     51function pcfw_product_code_admin_search($query_vars) {
    5252    global $typenow;
    5353    global $wpdb;
    5454    global $pagenow;
    5555
    56     if ( is_admin() && 'product' === $typenow && isset( $_GET['s'] ) && 'edit.php' === $pagenow ) {
    57         $search_term            = esc_sql( sanitize_text_field( $_GET['s'] ) );
    58         $post_types             = array( 'product', 'product_variation' );
     56    if (is_admin() && 'product' === $typenow && isset($_GET['s']) && 'edit.php' === $pagenow) {
     57        $search_term            = esc_sql(sanitize_text_field($_GET['s']));
    5958        $search_results         = $wpdb->get_results(
    6059            $wpdb->prepare(
    61                 "SELECT DISTINCT posts.ID as product_id, posts.post_parent as parent_id FROM {$wpdb->posts} posts LEFT JOIN {$wpdb->postmeta} AS postmeta ON posts.ID = postmeta.post_id WHERE postmeta.meta_key IN('_product_code_second', '_product_code' )  AND postmeta.meta_value LIKE %s AND posts.post_type IN ('" . implode( "','", $post_types ) . "') ORDER BY posts.post_parent ASC, posts.post_title ASC",
    62                 '%' . $wpdb->esc_like( $search_term ) . '%'
     60                "SELECT DISTINCT posts.ID as product_id, posts.post_parent as parent_id FROM {$wpdb->posts} posts LEFT JOIN {$wpdb->postmeta} AS postmeta ON posts.ID = postmeta.post_id WHERE postmeta.meta_key IN('_product_code_second', '_product_code' )  AND postmeta.meta_value LIKE %s AND posts.post_type IN ('product', 'product_variation') ORDER BY posts.post_parent ASC, posts.post_title ASC",
     61                '%' . $wpdb->esc_like($search_term) . '%'
    6362            )
    6463        );
    65         $product_ids            = wp_parse_id_list( array_merge( wp_list_pluck( $search_results, 'product_id' ), wp_list_pluck( $search_results, 'parent_id' ) ) );
    66       if( isset( $query_vars['post__in'] ) ) {
    67          $query_vars['post__in'] = array_merge( $product_ids, $query_vars['post__in'] );
    68       }
     64        $product_ids            = wp_parse_id_list(array_merge(wp_list_pluck($search_results, 'product_id'), wp_list_pluck($search_results, 'parent_id')));
     65        if (isset($query_vars['post__in'])) {
     66            $query_vars['post__in'] = array_merge($product_ids, $query_vars['post__in']);
     67        }
    6968    }
    7069
  • product-code-for-woocommerce/trunk/modules/search/pcfw-relevanssi-product-code-search.php

    r2588140 r3004043  
    11<?php
    22// Indexing variation product code
    3 add_filter( 'relevanssi_content_to_index', 'rlv_index_variation_product_code', 10, 2 );
     3add_filter('relevanssi_content_to_index', 'rlv_index_variation_product_code', 10, 2);
    44
    5 function rlv_index_variation_product_code( $content, $post ) {
    6    if ( 'product' === $post->post_type ) {
    7       $args = array(
    8          'post_parent' => $post->ID,
    9          'post_type' => 'product_variation',
    10          'posts_per_page' => -1
    11       );
    12       $variations = get_posts( $args );
    13       if ( !empty( $variations ) ) {
    14          foreach ( $variations as $variation ) {
    15             $sku = get_post_meta( $variation->ID, '_product_code', true );
    16             $content .= " $sku";
    17          }
    18       }
    19    }
    20    return $content;
     5function rlv_index_variation_product_code($content, $post) {
     6    if ('product' === $post->post_type) {
     7        $args = array(
     8            'post_parent' => $post->ID,
     9            'post_type' => 'product_variation',
     10            'posts_per_page' => -1
     11        );
     12        $variations = get_posts($args);
     13        if (!empty($variations)) {
     14            foreach ($variations as $variation) {
     15                $sku = get_post_meta($variation->ID, '_product_code', true);
     16                $content .= " $sku";
     17            }
     18        }
     19    }
     20    return $content;
    2121}
  • product-code-for-woocommerce/trunk/modules/search/pcfw-searchwp-product-code-search.php

    r2588140 r3004043  
    33
    44
    5 add_filter( 'searchwp_extra_metadata', 'my_searchwp_index_woocommerce_variation_product_code', 10, 2 );
     5add_filter('searchwp_extra_metadata', 'my_searchwp_index_woocommerce_variation_product_code', 10, 2);
    66
    77
     
    99// index WooCommerce product_variation product code with the parent post
    1010
    11 function my_searchwp_index_woocommerce_variation_product_code( $extra_meta, $post_being_indexed ) {
     11function my_searchwp_index_woocommerce_variation_product_code($extra_meta, $post_being_indexed) {
    1212
    1313
     
    1515    // we only care about WooCommerce Products
    1616
    17     if ( 'product' !== get_post_type( $post_being_indexed ) ) {
     17    if ('product' !== get_post_type($post_being_indexed)) {
    1818
    1919        return $extra_meta;
    20 
    2120    }
    2221
     
    3736    );
    3837
    39     $product_variations = get_posts( $args );
     38    $product_variations = get_posts($args);
    4039
    4140
    4241
    43     if ( ! empty( $product_variations ) ) {
     42    if (!empty($product_variations)) {
    4443
    4544
     
    4948        $extra_meta['_product_code_second'] = array();
    5049
    51        
     50
    5251
    5352
     
    5554        // loop through all product variations, grab and store the SKU
    5655
    57         foreach ( $product_variations as $product_variation ) {
     56        foreach ($product_variations as $product_variation) {
    5857
    59             $extra_meta['_product_code'][] = get_post_meta( absint( $product_variation ), '_product_code', true );
     58            $extra_meta['_product_code'][] = get_post_meta(absint($product_variation), '_product_code', true);
    6059
    61             $extra_meta['_product_code_second'][] = get_post_meta( absint( $product_variation ), '_product_code_second', true );
    62 
     60            $extra_meta['_product_code_second'][] = get_post_meta(absint($product_variation), '_product_code_second', true);
    6361        }
    64 
    6562    }
    6663
    67    
     64
    6865
    6966    return $extra_meta;
    70 
    7167}
    7268
    7369
    7470
    75 add_filter( 'searchwp_custom_field_keys', 'my_searchwp_custom_field_keys_product_code_variant', 10, 1 );
     71add_filter('searchwp_custom_field_keys', 'my_searchwp_custom_field_keys_product_code_variant', 10, 1);
    7672
    7773
    7874
    79 function my_searchwp_custom_field_keys_product_code_variant( $keys ) {
     75function my_searchwp_custom_field_keys_product_code_variant($keys) {
    8076
    81   $keys[] = '_product_code'; 
     77    $keys[] = '_product_code';
    8278
    83   $keys[] = '_product_code_second';
     79    $keys[] = '_product_code_second';
    8480
    85   return $keys;
    86 
     81    return $keys;
    8782}
  • product-code-for-woocommerce/trunk/product-code-for-woocommerce.php

    r3000925 r3004043  
    22
    33/**
    4  * @package              PCFW
    5  * @wordpress-plugin
    6  *
    74 * Plugin Name:          Product Code for WooCommerce
    85 * Plugin URI:           http://wordpress.org/plugins/product-code-for-woocommerce
    96 * Description:          Plugin provides a unique internal product identifier in addition to the GTIN, EAN, SKU and UPC throughout the order process. A secondary product code field can be activated from setup.
    10  * Version:              1.4.4
     7 * Version:              1.4.5
    118 * Author:               Artios Media
    129 * Author URI:           http://www.artiosmedia.com
     
    1714 * Text Domain:          product-code-for-woocommerce
    1815 * Domain Path:          /languages
    19  * Tested up to:         6.4.1
     16 * Tested up to:         6.3.2
    2017 * WC requires at least: 4.6.0
    21  * WC tested up to:      8.3.1
    22  * PHP tested up to:     8.2.12
     18 * WC tested up to:      8.2.0
     19 * PHP tested up to:     8.2.11
    2320 */
    2421
    2522namespace Artiosmedia\WC_Product_Code;
    2623
    27 define( 'PRODUCT_CODE_URL', plugins_url( '', __FILE__ ) );
    28 define( 'PRODUCT_CODE_PATH', plugin_dir_path( __FILE__ ) );
    29 define( 'PRODUCT_CODE_FIELD_NAME', '_product_code' );
    30 define( 'PRODUCT_CODE_FIELD_NAME_SECOND', '_product_code_second' );
     24define('PRODUCT_CODE_URL', plugins_url('', __FILE__));
     25define('PRODUCT_CODE_PATH', plugin_dir_path(__FILE__));
     26define('PRODUCT_CODE_FIELD_NAME', '_product_code');
     27define('PRODUCT_CODE_FIELD_NAME_SECOND', '_product_code_second');
    3128
    32 define( 'PRODUCT_CODE_TEMPLATE_PATH', __DIR__ . '/templates' );
    33 define( 'PRODUCT_CODE_PAYPAL_ID', 'E7LS2JGFPLTH2' );
     29define('PRODUCT_CODE_TEMPLATE_PATH', __DIR__ . '/templates');
     30define('PRODUCT_CODE_PAYPAL_ID', 'E7LS2JGFPLTH2');
    3431
    35 define( 'PRODUCT_CODE_VERSION', '1.4.4' );
    36 define( 'PRODUCT_CODE_DB_VERSION', '1.4.4' );
     32define('PRODUCT_CODE_VERSION', '1.4.5');
     33define('PRODUCT_CODE_DB_VERSION', '1.4.5');
    3734
    38 load_plugin_textdomain( 'product-code-for-woocommerce', false, basename( dirname( __FILE__ ) ) . '/languages' );
     35load_plugin_textdomain('product-code-for-woocommerce', false, basename(dirname(__FILE__)) . '/languages');
    3936
    40 require_once( __DIR__ . '/vendor/autoload.php' );
     37require_once(__DIR__ . '/vendor/autoload.php');
    4138
    42 if ( ! class_exists( 'PCFW_Services' ) ) {
    43     include( PRODUCT_CODE_PATH . 'classes/class-pcfw-services.php' );
     39if (!class_exists('PCFW_Services')) {
     40    include(PRODUCT_CODE_PATH . 'classes/class-pcfw-services.php');
    4441}
    4542
    46 if ( ! class_exists( 'PCFW_Admin_settings' ) ) {
    47     include( PRODUCT_CODE_PATH . 'classes/class-pcfw-admin-settings.php' );
     43if (!class_exists('PCFW_Admin_Settings')) {
     44    include(PRODUCT_CODE_PATH . 'classes/class-pcfw-admin-settings.php');
    4845}
    49 if ( ! class_exists( 'PCFW_wc_export_filter' ) ) {
    50     include( PRODUCT_CODE_PATH . 'modules/export/pcfw-export-support.php' );
     46if (!class_exists('PCFW_Wc_Export_Filter')) {
     47    include(PRODUCT_CODE_PATH . 'modules/export/pcfw-export-support.php');
    5148}
    5249
    5350new PCFW_Services();
    5451
    55 add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), function( $links ) {
    56     $settings = sprintf( '<a href="%s">%s</a>', admin_url( 'admin.php?page=wc-settings&tab=products&section=product_code_settings' ), __( 'Settings', 'product-code-for-woocommerce' ) );
     52add_filter('plugin_action_links_' . plugin_basename(__FILE__), function ($links) {
     53    $settings = sprintf('<a href="%s">%s</a>', admin_url('admin.php?page=wc-settings&tab=products&section=product_code_settings'), __('Settings', 'product-code-for-woocommerce'));
    5754
    58     array_unshift( $links, $settings );
    59     return $links;
    60 } );
     55    array_unshift($links, $settings);
     56    return $links;
     57});
    6158
    62 register_activation_hook( __FILE__, function() {
    63     // Must Be deleted on other update ,
    64     delete_option( 'product_code_update' );
     59register_activation_hook(__FILE__, function () {
     60    // Must Be deleted on other update ,
     61    delete_option('product_code_update');
    6562
    66     $show_product = get_option( 'product_code' );
    67     if ( ! $show_product )
    68     add_option( 'product_code', 'yes' );
    69     add_option( 'product_code_text', 'Product Code' );
     63    $show_product = get_option('product_code');
     64    if (!$show_product) {
     65        add_option('product_code', 'yes');
     66    }
    7067
    71     update_option( "product_code_notice_dismiss", date( 'Y-m-d', strtotime( '+30 days' ) ) );
    72 } );
     68    add_option('product_code_text', 'Product Code');
    7369
    74 register_deactivation_hook( __FILE__, function() {
    75     delete_option( 'product_code' );
    76 } );
     70    update_option('product_code_notice_dismiss', gmdate('Y-m-d', strtotime('+30 days')));
     71});
     72
     73register_deactivation_hook(__FILE__, function () {
     74    delete_option('product_code');
     75});
    7776
    7877add_action('before_woocommerce_init', function () {
    79     // Check if the FeaturesUtil class exists in the \Automattic\WooCommerce\Utilities namespace.
    80     if (class_exists(\Automattic\WooCommerce\Utilities\FeaturesUtil::class)) {
    81         // Declare compatibility with custom order tables using the FeaturesUtil class.
    82         \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility('custom_order_tables', __FILE__, true);
    83     }
    84  });
    85  
     78    // Check if the FeaturesUtil class exists in the \Automattic\WooCommerce\Utilities namespace.
     79    if (class_exists(\Automattic\WooCommerce\Utilities\FeaturesUtil::class)) {
     80        // Declare compatibility with custom order tables using the FeaturesUtil class.
     81        \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility('custom_order_tables', __FILE__, true);
     82    }
     83});
     84
    8685// run on upgrade
    87 add_action( 'admin_init', function() {
     86add_action('admin_init', function () {
    8887
    8988
    90     if ( PRODUCT_CODE_VERSION === "1.0.6" && ( ! $upgrade_db ) ) {
    91     update_option( "product_code_notice_dismiss", date( 'Y-m-d', strtotime( '+30 days' ) ) );
    92     update_option( "product_code_update", true );
    93     }
     89    if (PRODUCT_CODE_VERSION === '1.0.6' && !$upgrade_db) {
     90        update_option('product_code_notice_dismiss', gmdate('Y-m-d', strtotime('+30 days')));
     91        update_option('product_code_update', true);
     92    }
    9493
    95     if ( PRODUCT_CODE_VERSION === "1.0.7" ) {
    96     $product_text = get_option( 'product_code_text' );
    97     if ( ! $product_text ) {
    98         update_option( 'product_code_text', 'Product Code' );
     94    if (PRODUCT_CODE_VERSION === '1.0.7') {
     95        $product_text = get_option('product_code_text');
     96        if (!$product_text) {
     97            update_option('product_code_text', 'Product Code');
     98        }
    9999    }
    100     }
    101     /* Change the order of code and resolved offset error */
    102     // update the version value
    103     $product_code_info = array(
    104     'version'    => PRODUCT_CODE_VERSION,
    105     'db_version'     => PRODUCT_CODE_DB_VERSION
    106     );
    107     update_site_option( 'product_code_info', $product_code_info );
    108     /* Change the order of code and resolved offset error */
     100    /* Change the order of code and resolved offset error */
     101    // update the version value
     102    $product_code_info = array(
     103        'version'    => PRODUCT_CODE_VERSION,
     104        'db_version'     => PRODUCT_CODE_DB_VERSION
     105    );
     106    update_site_option('product_code_info', $product_code_info);
     107    /* Change the order of code and resolved offset error */
    109108
    110     $plugin_options = get_site_option( 'product_code_info' );
    111     $upgrade_db  = get_option( "product_code_db_updated" );
    112    
    113 // Check if postmeta data is changed to the new name.
    114     Global $wpdb;
    115     $query  = "SELECT * from " . $wpdb->prefix . "postmeta WHERE meta_key='_product_code_variant' ";
    116     $results = $wpdb->get_results( $query );
     109    $plugin_options = get_site_option('product_code_info');
     110    $upgrade_db  = get_option('product_code_db_updated');
    117111
    118 // If plugin version is less then 1.2.0 then upgrade and if not update database after version upgrade still display the notice.
    119     if ( ( $plugin_options[ 'version' ] < "1.2.2" && ( ! $upgrade_db ) ) || ( ! empty( $results ) )  ) {
    120     add_action( "admin_notices", function() {
    121         $url = admin_url( 'admin-ajax.php' );
    122         ?>
    123         <div class="warning notice">
    124             <p><?php _e( '<strong>NOTICE! Product Code For WooCommerce</strong> must update your database to modify meta fields. Consider backing up database first.', 'product-code-for-woocommerce' ); ?> <a class="button button-primary" href="<?php echo $url; ?>?action=product_code_update_database" target="_blank"><?php _e( 'Update Now', 'product-code-for-woocommerce' ); ?></a></p>
    125         </div>
    126         <?php
    127     } );
    128     }
    129 } );
     112    // Check if postmeta data is changed to the new name.
     113    global $wpdb;
     114    $results = $wpdb->get_results("SELECT * from {$wpdb->prefix}postmeta WHERE meta_key='_product_code_variant'");
     115
     116    // If plugin version is less then 1.2.0 then upgrade and if not update database after version upgrade still display the notice.
     117    if (( $plugin_options['version'] < '1.2.2' && !$upgrade_db ) || !empty($results)) {
     118        add_action('admin_notices', function () {
     119            $url = admin_url('admin-ajax.php');
     120            $notice_text = __('<strong>NOTICE! Product Code For WooCommerce</strong> must update your database to modify meta fields. Consider backing up database first.', 'product-code-for-woocommerce');
     121            ?>
     122            <div class="warning notice">
     123                <p><?php echo wp_kses_post($notice_text); ?> <a class="button button-primary" href="<?php echo esc_url($url); ?>?action=product_code_update_database" target="_blank"><?php esc_html_e('Update Now', 'product-code-for-woocommerce'); ?></a></p>
     124            </div>
     125<?php
     126        });
     127    }
     128});
    130129
    131130// Include files for search
    132 add_filter( 'init', function() {
    133     include_once PRODUCT_CODE_PATH . 'modules/search/pcfw-filter-search.php';
    134     include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
    135     if ( ! is_admin() && is_plugin_active( 'relevanssi/relevanssi.php' ) || ! function_exists( 'wc_clean' ) ) {
    136     include_once PRODUCT_CODE_PATH . 'modules/search/pcfw-relevanssi-product-code-search.php';
    137     } else
    138     if ( ! is_admin() && is_plugin_active( 'searchwp/searchwp.php' ) && is_plugin_active( 'searchwp-woocommerce/searchwp-woocommerce.php' ) ) {
    139     include_once PRODUCT_CODE_PATH . 'modules/search/pcfw-searchwp-product-code-search.php';
    140     } else {
    141     include_once PRODUCT_CODE_PATH . 'modules/search/pcfw-product-code-search.php';
    142     }
    143 }, 11 );
     131add_filter('init', function () {
     132    include_once PRODUCT_CODE_PATH . 'modules/search/pcfw-filter-search.php';
     133    include_once(ABSPATH . 'wp-admin/includes/plugin.php');
     134    if (!is_admin() && is_plugin_active('relevanssi/relevanssi.php') || !function_exists('wc_clean')) {
     135        include_once PRODUCT_CODE_PATH . 'modules/search/pcfw-relevanssi-product-code-search.php';
     136    } else if (!is_admin() && is_plugin_active('searchwp/searchwp.php') && is_plugin_active('searchwp-woocommerce/searchwp-woocommerce.php')) {
     137        include_once PRODUCT_CODE_PATH . 'modules/search/pcfw-searchwp-product-code-search.php';
     138    } else {
     139        include_once PRODUCT_CODE_PATH . 'modules/search/pcfw-product-code-search.php';
     140    }
     141}, 11);
    144142
    145143
    146 add_action('save_post',function($post_id, $post){
    147     if ($post->post_type != 'product'){
    148         return;
    149     }
    150     $product = wc_get_product($post_id);
    151     $type = $product->get_type();
    152     global $post;
    153     if($type == "variable"){
    154          $variations = $product->get_available_variations();
    155          $variations_id = wp_list_pluck( $variations, 'variation_id' );
    156          delete_post_meta($post_id,'_product_code');
    157              foreach($variations_id as $var){
    158                  $ProductCode = get_post_meta($var,"_product_code",true);
    159                  add_post_meta($post_id, '_product_code', $ProductCode);
    160              }
    161     }
     144add_action('save_post', function ($post_id, $post) {
     145    if ('product' != $post->post_type) {
     146        return;
     147    }
     148    $product = wc_get_product($post_id);
     149    $type = $product->get_type();
     150    global $post;
     151    if ('variable' == $type) {
     152        $variations = $product->get_available_variations();
     153        $variations_id = wp_list_pluck($variations, 'variation_id');
     154        delete_post_meta($post_id, '_product_code');
     155        foreach ($variations_id as $var) {
     156            $ProductCode = get_post_meta($var, '_product_code', true);
     157            add_post_meta($post_id, '_product_code', $ProductCode);
     158        }
     159    }
    162160}, 10, 2);
    163 
    164 
  • product-code-for-woocommerce/trunk/readme.txt

    r3000925 r3004043  
    66Requires at least: 4.6
    77Tested up to: 6.4.1
    8 Version: 1.4.4
    9 Stable tag: 1.4.4
     8Version: 1.4.5
     9Stable tag: 1.4.5
    1010Requires PHP: 7.4.33
    1111License: GPLv3 or later license and included
     
    3232As of <strong>version 1.4.1</strong>, an administrator can choose to hide the default and secondary product code from the user-side product posts while the other display injections still work (checkout, cart, and receipts).
    3333
     34As of <strong>version 1.4.5</strong>, shortcodes have changed to solve a vulnerability found by PatchStack, where the new shortcodes are...".
     35
    3436== Installation ==
    3537
     
    38403. Enter the Product Code under the SKU from either Variable or Simple products.
    3941
    40 == Technical Details for Release 1.4.4 ==
     42== Technical Details for Release 1.4.5 ==
    4143
    4244Load time: 0.279 s; Memory usage: 3.61 MiB
     
    135137
    136138== Changelog ==
     139
     1401.4.5 11/30/23
     141- Fixed Cross Site Scripting (XSS) vulnerability
     142- Add whitelist check for the wrapper tag
    137143
    1381441.4.4 11/23/23
  • product-code-for-woocommerce/trunk/templates/product-meta-row.php

    r2967261 r3004043  
    1515?>
    1616
    17 <?php if ($hide_product_code == 'no' && ($value || (get_option('product_code_hide_empty_field') != 'yes' && !$value) || $product_type == "variable")) : ?>
    18     <span class="wo_productcode">
    19         <input type="hidden" value="<?php echo $post->ID ?>" id="product_id" />
    20         <span><?php echo ($text ? $text : __('Product Code', 'product-code-for-woocommerce')) ?>:</span>
    21         <span class="stl_codenum"><?php echo !$value ? __('N/A', 'product-code-for-woocommerce') : $value ?></span>
    22     </span>
     17<?php if ('no' == $hide_product_code && ( $value || ( 'yes' != get_option('product_code_hide_empty_field') && !$value ) || 'variable' == $product_type )) : ?>
     18    <span class="wo_productcode">
     19        <input type="hidden" value="<?php echo absint($post->ID); ?>" id="product_id" />
     20        <span><?php echo esc_html($text ? $text : __('Product Code', 'product-code-for-woocommerce')); ?>:</span>
     21        <span class="stl_codenum"><?php echo esc_html(!$value ? __('N/A', 'product-code-for-woocommerce') : $value); ?></span>
     22    </span>
    2323<?php endif; ?>
    2424
    2525<?php
    26 if ($hide_second_product_code == 'no' && get_option('product_code_second') == 'yes') {
    27     if ($value_second || (get_option('product_code_hide_empty_field') != 'yes' && !$value_second) || $product_type == "variable") : ?>
    28         <span class="wo_productcode_second">
    29             <input type="hidden" value="<?php echo $post->ID ?>" id="product_id_second" />
    30             <span><?php echo ($text_second ? $text_second : __('Product Code', 'product-code-for-woocommerce')) ?>:</span>
    31             <span class="stl_codenum_second"><?php echo !$value_second ? __('N/A', 'product-code-for-woocommerce') : $value_second ?></span>
    32         </span>
    33     <?php endif; ?>
     26if ('no' == $hide_second_product_code && 'yes' == get_option('product_code_second')) {
     27    if ($value_second || ( 'yes' != get_option('product_code_hide_empty_field') && !$value_second ) || 'variable' == $product_type) :
     28        ?>
     29        <span class="wo_productcode_second">
     30            <input type="hidden" value="<?php echo absint($post->ID); ?>" id="product_id_second" />
     31            <span><?php echo esc_html($text_second ? $text_second : __('Product Code', 'product-code-for-woocommerce')); ?>:</span>
     32            <span class="stl_codenum_second"><?php echo esc_html(!$value_second ? __('N/A', 'product-code-for-woocommerce') : $value_second); ?></span>
     33        </span>
     34    <?php endif; ?>
    3435<?php } ?>
  • product-code-for-woocommerce/trunk/templates/quick-edit-text-field.php

    r2588140 r3004043  
    1212<div style="clear:both;"></div>
    1313<label class="product_code">
    14     <span class="title"><?php
    15 _e('Product Code','product-code-for-woocommerce')
    16 
    17 ?></span>
     14    <span class="title"><?php esc_html_e('Product Code', 'product-code-for-woocommerce'); ?></span>
    1815    <span class="input-text-wrap">
    19         <input type="text" name="<?php
    20 echo $field_name
    21 
    22 ?>" class="text" placeholder="<?php
    23 _e('Product Code','product-code-for-woocommerce')
    24 
    25 ?>" value="<?php
    26 echo $code
    27 
    28 ?>" />
     16        <input type="text"
     17            name="<?php echo esc_attr($field_name); ?>" class="text"
     18            placeholder="<?php esc_attr_e('Product Code', 'product-code-for-woocommerce'); ?>"
     19            value="<?php echo esc_attr($code); ?>"
     20        />
    2921    </span>
    3022</label>
  • product-code-for-woocommerce/trunk/templates/variation-field.php

    r2967261 r3004043  
    1212<div class="form-row form-row-first">
    1313
    14     <?php
     14    <?php
    1515
    16     $label = $this->get_field_title_text();
    17     $label_second = $this->get_second_field_title_text();
     16    $label = $this->get_field_title_text();
     17    $label_second = $this->get_second_field_title_text();
    1818
    19     woocommerce_wp_text_input([
    20         'id' => sprintf('%s_%d', $field_name, $i),
    21         'label' => $label,
    22         'desc_tip' => true,
    23         'description' => sprintf(__('%s refers to a company’s unique internal product identifier, needed for online product fulfillment.', 'product-code-for-woocommerce'), $label),
    24         'value' => $code,
    25     ]);
     19    woocommerce_wp_text_input([
     20        'id' => sprintf('%s_%d', $field_name, $i),
     21        'label' => $label,
     22        'desc_tip' => true,
     23        'description' => sprintf(
     24            /* translators: 1 for label */
     25            __('%s refers to a company’s unique internal product identifier, needed for online product fulfillment.', 'product-code-for-woocommerce'),
     26            $label
     27        ),
     28        'value' => $code,
     29    ]);
    2630
    27     if ($displaySecond == 'yes') {
    28         woocommerce_wp_text_input([
    29             'id' => sprintf('%s_%d', $field_name_second, $i),
    30             'label' => $label_second,
    31             'desc_tip' => true,
    32             'description' => sprintf(__('%s refers to a company’s unique internal product identifier, needed for online product fulfillment.', 'product-code-for-woocommerce'), $label_second),
    33             'value' => $code_second,
    34         ]);
    35     }
     31    if ('yes' == $displaySecond) {
     32        woocommerce_wp_text_input([
     33            'id' => sprintf('%s_%d', $field_name_second, $i),
     34            'label' => $label_second,
     35            'desc_tip' => true,
     36            'description' => sprintf(
     37                /* translators: 1 for label */
     38                __('%s refers to a company’s unique internal product identifier, needed for online product fulfillment.', 'product-code-for-woocommerce'),
     39                $label_second
     40            ),
     41            'value' => $code_second,
     42        ]);
     43    }
    3644
    37     ?>
    38     <!-- <label for="product_code_<?php
    39                                     echo $variation->ID
    40 
    41                                     ?>">
    42         <strong>
    43             <?php
    44             echo $label;
    45 
    46             ?>
    47         </strong>
    48     </label>
    49     <input type="text" value="<?php
    50                                 echo $code
    51 
    52                                 ?>" name="<?php
    53                                             echo $field_name
    54 
    55                                             ?>" id="product_code_<?php
    56                                                                     echo $variation->ID
    57 
    58                                                                     ?>" /> -->
     45    ?>
    5946</div>
    6047<div style="clear:both;"></div>
  • product-code-for-woocommerce/trunk/templates/wc-text-input.php

    r2588140 r3004043  
    99 */
    1010
    11 woocommerce_wp_text_input(['id' => $c('id'),'label' => $c('label'),'desc_tip' =>
    12     $c('desc_tip'),'description' => $c('description'),'value' => $c('value'),]);
     11woocommerce_wp_text_input(['id' => $c('id'),'label' => $c('label'),'desc_tip' => $c('desc_tip'),'description' => $c('description'),'value' => $c('value'),]);
Note: See TracChangeset for help on using the changeset viewer.