/** * Get compare list on popup */ public static function get_compare_list_html_popup() { global $woo_compare_comparison_page_global_settings, $woo_compare_page_style, $woo_compare_table_style, $woo_compare_table_content_style, $woo_compare_addtocart_style, $woo_compare_viewcart_style; global $woo_compare_product_prices_style; $current_db_version = get_option('woocommerce_db_version', null); $compare_list = WC_Compare_Functions::get_compare_list(); $woo_compare_basket_icon = get_option('woo_compare_basket_icon'); if (trim($woo_compare_basket_icon) == '') { $woo_compare_basket_icon = WOOCP_IMAGES_URL . '/compare_remove.png'; } $html = ''; $product_cats = array(); $products_fields = array(); $products_prices = array(); $custom_class = ''; $add_to_cart_text = $woo_compare_addtocart_style['addtocart_link_text']; $add_to_cart_button_class = 'add_to_cart_link_type'; if (is_array($compare_list) && count($compare_list) > 0) { $html .= '<div id="compare-wrapper"><div class="compare-products">'; $html .= '<table id="product_comparison" class="compare_popup_table" border="1" bordercolor="' . $woo_compare_table_style['table_border_colour'] . '" cellpadding="5" cellspacing="0" width="">'; $html .= '<tbody><tr class="row_1 row_product_detail"><th class="column_first first_row"><div class="column_first_wide"> '; $html .= '</div></th>'; $i = 0; foreach ($compare_list as $product_id) { $product_cat = get_post_meta($product_id, '_woo_compare_category', true); $products_fields[$product_id] = WC_Compare_Categories_Fields_Data::get_fieldid_results($product_cat); if ($product_cat > 0) { $product_cats[] = $product_cat; } $i++; if (version_compare($current_db_version, '2.0', '<') && null !== $current_db_version) { $current_product = new WC_Product($product_id); } elseif (version_compare(WC()->version, '2.2.0', '<')) { $current_product = get_product($product_id); } else { $current_product = wc_get_product($product_id); } $product_name = WC_Compare_Functions::get_variation_name($product_id); $product_price = $current_product->get_price_html(); /** * Add code check show or hide price and add to cart button support for Woo Catalog Visibility Options plugin */ $show_add_to_cart = true; if (class_exists('WC_CVO_Visibility_Options')) { global $wc_cvo; /** * Check show or hide price */ if ($wc_cvo->setting('wc_cvo_prices') == 'secured' && !catalog_visibility_user_has_access() || $wc_cvo->setting('wc_cvo_prices') == 'disabled') { $product_price = ''; } /** * Check show or hide add to cart button */ if ($wc_cvo->setting('wc_cvo_atc') == 'secured' && !catalog_visibility_user_has_access() || $wc_cvo->setting('wc_cvo_atc') == 'disabled') { $show_add_to_cart = false; } } $products_prices[$product_id] = $product_price; $image_src = WC_Compare_Functions::get_post_thumbnail($product_id, 220, 180); if (trim($image_src) == '') { $image_src = '<img alt="' . $product_name . '" src="' . (version_compare($current_db_version, '2.1.0', '<') && null !== $current_db_version ? woocommerce_placeholder_img_src() : wc_placeholder_img_src()) . '" />'; } $html .= '<td class="first_row column_' . $i . '"><div class="td-spacer"><div class="woo_compare_popup_remove_product_container"><a class="woo_compare_popup_remove_product" rel="' . $product_id . '" style="cursor:pointer;">Remove <img src="' . $woo_compare_basket_icon . '" border=0 /></a></div>'; $html .= '<div class="compare_image_container">' . $image_src . '</div>'; $html .= '<div class="compare_product_name">' . $product_name . '</div>'; $html .= '<div class="compare_price">' . $products_prices[$product_id] . '</div>'; if ($show_add_to_cart && $current_product->is_in_stock() && trim($products_prices[$product_id]) != '') { if ($current_product->product_type != 'external') { $cart_url = add_query_arg('add-to-cart', $product_id, get_option('siteurl') . '/?post_type=product'); } else { if ($current_product->product_type == 'external') { if (version_compare($current_db_version, '2.0', '<') && null !== $current_db_version) { $cart_url = get_post_meta($product_id, '_product_url', true); $add_to_cart_text_external = get_post_meta($product_id, '_button_text', true); $add_to_cart_text_external ? $add_to_cart_text_external : __('Buy product', 'woo_cp'); } else { $cart_url = $current_product->product_url; $add_to_cart_text_external = $current_product->get_button_text(); } } } switch (get_post_type($product_id)) { case "product_variation": $class = 'is_variation'; $cart_url = WC_Compare_Functions::get_product_url($product_id); break; default: $class = 'simple'; break; } $html .= '<div class="compare_add_cart">'; if ($current_product->product_type == 'external') { $html .= sprintf('<a href="%s" rel="nofollow" class="button add_to_cart_button %s product_type_%s %s" target="_blank">%s</a>', $cart_url, $add_to_cart_button_class, $class, $custom_class, $add_to_cart_text_external); } else { $html .= sprintf('<a href="%s" data-product_id="%s" class="button add_to_cart_button %s product_type_%s %s" target="_blank">%s</a>', $cart_url, $product_id, $add_to_cart_button_class, $class, $custom_class, $add_to_cart_text); } $html .= '<a class="virtual_added_to_cart" href="#"> </a>'; $html .= '</div>'; } $html .= '</div></td>'; } $html .= '</tr>'; $product_cats = implode(",", $product_cats); $compare_fields = WC_Compare_Categories_Fields_Data::get_results('cat_id IN(' . $product_cats . ')', 'cf.cat_id ASC, cf.field_order ASC'); if (is_array($compare_fields) && count($compare_fields) > 0) { $j = 1; foreach ($compare_fields as $field_data) { $j++; $html .= '<tr class="row_' . $j . '">'; if (trim($field_data->field_unit) != '') { $html .= '<th class="column_first"><div class="compare_value">' . stripslashes($field_data->field_name) . ' (' . trim(stripslashes($field_data->field_unit)) . ')</div></th>'; } else { $html .= '<th class="column_first"><div class="compare_value">' . stripslashes($field_data->field_name) . '</div></th>'; } $i = 0; foreach ($compare_list as $product_id) { $i++; $empty_cell_class = ''; $empty_text_class = ''; if (in_array($field_data->id, $products_fields[$product_id])) { $field_value = get_post_meta($product_id, '_woo_compare_' . $field_data->field_key, true); if (is_serialized($field_value)) { $field_value = maybe_unserialize($field_value); } if (is_array($field_value) && count($field_value) > 0) { $field_value = implode(', ', $field_value); } elseif (is_array($field_value) && count($field_value) < 0) { $field_value = $woo_compare_table_content_style['empty_text']; } if (trim($field_value) == '') { $field_value = $woo_compare_table_content_style['empty_text']; } } else { $field_value = $woo_compare_table_content_style['empty_text']; } if ($field_value == $woo_compare_table_content_style['empty_text']) { $empty_cell_class = 'empty_cell'; $empty_text_class = 'empty_text'; } $html .= '<td class="column_' . $i . ' ' . $empty_cell_class . '"><div class="td-spacer ' . $empty_text_class . ' compare_' . $field_data->field_key . '">' . $field_value . '</div></td>'; } $html .= '</tr>'; if ($j == 2) { $j = 0; } } $j++; if ($j > 2) { $j = 1; } $html .= '<tr class="row_' . $j . ' row_end"><th class="column_first"> </th>'; $i = 0; foreach ($compare_list as $product_id) { $i++; $html .= '<td class="column_' . $i . '">'; $html .= '<div class="td-spacer compare_price">' . $products_prices[$product_id] . '</div>'; $html .= '</td>'; } } $html .= '</tbody></table>'; $html .= '</div></div>'; } else { $html .= '<div class="no_compare_list">' . $woo_compare_page_style['no_product_message_text'] . '</div>'; } return $html; }