/** * Automatic Set all Product Attribute as Compare Features * */ public function automatic_add_features() { $current_db_version = get_option('woocommerce_db_version', null); if (version_compare($current_db_version, '2.1.0', '<') && null !== $current_db_version) { global $woocommerce; $top_variations = $woocommerce->get_attribute_taxonomies(); } else { $top_variations = wc_get_attribute_taxonomies(); } if ($top_variations) { foreach ($top_variations as $top_variation) { $check_existed = WC_Compare_Data::get_count("field_name='" . trim(addslashes($top_variation->attribute_label)) . "'"); if ($check_existed < 1) { $child_variations = get_terms(version_compare($current_db_version, '2.1.0', '<') && null !== $current_db_version ? $woocommerce->attribute_taxonomy_name($top_variation->attribute_name) : wc_attribute_taxonomy_name($top_variation->attribute_name), array('parent' => 0, 'hide_empty' => 0, 'hierarchical' => 0)); $default_value = ''; if (count($child_variations) > 0) { $line = ''; foreach ($child_variations as $child_variation) { $default_value .= $line . addslashes($child_variation->name); $line = ' '; } } if (trim($default_value) != '') { $feature_id = WC_Compare_Data::insert_row(array('field_name' => trim(addslashes($top_variation->attribute_label)), 'field_type' => 'checkbox', 'field_unit' => '', 'default_value' => $default_value)); } else { $feature_id = WC_Compare_Data::insert_row(array('field_name' => trim(addslashes($top_variation->attribute_label)), 'field_type' => 'input-text', 'field_unit' => '', 'default_value' => '')); } } } } }
/** * Install Database, settings option and auto add widget to sidebar */ function woocp_install() { update_option('a3rev_woocp_pro_version', '2.4.1'); update_option('a3rev_woocp_lite_version', '2.2.0'); $product_compare_id = WC_Compare_Functions::create_page(esc_sql('product-comparison'), '', __('Product Comparison', 'woo_cp'), '[product_comparison_page]'); update_option('product_compare_id', $product_compare_id); // Set Settings Default from Admin Init global $wc_compare_admin_init; $wc_compare_admin_init->set_default_settings(); WC_Compare_Data::install_database(); WC_Compare_Categories_Data::install_database(); WC_Compare_Categories_Fields_Data::install_database(); // Build sass global $wc_compare_less; $wc_compare_less->plugin_build_sass(); update_option('a3rev_woocp_just_installed', true); }
public static function auto_create_compare_feature() { if (isset($_POST['add_new_attribute']) && $_POST['add_new_attribute']) { //check_admin_referer( 'woocommerce-add-new_attribute' ); $attribute_name = (string) sanitize_title($_POST['attribute_name']); $attribute_type = (string) $_POST['attribute_type']; $attribute_label = (string) $_POST['attribute_label']; if (!$attribute_label) { $attribute_label = ucwords($attribute_name); } if (!$attribute_name) { $attribute_name = sanitize_title($attribute_label); } if ($attribute_name && strlen($attribute_name) < 30 && $attribute_type && !taxonomy_exists('pa_' . $attribute_name)) { $check_existed = WC_Compare_Data::get_count("field_name='" . $attribute_label . "'"); if ($check_existed < 1) { $feature_id = WC_Compare_Data::insert_row(array('field_name' => $attribute_label, 'field_type' => 'input-text', 'field_unit' => '', 'default_value' => '')); } } } }
public static function features_search_area() { global $wpdb; ?> <div class="icon32 icon32-compare-product" id="icon32-compare-product"><br></div> <h2><?php _e('Categories & Features', 'woo_cp'); ?> <a href="admin.php?page=woo-compare-features&act=add-new" class="add-new-h2"><?php _e('Add New', 'woo_cp'); ?> </a></h2> <div style="clear:both;height:12px"></div> <form method="get" action="admin.php?page=woo-compare-features" name="compare_search_features"> <input type="hidden" name="page" value="woo-compare-features" /> <input type="hidden" name="tab" value="features" /> <?php $s_feature = ''; if (isset($_REQUEST['s_feature']) && trim($_REQUEST['s_feature']) != '') { $s_feature = trim(stripslashes($_REQUEST['s_feature'])); } ?> <table class="form-table" style="width:535px;"> <tbody> <tr valign="top"> <th class="titledesc" scope="rpw" style="padding-left:0;"><input type="text" name="s_feature" id="s_feature" value="<?php echo $s_feature; ?> " style="min-width:300px" /></th> <td class="forminp search_features_td" style="padding-right:0; text-align:right;"><input type="submit" id="search_features" name="" value="<?php _e('Search Features', 'woo_cp'); ?> " class="button"></td> </tr> </tbody> </table> <?php if (isset($_REQUEST['s_feature'])) { $p = 1; $rows = 25; if (isset($_REQUEST['pp'])) { $p = $_REQUEST['pp']; } if (isset($_REQUEST['rows'])) { $rows = $_REQUEST['rows']; } $start = ($p - 1) * $rows; $end = $start + $rows; $div = 5; $keyword = trim(stripslashes($_REQUEST['s_feature'])); $link = add_query_arg(array('pp' => '', 'rows' => $rows, 's_feature' => $keyword)); $character = 'latin1'; if ($wpdb->has_cap('collation')) { if (!empty($wpdb->charset)) { $character = "{$wpdb->charset}"; } } $where = "LOWER( CONVERT( field_name USING " . $character . ") ) LIKE '%" . strtolower(trim($_REQUEST['s_feature'])) . "%'"; $total = WC_Compare_Data::get_count($where); if ($end > $total) { $end = $total; } $items = WC_Compare_Data::get_results($where, 'field_name ASC', $start . ',' . $rows); $innerPage = WC_Compare_Functions::printPage($link, $total, $p, $div, $rows, false); ?> <h3><?php _e('Found', 'woo_cp'); ?> <?php echo $total; ?> <?php _e('feature(s)', 'woo_cp'); ?> </h3> <?php if ($total > 0) { ?> <table cellspacing="0" class="widefat post fixed" style="width:535px;"> <thead> <tr> <th class="manage-column" scope="col"><?php _e('Feature Name', 'woo_cp'); ?> </th> <th width="90" class="manage-column" scope="col" style="text-align:right"><?php _e('Type', 'woo_cp'); ?> </th> <th width="100" class="manage-column" scope="col" style="text-align:right"></th> </tr> </thead> <tbody> <?php foreach ($items as $field_data) { ?> <tr> <td><?php echo stripslashes($field_data->field_name); ?> </td> <td align="right"><?php echo WC_Compare_Fields_Class::$default_types[$field_data->field_type]['name']; ?> </td> <td align="right"><a href="admin.php?page=woo-compare-features&act=field-edit&field_id=<?php echo $field_data->id; ?> " class="c_field_edit" title="<?php _e('Edit', 'woo_cp'); ?> " ><?php _e('Edit', 'woo_cp'); ?> </a> | <a href="admin.php?page=woo-compare-features&act=field-delete&field_id=<?php echo $field_data->id; ?> " class="c_field_delete" onclick="javascript:return confirmation('<?php _e('Are you sure you want to delete', 'woo_cp'); ?> #<?php echo htmlspecialchars($field_data->field_name); ?> ');" title="<?php _e('Delete', 'woo_cp'); ?> " ><?php _e('Delete', 'woo_cp'); ?> </a></td> </tr> <?php } ?> </tbody> <tfoot> <tr> <th class="manage-column column-title" colspan="3" style="padding:2px 7px"> <div class="tablenav"> <span class="search_item_title"><?php _e('Show', 'woo_cp'); ?> :</span> <select name="rows" class="number_items"> <?php $number_items_array = array('15' => '15', '25' => '25', '50' => '50', '75' => '75', '100' => '100', '200' => '200', '1000000' => 'All'); foreach ($number_items_array as $key => $value) { if ($key == $rows) { echo "<option selected='selected' value='{$key}'>{$value}</option>"; } else { echo "<option value='{$key}'>{$value}</option>"; } } ?> </select> <input type="submit" class="button" value="<?php _e('Go', 'woo_cp'); ?> " name="" id="search_items" /> <div class="tablenav-pages"><span class="displaying-num"><?php _e('Displaying', 'woo_cp'); ?> <?php echo $start + 1; ?> - <?php echo $end; ?> <?php _e('of', 'woo_cp'); ?> <?php echo $total; ?> </span><?php echo $innerPage; ?> </div> </div> </th> </tr> </tfoot> </table> <?php } } ?> </form> <?php }
public static function check_field_key_for_update($field_id, $field_key) { $count = WC_Compare_Data::get_count("id!='{$field_id}' AND field_key='{$field_key}'"); if ($count > 0) { return false; } else { return true; } }