/** * 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_category($term_id) { $term = get_term($term_id, 'product_cat'); $check_existed = WC_Compare_Categories_Data::get_count("category_name='" . trim($term->name) . "'"); if ($check_existed < 1) { WC_Compare_Categories_Data::insert_row(array('category_name' => trim(addslashes($term->name)))); } }
public function add_meta_all_products() { // Add deactivate compare feature meta for all products when activate this plugin $have_deactivate_meta = get_posts(array('numberposts' => -1, 'post_type' => array('product', 'product_variation'), 'post_status' => array('publish', 'private'), 'meta_key' => '_woo_deactivate_compare_feature')); $have_ids = array(); if (is_array($have_deactivate_meta) && count($have_deactivate_meta) > 0) { foreach ($have_deactivate_meta as $product) { $have_ids[] = $product->ID; } } if (is_array($have_ids) && count($have_ids) > 0) { $no_deactivate_meta = get_posts(array('numberposts' => -1, 'post_type' => array('product', 'product_variation'), 'post_status' => array('publish', 'private'), 'post__not_in' => $have_ids)); } else { $no_deactivate_meta = get_posts(array('numberposts' => -1, 'post_type' => array('product', 'product_variation'), 'post_status' => array('publish', 'private'))); } if (is_array($no_deactivate_meta) && count($no_deactivate_meta) > 0) { foreach ($no_deactivate_meta as $product) { add_post_meta($product->ID, '_woo_deactivate_compare_feature', ''); } } // Add deactivate compare feature meta for all products when activate this plugin $have_compare_category_meta = get_posts(array('numberposts' => -1, 'post_type' => array('product', 'product_variation'), 'post_status' => array('publish', 'private'), 'meta_key' => '_woo_compare_category_name')); $have_ids = array(); if (is_array($have_compare_category_meta) && count($have_compare_category_meta) > 0) { foreach ($have_compare_category_meta as $product) { $have_ids[] = $product->ID; } } if (is_array($have_ids) && count($have_ids) > 0) { $no_compare_category_meta = get_posts(array('numberposts' => -1, 'post_type' => array('product', 'product_variation'), 'post_status' => array('publish', 'private'), 'post__not_in' => $have_ids)); } else { $no_compare_category_meta = get_posts(array('numberposts' => -1, 'post_type' => array('product', 'product_variation'), 'post_status' => array('publish', 'private'))); } if (is_array($no_compare_category_meta) && count($no_compare_category_meta) > 0) { foreach ($no_compare_category_meta as $product) { add_post_meta($product->ID, '_woo_compare_category_name', ''); } } // Add compare category name into product have compare category id $have_compare_category_id_meta = get_posts(array('numberposts' => -1, 'post_type' => array('product', 'product_variation'), 'post_status' => array('publish', 'private'), 'meta_key' => '_woo_compare_category')); if (is_array($have_compare_category_id_meta) && count($have_compare_category_id_meta) > 0) { foreach ($have_compare_category_id_meta as $product) { $compare_category = get_post_meta($product->ID, '_woo_compare_category', true); $category_data = WC_Compare_Categories_Data::get_row($compare_category); @update_post_meta($product->ID, '_woo_compare_category_name', stripslashes($category_data->category_name)); } } }
public static function woocp_features_orders() { $unavaliable_fields = WC_Compare_Categories_Fields_Data::get_unavaliable_field_results('field_name ASC'); if (is_array($unavaliable_fields) && count($unavaliable_fields) > 0) { $un_i = 0; ?> <h3 id="#un_assigned"><?php _e('Un-Assigned Features (Assign to a Category to activate)', 'woo_cp'); ?> </h3> <form action="admin.php?page=woo-compare-features" method="post" name="form_delete_fields" id="form_delete_fields" style="margin-bottom:30px;"> <table cellspacing="0" class="widefat post fixed" style="width:535px;"> <thead> <tr> <th width="25" class="manage-column" scope="col" style="white-space: nowrap;"><input id="toggle1" class="toggle" type="checkbox" style="margin:0;" /></th> <th width="30" class="manage-column" scope="col" style="white-space: nowrap;"><?php _e('No', 'woo_cp'); ?> </th> <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 ($unavaliable_fields as $field_data) { $un_i++; ?> <tr> <td><input class="list_fields" type="checkbox" name="un_fields[]" value="<?php echo $field_data->id; ?> " /></td> <td><?php echo $un_i; ?> </td> <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> </table> <div style="margin-top:10px;"><input type="submit" name="bt_delete" id="bt_delete" class="button button-primary" value="<?php _e('Delete', 'woo_cp'); ?> " onclick="if (confirm('<?php _e('Are you sure about deleting this?', 'woo_cp'); ?> ')) return true; else return false" /></div> </form> <?php } $compare_cats = WC_Compare_Categories_Data::get_results('', 'category_order ASC'); if (is_array($compare_cats) && count($compare_cats) > 0) { ?> <h3><?php _e('Manage Compare Categories and Features', 'woo_cp'); ?> </h3> <p><?php _e('Use drag and drop to change Category order and Feature order within Categories.', 'woo_cp'); ?> </p> <div class="updated below-h2 update_feature_order_message" style="display:none"><p></p></div> <div style="clear:both"></div> <ul style="margin:0; padding:0;" class="sorttable"> <?php foreach ($compare_cats as $cat) { $compare_fields = WC_Compare_Categories_Fields_Data::get_results("cat_id='" . $cat->id . "'", 'cf.field_order ASC'); ?> <li id="recordsArray_<?php echo $cat->id; ?> "> <input type="hidden" name="compare_orders_<?php echo $cat->id; ?> " class="compare_category_id" value="<?php echo $cat->id; ?> " /> <table cellspacing="0" class="widefat post fixed sorttable" id="compare_orders_<?php echo $cat->id; ?> " style="width:535px; margin-bottom:20px;"> <thead> <tr> <th width="25" style="white-space: nowrap;"><span class="c_field_name"> </span></th> <th><strong><?php echo stripslashes($cat->category_name); ?> </strong> :</th> <th width="90"></th> <th width="100" style="text-align:right; font-size:12px;white-space: nowrap;"><a href="admin.php?page=woo-compare-features&act=cat-edit&category_id=<?php echo $cat->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=cat-delete&category_id=<?php echo $cat->id; ?> " title="<?php _e('Delete', 'woo_cp'); ?> " class="c_field_delete" onclick="javascript:return confirmation('<?php _e('Are you sure you want to delete', 'woo_cp'); ?> #<?php echo htmlspecialchars($cat->category_name); ?> ');"><?php _e('Delete', 'woo_cp'); ?> </a><?php if (is_array($compare_fields) && count($compare_fields) > 0) { ?> | <span class="c_openclose_table c_close_table" id="expand_<?php echo $cat->id; ?> "> </span><?php } else { ?> | <span class="c_openclose_none"> </span><?php } ?> </th> </tr> </thead> <tbody class="expand_<?php echo $cat->id; ?> "> <?php if (is_array($compare_fields) && count($compare_fields) > 0) { $i = 0; foreach ($compare_fields as $field_data) { $i++; ?> <tr id="recordsArray_<?php echo $field_data->id; ?> " style="display:none"> <td><span class="compare_sort"><?php echo $i; ?> </span>.</td> <td><div class="c_field_name"><?php echo stripslashes($field_data->field_name); ?> </div></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; ?> &cat_id=<?php echo $cat->id; ?> " class="c_field_delete" onclick="javascript:return confirmation('<?php _e('Are you sure you want to remove', 'woo_cp'); ?> #<?php echo htmlspecialchars($field_data->field_name); ?> <?php _e('from', 'woo_cp'); ?> #<?php echo htmlspecialchars($cat->category_name); ?> ');" title="<?php _e('Remove', 'woo_cp'); ?> " ><?php _e('Remove', 'woo_cp'); ?> </a></td> </tr> <?php } } else { echo '<tr><td colspan="4">' . __('You have not assigned any Features to this category yet. No Hurry!', 'woo_cp') . '</td></tr>'; } ?> </tbody> </table> </li> <?php } ?> </ul> <?php wp_enqueue_script('jquery-ui-sortable'); ?> <?php $woocp_update_order = wp_create_nonce("woocp-update-order"); ?> <?php $woocp_update_cat_order = wp_create_nonce("woocp-update-cat-order"); ?> <script type="text/javascript"> (function($){ $(function(){ $(".c_openclose_table").click( function() { if ( $(this).hasClass('c_close_table') ) { $(this).removeClass("c_close_table"); $(this).addClass("c_open_table"); $("tbody."+$(this).attr('id')+" tr").css('display', ''); } else { $(this).removeClass("c_open_table"); $(this).addClass("c_close_table"); $("tbody."+$(this).attr('id')+" tr").css('display', 'none'); } }); var fixHelper = function(e, ui) { ui.children().each(function() { $(this).width($(this).width()); }); return ui; }; $(".sorttable tbody").sortable({ helper: fixHelper, placeholder: "ui-state-highlight", opacity: 0.8, cursor: 'move', update: function() { var cat_id = $(this).parent('table').siblings(".compare_category_id").val(); var order = $(this).sortable("serialize") + '&action=woocp_update_orders&security=<?php echo $woocp_update_order; ?> &cat_id='+cat_id; $.post("<?php echo admin_url('admin-ajax.php', 'relative'); ?> ", order, function(theResponse){ $(".update_feature_order_message p").html(theResponse); $(".update_feature_order_message").show(); $("#compare_orders_"+cat_id).find(".compare_sort").each(function(index){ $(this).html(index+1); }); }); } }); $("ul.sorttable").sortable({ placeholder: "ui-state-highlight", opacity: 0.8, cursor: 'move', update: function() { var order = $(this).sortable("serialize") + '&action=woocp_update_cat_orders&security=<?php echo $woocp_update_cat_order; ?> '; $.post("<?php echo admin_url('admin-ajax.php', 'relative'); ?> ", order, function(theResponse){ $(".update_feature_order_message p").html(theResponse).show(); $(".update_feature_order_message").show(); }); } }); }); })(jQuery); </script> <?php } }
public static function delete_rows($items = array()) { if (is_array($items) && count($items) > 0) { foreach ($items as $category_id) { WC_Compare_Categories_Data::delete_row($category_id); } } }
/** * Check product that is assigned the compare category for it */ public static function check_product_have_cat($product_id) { $compare_category = get_post_meta($product_id, '_woo_compare_category', true); if ($compare_category > 0 && WC_Compare_Categories_Data::get_count("id='" . $compare_category . "'") > 0) { $compare_fields = WC_Compare_Categories_Fields_Data::get_fieldid_results($compare_category); if (is_array($compare_fields) && count($compare_fields) > 0) { return true; } else { return false; } } else { return false; } }
public static function woocp_update_cat_orders() { check_ajax_referer('woocp-update-cat-order', 'security'); $updateRecordsArray = $_REQUEST['recordsArray']; $listingCounter = 1; foreach ($updateRecordsArray as $recordIDValue) { WC_Compare_Categories_Data::update_order($recordIDValue, $listingCounter); $listingCounter++; } _e('You just save the order for compare categories.', 'woo_cp'); die; }
public static function save_compare_meta_boxes($post_id) { $post_status = get_post_status($post_id); $post_type = get_post_type($post_id); if ($post_type == 'product' && $post_status != false) { if (isset($_REQUEST['_woo_deactivate_compare_feature']) && $_REQUEST['_woo_deactivate_compare_feature'] == 'no') { update_post_meta($post_id, '_woo_deactivate_compare_feature', 'no'); } else { update_post_meta($post_id, '_woo_deactivate_compare_feature', 'yes'); } $compare_category = 0; if (isset($_REQUEST['_woo_compare_category'])) { $compare_category = $_REQUEST['_woo_compare_category']; update_post_meta($post_id, '_woo_compare_category', $compare_category); } $category_data = WC_Compare_Categories_Data::get_row($compare_category); if ($category_data != NULL) { update_post_meta($post_id, '_woo_compare_category_name', stripslashes($category_data->category_name)); } $compare_fields = WC_Compare_Categories_Fields_Data::get_results("cat_id='" . $compare_category . "'", 'cf.field_order ASC'); if (is_array($compare_fields) && count($compare_fields) > 0) { foreach ($compare_fields as $field_data) { if (isset($_REQUEST['_woo_compare_' . $field_data->field_key])) { update_post_meta($post_id, '_woo_compare_' . $field_data->field_key, $_REQUEST['_woo_compare_' . $field_data->field_key]); } } } if (isset($_REQUEST['variable_post_id'])) { $variable_ids = $_REQUEST['variable_post_id']; foreach ($variable_ids as $variation_id) { $post_type = get_post_type($variation_id); if ($post_type == 'product_variation') { if (isset($_REQUEST['variable_woo_deactivate_compare_feature'][$variation_id]) && $_REQUEST['variable_woo_deactivate_compare_feature'][$variation_id] == 'no') { update_post_meta($variation_id, '_woo_deactivate_compare_feature', 'no'); } else { update_post_meta($variation_id, '_woo_deactivate_compare_feature', 'yes'); } $variation_compare_category = 0; if (isset($_REQUEST['variable_woo_compare_category'][$variation_id])) { $variation_compare_category = $_REQUEST['variable_woo_compare_category'][$variation_id]; update_post_meta($variation_id, '_woo_compare_category', $variation_compare_category); } $variation_category_data = WC_Compare_Categories_Data::get_row($variation_compare_category); if ($variation_category_data != NULL) { update_post_meta($variation_id, '_woo_compare_category_name', stripslashes($variation_category_data->category_name)); } $compare_fields = WC_Compare_Categories_Fields_Data::get_results("cat_id='" . $variation_compare_category . "'", 'cf.field_order ASC'); if (is_array($compare_fields) && count($compare_fields) > 0) { foreach ($compare_fields as $field_data) { if (isset($_REQUEST['variable_woo_compare_' . $field_data->field_key][$variation_id])) { update_post_meta($variation_id, '_woo_compare_' . $field_data->field_key, $_REQUEST['variable_woo_compare_' . $field_data->field_key][$variation_id]); } } } } } } } }
public static function woocp_products_manager() { $compare_product_message = ''; $paged = isset($_POST['paged']) ? $_POST['paged'] : 1; $rp = isset($_POST['rp']) ? $_POST['rp'] : 10; $cp_show_variations = isset($_POST['cp_show_variations']) ? $_POST['cp_show_variations'] : 0; $sortname = isset($_POST['sortname']) ? $_POST['sortname'] : 'title'; $sortorder = isset($_POST['sortorder']) ? $_POST['sortorder'] : 'asc'; $query = isset($_POST['query']) ? $_POST['query'] : ''; $qtype = isset($_POST['qtype']) ? $_POST['qtype'] : ''; if (isset($_REQUEST['bt_update_product_features'])) { if (isset($_REQUEST['productid']) && $_REQUEST['productid'] > 0) { $post_id = $_REQUEST['productid']; $post_status = get_post_status($post_id); $post_type = get_post_type($post_id); if (($post_type == 'product' || $post_type == 'product_variation') && $post_status != false) { if (isset($_REQUEST['_woo_deactivate_compare_feature']) && $_REQUEST['_woo_deactivate_compare_feature'] == 'no') { update_post_meta($post_id, '_woo_deactivate_compare_feature', 'no'); } else { update_post_meta($post_id, '_woo_deactivate_compare_feature', 'yes'); } $compare_category = $_REQUEST['_woo_compare_category']; update_post_meta($post_id, '_woo_compare_category', $compare_category); if ($compare_category > 0) { $category_data = WC_Compare_Categories_Data::get_row($compare_category); if ($category_data != NULL) { update_post_meta($post_id, '_woo_compare_category_name', stripslashes($category_data->category_name)); } $compare_fields = WC_Compare_Categories_Fields_Data::get_results("cat_id='" . $compare_category . "'", 'cf.field_order ASC'); if (is_array($compare_fields) && count($compare_fields) > 0) { foreach ($compare_fields as $field_data) { if (isset($_REQUEST['_woo_compare_' . $field_data->field_key])) { update_post_meta($post_id, '_woo_compare_' . $field_data->field_key, $_REQUEST['_woo_compare_' . $field_data->field_key]); } } } } else { update_post_meta($post_id, '_woo_compare_category_name', ''); } } $compare_product_message = '<div class="updated" id="result_msg"><p>' . __('Compare Product Feature Fields Successfully updated.', 'woo_cp') . '.</p></div>'; } } ?> <style> .update_message{padding:10px; background-color:#FFFFCC;border:1px solid #DDDDDD;margin-bottom:15px;} body .flexigrid div.sDiv{display:block;} .flexigrid div.sDiv .sDiv2 select{display:none;} .flexigrid div.sDiv .cp_search, .flexigrid div.sDiv .cp_reset{cursor:pointer;} .edit_product_compare{cursor:pointer; text-decoration:underline; color:#06F;} .icon32-compare-product { background:url(<?php echo WOOCP_IMAGES_URL; ?> /a3-plugins.png) no-repeat left top !important; } .pro_feature_fields { padding:0 10px 10px 10px; } </style> <div id="htmlForm"> <div style="clear:both"></div> <div class="wrap a3rev_panel_container a3rev_manager_panel_container"> <div id="a3_plugin_panel_container"><div id="a3_plugin_panel_fields"> <div class="icon32 icon32-compare-product" id="icon32-compare-product"><br></div> <h2><?php _e('WooCommerce Compare Products Manager', 'woo_cp'); ?> </h2> <?php echo $compare_product_message; ?> <div style="clear:both; margin-bottom:20px;"></div> <div class="pro_feature_fields"> <?php global $wc_compare_admin_init; $wc_compare_admin_init->upgrade_top_message(true); ?> <table id="woocp_products_manager" style="display:none"></table> </div> <?php $woocp_products_manager = wp_create_nonce("woocp-products-manager"); ?> <script type="text/javascript"> function alert_upgrade(text) { var answer = confirm(text) if (answer){ window.open("<?php echo WOOCP_AUTHOR_URI; ?> ", '_blank') }else{ return false; } } (function($){ $(function(){ $("#woocp_products_manager").flexigrid({ url: '<?php echo admin_url('admin-ajax.php', 'relative') . '?action=woocp_get_products&security=' . $woocp_products_manager; ?> ', dataType: 'json', width: 'auto', resizable: false, colModel : [ {display: '<?php _e("No", 'woo_cp'); ?> ', name : 'number', width : 20, sortable : false, align: 'right'}, {display: '<?php _e("Product Name", 'woo_cp'); ?> ', name : 'title', width : 200, sortable : true, align: 'left'}, {display: '<?php _e("Product Category", 'woo_cp'); ?> ', name : 'cat', width : 110, sortable : false, align: 'left'}, {display: '<?php _e("Compare Category", 'woo_cp'); ?> ', name : '_woo_compare_category_name', width : 110, sortable : true, align: 'left'}, {display: '<?php _e("Activated / Deactivated", 'woo_cp'); ?> ', name : '_woo_deactivate_compare_feature', width : 110, sortable : false, align: 'center'}, {display: '<?php _e("Edit", 'woo_cp'); ?> ', name : 'edit', width : 30, sortable : false, align: 'center'} ], searchitems : [ {display: '<?php _e("Product Name", 'woo_cp'); ?> ', name : 'title', isdefault: true} ], sortname: "title", sortorder: "asc", usepager: true, title: '<?php _e("Products", 'woo_cp'); ?> ', findtext: '<?php _e("Find Product Name", 'woo_cp'); ?> ', useRp: true, rp: <?php echo $rp; ?> , //results per page newp: <?php echo $paged; ?> , page: <?php echo $paged; ?> , query: '<?php echo $query; ?> ', qtype: '<?php echo $qtype; ?> ', sortname: '<?php echo $sortname; ?> ', sortorder: '<?php echo $sortorder; ?> ', rpOptions: [10, 15, 20, 30, 50, 100], //allowed per-page values showToggleBtn: false, //show or hide column toggle popup showTableToggleBtn: false, height: 'auto', variations: '<?php echo $cp_show_variations; ?> ' }); $(document).on("click", ".edit_product_compare", function(ev){ return alert_upgrade('<?php _e('Please upgrade to the Pro Version to activate Products express Compare feature manager', 'woo_cp'); ?> '); }); }); })(jQuery); </script> </div><div id="a3_plugin_panel_upgrade_area"><div id="a3_plugin_panel_extensions"><?php echo WC_Compare_Functions::plugin_pro_notice(); ?> </div></div></div> </div> </div> <?php }