admin_url( 'admin-ajax.php' ) ) ); $pcp_compare_data=get_option('data_compare_product'); $pcp_table_dataa = get_option('data_compare_table_product'); if(!empty($pcp_compare_data) || !empty($pcp_table_dataa)){ extract($pcp_table_dataa); extract($pcp_compare_data); if(isset($fields_attr) || $fields_attr!=''){ $fields_attr = unserialize($fields_attr); } } ?> id,$compare_product)){ echo "Added"; }else{ if(isset($bt_lk_text)){ echo ($bt_lk_text!='')?$bt_lk_text:'compare' ;}}?> 1,'is_button'=>'Button','bt_lk_text'=>'Compare', 'bt_product_page'=>1,'pcpp_button_in_image_'=>1, 'bt_product_list'=>1,'table_text'=>'Compare Table', 'fields_attr'=>serialize($fields_attr),'pcp_image_width'=>220, 'pcp_image_height'=>154, ); update_option('data_compare_product',$pcp_data); } $pcp_table_dataa = get_option('data_compare_table_product'); if((!isset($pcp_table_dataa) || empty($pcp_table_dataa))){ $fields_attr = Array( 'image', 'title', 'price','add-to-cart','description', 'stock' ); $pcp_data = array( 'table_text'=>'Compare Table', 'fields_attr'=>serialize($fields_attr),'pcp_image_width'=>220, 'pcp_image_height'=>154, ); update_option('data_compare_table_product',$pcp_data); } } add_action( 'woocommerce_after_shop_loop_item', 'pcp_shop_display_compare', 11); add_action( 'wp_ajax_pcp_data_retrive', 'pcp_data_retrive' ); add_action( 'wp_ajax_nopriv_pcp_data_retrive', 'pcp_data_retrive' ); function pcp_data_retrive(){ global $product; $pcp_compare_data = get_option('data_compare_product'); $pcp_table_dataa = get_option('data_compare_table_product'); if(!empty($pcp_compare_data) || !empty($pcp_table_dataa)){ extract($pcp_table_dataa); extract($pcp_compare_data); if(isset($fields_attr) || $fields_attr!=''){ $fields_attr = unserialize($fields_attr); } } $compare_data = $_SESSION['compare_data']; if(isset($_POST['prod_id'])){ $product_id=$_POST['prod_id']; if(!in_array($product_id,$compare_data)){ $compare_data[] = $product_id; $_SESSION['compare_data'] = $compare_data; } if(!isset($div_data)){ $div_data = ''; } if(empty($div_data)){ $div_data['first_div'] = ''; //remove button row $div_data['first_div'] = ''; foreach($compare_data as $com_pro_id){ $_pf = new WC_Product_Factory(); $all_product=$_pf->get_product($com_pro_id); $all_product->get_availability(); $pur = $all_product->is_purchasable() && $all_product->is_in_stock() ? 'add_to_cart_button' : ''; $product_type = esc_attr( $all_product->product_type ); $src = wp_get_attachment_image_src( get_post_thumbnail_id($com_pro_id),'full'); $product_image=$src[0]; $div_data['first_div'] .= ' Remove '; } $div_data['first_div'] .=''; //title row $div_data['first_div'] .= ''; foreach($compare_data as $com_pro_id){ $_pf = new WC_Product_Factory(); $all_product=$_pf->get_product($com_pro_id); $all_product->get_availability(); $related = $all_product->get_related(); $pur = $all_product->is_purchasable() && $all_product->is_in_stock() ? 'add_to_cart_button' : ''; $product_type = esc_attr( $all_product->product_type ); $src = wp_get_attachment_image_src( get_post_thumbnail_id($com_pro_id),'full'); $product_image=$src[0]; if(isset($fields_attr) && !empty($fields_attr)){ if(in_array('title',$fields_attr)){ $div_data['first_div'] .= ''; $pr_title= get_the_title($com_pro_id) ; $div_data['first_div'] .= $pr_title; $div_data['first_div'] .= ''; } } } $div_data['first_div'] .=''; //description Row $div_data['first_div'] .= ''; foreach($compare_data as $com_pro_id){ $_pf = new WC_Product_Factory(); $all_product=$_pf->get_product($com_pro_id); $all_product->get_availability(); $pur = $all_product->is_purchasable() && $all_product->is_in_stock() ? 'add_to_cart_button' : ''; $product_type = esc_attr( $all_product->product_type ); $src = wp_get_attachment_image_src( get_post_thumbnail_id($com_pro_id),'full'); $product_image=$src[0]; if(isset($fields_attr) && !empty($fields_attr)){ if(in_array('description',$fields_attr)){ $div_data['first_div'] .= ''; if($description_excerpt_enable == 1){ $pr_desc= $all_product->post->post_content; preg_match('/.+)[\'"].*>/i', $pr_desc, $pr_desc_image); $pr_desc_with_out_image = strip_tags($pr_desc); if(strlen($pr_desc_with_out_image)> $description_excerpt_count){ $pr_desc_with_out_image = substr($pr_desc_with_out_image, 0, $description_excerpt_count)."..."; $pr_desc = $pr_desc_image[0].$pr_desc_with_out_image; }else{ $pr_desc; } }else{ $pr_desc = $all_product->post->post_content; } $div_data['first_div'] .= $pr_desc ; $div_data['first_div'] .= ''; } } } $div_data['first_div'] .=''; //image Row $div_data['first_div'] .= ''; foreach($compare_data as $com_pro_id){ $_pf = new WC_Product_Factory(); $all_product=$_pf->get_product($com_pro_id); $all_product->get_availability(); $pur = $all_product->is_purchasable() && $all_product->is_in_stock() ? 'add_to_cart_button' : ''; $product_type = esc_attr( $all_product->product_type ); $src = wp_get_attachment_image_src( get_post_thumbnail_id($com_pro_id),'full'); $product_image=$src[0]; if($product_image!=''){ $product_image; }else{ $product_image = plugins_url()."/woocommerce/assets/images/placeholder.png"; } if(isset($fields_attr) && !empty($fields_attr)){ if(in_array('image',$fields_attr)){ $div_data['first_div'] .= 'Placeholder'; } } } $div_data['first_div'] .=''; //price Row $div_data['first_div'] .= ''; foreach($compare_data as $com_pro_id){ $_pf = new WC_Product_Factory(); $all_product=$_pf->get_product($com_pro_id); $all_product->get_availability(); $pur = $all_product->is_purchasable() && $all_product->is_in_stock() ? 'add_to_cart_button' : ''; $product_type = esc_attr( $all_product->product_type ); $src = wp_get_attachment_image_src( get_post_thumbnail_id($com_pro_id),'full'); $product_image=$src[0]; if(isset($fields_attr) && !empty($fields_attr)){ if(in_array('price',$fields_attr)){ $div_data['first_div'] .= ''; $pr_price= $all_product->price; if(!empty($pr_price)){ $div_data['first_div'] .= get_woocommerce_currency_symbol(); $div_data['first_div'] .= $pr_price; }else{ $div_data['first_div'] .= "-"; } $div_data['first_div'] .= ''; } } } $div_data['first_div'] .=''; //stock Row $div_data['first_div'] .= ''; foreach($compare_data as $com_pro_id){ $_pf = new WC_Product_Factory(); $all_product=$_pf->get_product($com_pro_id); $all_product->get_availability(); $pur = $all_product->is_purchasable() && $all_product->is_in_stock() ? 'add_to_cart_button' : ''; $product_type = esc_attr( $all_product->product_type ); $src = wp_get_attachment_image_src( get_post_thumbnail_id($com_pro_id),'full'); $product_image=$src[0]; if(isset($fields_attr) && !empty($fields_attr)){ if(in_array('stock',$fields_attr)){ $div_data['first_div'] .= ''; $pr_stock=$all_product->stock_status; $div_data['first_div'] .= $pr_stock; $div_data['first_div'] .= ''; } } } $div_data['first_div'] .=''; //all attributes row if(isset($dynamic_attributes)&&!empty($dynamic_attributes)){ foreach($dynamic_attributes as $dynamic_attribute => $dynamic_attribute_value){ $div_data['first_div'] .= ''; foreach($compare_data as $com_pro_id){ $_pf = new WC_Product_Factory(); $all_product=$_pf->get_product($com_pro_id); $all_product->get_availability(); $pr_type = $all_product->product_type; $related = $all_product->get_related(); $pur = $all_product->is_purchasable() && $all_product->is_in_stock() ? 'add_to_cart_button' : ''; $product_type = esc_attr( $all_product->product_type ); $attributes = $all_product->get_attributes(); $src = wp_get_attachment_image_src( get_post_thumbnail_id($com_pro_id),'full'); $product_image=$src[0]; if ( get_option( 'woocommerce_enable_review_rating' ) === 'no' ) { return; } //$rating_count = $review_count = count( get_product_reviews( $com_pro_id ) ); //$average = get_average_rating( $com_pro_id ); $pcp_colors = wc_get_product_terms( $all_product->id, $dynamic_attribute_value ); $comma_pcp_color = array(); foreach($pcp_colors as $pcp_color){ $comma_pcp_color[] = $pcp_color->name; } $comma_pcp_color = implode(',',$comma_pcp_color); $div_data['first_div'] .= ''; if(isset($comma_pcp_color) && !empty($comma_pcp_color)){ $div_data['first_div'] .= $comma_pcp_color; }else{ $div_data['first_div'] .= "-"; } $div_data['first_div'] .= ''; } $div_data['first_div'] .=''; } } //Add to cart row $div_data['first_div'] .= ''; foreach($compare_data as $com_pro_id){ $_pf = new WC_Product_Factory(); $all_product=$_pf->get_product($com_pro_id); $all_product->get_availability(); $pur = $all_product->is_purchasable() && $all_product->is_in_stock() ? 'add_to_cart_button' : ''; $product_type = esc_attr( $all_product->product_type ); $src = wp_get_attachment_image_src( get_post_thumbnail_id($com_pro_id),'full'); $product_image=$src[0]; if(isset($fields_attr) && !empty($fields_attr)){ if(in_array('add-to-cart',$fields_attr)){ $div_data['first_div'].=''.$all_product->add_to_cart_text().''; } } } $div_data['first_div'] .=''; } else{ //remove button row $div_data['first_div'] = ''; foreach($compare_data as $com_pro_id){ $_pf = new WC_Product_Factory(); $all_product=$_pf->get_product($com_pro_id); $all_product->get_availability(); $pur = $all_product->is_purchasable() && $all_product->is_in_stock() ? 'add_to_cart_button' : ''; $product_type = esc_attr( $all_product->product_type ); $src = wp_get_attachment_image_src( get_post_thumbnail_id($com_pro_id),'full'); $product_image=$src[0]; $div_data['first_div'] .= ' Remove '; } $div_data['first_div'] .=''; //title row $div_data['first_div'] .= ''; foreach($compare_data as $com_pro_id){ $_pf = new WC_Product_Factory(); $all_product=$_pf->get_product($com_pro_id); $all_product->get_availability(); $pur = $all_product->is_purchasable() && $all_product->is_in_stock() ? 'add_to_cart_button' : ''; $product_type = esc_attr( $all_product->product_type ); $src = wp_get_attachment_image_src( get_post_thumbnail_id($com_pro_id),'full'); $product_image=$src[0]; if(isset($fields_attr) && !empty($fields_attr)){ if(in_array('title',$fields_attr)){ $div_data['first_div'] .= ''; $pr_title= get_the_title($com_pro_id) ; $div_data['first_div'] .= $pr_title; $div_data['first_div'] .= ''; } } } $div_data['first_div'] .=''; //description Row $div_data['first_div'] .= ''; foreach($compare_data as $com_pro_id){ $_pf = new WC_Product_Factory(); $all_product=$_pf->get_product($com_pro_id); $all_product->get_availability(); $pur = $all_product->is_purchasable() && $all_product->is_in_stock() ? 'add_to_cart_button' : ''; $product_type = esc_attr( $all_product->product_type ); $src = wp_get_attachment_image_src( get_post_thumbnail_id($com_pro_id),'full'); $product_image=$src[0]; if(isset($fields_attr) && !empty($fields_attr)){ if(in_array('description',$fields_attr)){ $div_data['first_div'] .= ''; if($description_excerpt_enable == 1){ $pr_desc= $all_product->post->post_content; preg_match('/.+)[\'"].*>/i', $pr_desc, $pr_desc_image); $pr_desc_with_out_image = strip_tags($pr_desc); if(strlen($pr_desc_with_out_image)> $description_excerpt_count){ $pr_desc_with_out_image = substr($pr_desc_with_out_image, 0, $description_excerpt_count)."..."; $pr_desc = $pr_desc_image[0].$pr_desc_with_out_image; }else{ $pr_desc; } }else{ $pr_desc = $all_product->post->post_content; } $div_data['first_div'] .= $pr_desc ; $div_data['first_div'] .= ''; } } } $div_data['first_div'] .=''; //image Row $div_data['first_div'] .= ''; foreach($compare_data as $com_pro_id){ $_pf = new WC_Product_Factory(); $all_product=$_pf->get_product($com_pro_id); $all_product->get_availability(); $pur = $all_product->is_purchasable() && $all_product->is_in_stock() ? 'add_to_cart_button' : ''; $product_type = esc_attr( $all_product->product_type ); $src = wp_get_attachment_image_src( get_post_thumbnail_id($com_pro_id),'full'); $product_image=$src[0]; if($product_image!=''){ $product_image; }else{ $product_image = plugins_url()."/woocommerce/assets/images/placeholder.png"; } if(isset($fields_attr) && !empty($fields_attr)){ if(in_array('image',$fields_attr)){ $div_data['first_div'] .= 'Placeholder'; } } } $div_data['first_div'] .=''; //price Row $div_data['first_div'] .= ''; foreach($compare_data as $com_pro_id){ $_pf = new WC_Product_Factory(); $all_product=$_pf->get_product($com_pro_id); $all_product->get_availability(); $pur = $all_product->is_purchasable() && $all_product->is_in_stock() ? 'add_to_cart_button' : ''; $product_type = esc_attr( $all_product->product_type ); $src = wp_get_attachment_image_src( get_post_thumbnail_id($com_pro_id),'full'); $product_image=$src[0]; if(isset($fields_attr) && !empty($fields_attr)){ if(in_array('price',$fields_attr)){ $div_data['first_div'] .= ''; $pr_price= $all_product->price; if(!empty($pr_price)){ $div_data['first_div'] .= get_woocommerce_currency_symbol(); $div_data['first_div'] .= $pr_price; }else{ $div_data['first_div'] .= "-"; } $div_data['first_div'] .= ''; } } } $div_data['first_div'] .=''; //stock Row $div_data['first_div'] .= ''; foreach($compare_data as $com_pro_id){ $_pf = new WC_Product_Factory(); $all_product=$_pf->get_product($com_pro_id); $all_product->get_availability(); $pur = $all_product->is_purchasable() && $all_product->is_in_stock() ? 'add_to_cart_button' : ''; $product_type = esc_attr( $all_product->product_type ); $src = wp_get_attachment_image_src( get_post_thumbnail_id($com_pro_id),'full'); $product_image=$src[0]; if(isset($fields_attr) && !empty($fields_attr)){ if(in_array('stock',$fields_attr)){ $div_data['first_div'] .= ''; $pr_stock=$all_product->stock_status; $div_data['first_div'] .= $pr_stock ; $div_data['first_div'] .= ''; } } } $div_data['first_div'] .=''; //all attributes row if(isset($dynamic_attributes)&&!empty($dynamic_attributes)){ foreach($dynamic_attributes as $dynamic_attribute => $dynamic_attribute_value){ $div_data['first_div'] .= ''; foreach($compare_data as $com_pro_id){ $_pf = new WC_Product_Factory(); $all_product=$_pf->get_product($com_pro_id); $all_product->get_availability(); $pr_type = $all_product->product_type; $related = $all_product->get_related(); $pur = $all_product->is_purchasable() && $all_product->is_in_stock() ? 'add_to_cart_button' : ''; $product_type = esc_attr( $all_product->product_type ); $attributes = $all_product->get_attributes(); $src = wp_get_attachment_image_src( get_post_thumbnail_id($com_pro_id),'full'); $product_image=$src[0]; if ( get_option( 'woocommerce_enable_review_rating' ) === 'no' ) { return; } //$rating_count = $review_count = count( get_product_reviews( $com_pro_id ) ); //$average = get_average_rating( $com_pro_id ); $pcp_colors = wc_get_product_terms( $all_product->id, $dynamic_attribute_value ); $comma_pcp_color = array(); foreach($pcp_colors as $pcp_color){ $comma_pcp_color[] = $pcp_color->name; } $comma_pcp_color = implode(',',$comma_pcp_color); $div_data['first_div'] .= ''; if(isset($comma_pcp_color) && !empty($comma_pcp_color)){ $div_data['first_div'] .= $comma_pcp_color; }else{ $div_data['first_div'] .= "-"; } $div_data['first_div'] .= ''; } $div_data['first_div'] .=''; } } //Add to cart row $div_data['first_div'] .= ''; foreach($compare_data as $com_pro_id){ $_pf = new WC_Product_Factory(); $all_product=$_pf->get_product($com_pro_id); $all_product->get_availability(); $pur = $all_product->is_purchasable() && $all_product->is_in_stock() ? 'add_to_cart_button' : ''; $product_type = esc_attr( $all_product->product_type ); $src = wp_get_attachment_image_src( get_post_thumbnail_id($com_pro_id),'full'); $product_image=$src[0]; if(isset($fields_attr) && !empty($fields_attr)){ if(in_array('add-to-cart',$fields_attr)){ $div_data['first_div'].=''.$all_product->add_to_cart_text().''; } } } $div_data['first_div'] .=''; } echo json_encode($div_data); } die(); } add_action( 'wp_ajax_pcp_product_id_remove', 'pcp_product_id_remove' ); add_action( 'wp_ajax_nopriv_pcp_product_id_remove', 'pcp_product_id_remove' ); function pcp_product_id_remove(){ $pcp_compare_data=get_option('data_compare_product'); $pcp_table_dataa = get_option('data_compare_table_product'); if(!empty($pcp_compare_data) || !empty($pcp_table_dataa)){ extract($pcp_table_dataa); extract($pcp_compare_data); if(isset($fields_attr) || $fields_attr!=''){ $fields_attr=unserialize($fields_attr); } } $remove_pro_id = $_POST['remove_prod_id']; $compare_data1 = $_SESSION['compare_data']; if(!empty($remove_pro_id)){ $compare_data = $_SESSION['compare_data']; foreach ($compare_data as $key => $value){ if ($value == $remove_pro_id) { unset($compare_data[$key]); $_SESSION['compare_data'] = $compare_data; } } $compare_data = $_SESSION['compare_data']; if(!empty($compare_data)){ if(!isset($div_data)){ $div_data = ''; } if(empty($div_data)){ $div_data['first_div'] = ''; //remove button row $div_data['first_div'] = ''; foreach($compare_data as $com_pro_id){ $_pf = new WC_Product_Factory(); $all_product=$_pf->get_product($com_pro_id); $all_product->get_availability(); $pur = $all_product->is_purchasable() && $all_product->is_in_stock() ? 'add_to_cart_button' : ''; $product_type = esc_attr( $all_product->product_type ); $src = wp_get_attachment_image_src( get_post_thumbnail_id($com_pro_id),'full'); $product_image=$src[0]; $div_data['first_div'] .= ' Remove '; } $div_data['first_div'] .=''; //title row $div_data['first_div'] .= ''; foreach($compare_data as $com_pro_id){ $_pf = new WC_Product_Factory(); $all_product=$_pf->get_product($com_pro_id); $all_product->get_availability(); $pur = $all_product->is_purchasable() && $all_product->is_in_stock() ? 'add_to_cart_button' : ''; $product_type = esc_attr( $all_product->product_type ); $src = wp_get_attachment_image_src( get_post_thumbnail_id($com_pro_id),'full'); $product_image=$src[0]; if(isset($fields_attr) && !empty($fields_attr)){ if(in_array('title',$fields_attr)){ $div_data['first_div'] .= ''; $pr_title= get_the_title($com_pro_id) ; $div_data['first_div'] .= $pr_title ;//= substr($pr_title, 0, 20)."..."; $div_data['first_div'] .= ''; } } } $div_data['first_div'] .=''; //description Row $div_data['first_div'] .= ''; foreach($compare_data as $com_pro_id){ $_pf = new WC_Product_Factory(); $all_product=$_pf->get_product($com_pro_id); $all_product->get_availability(); $pur = $all_product->is_purchasable() && $all_product->is_in_stock() ? 'add_to_cart_button' : ''; $product_type = esc_attr( $all_product->product_type ); $src = wp_get_attachment_image_src( get_post_thumbnail_id($com_pro_id),'full'); $product_image=$src[0]; if(isset($fields_attr) && !empty($fields_attr)){ if(in_array('description',$fields_attr)){ $div_data['first_div'] .= ''; $pr_desc= $all_product->post->post_content; if($description_excerpt_enable == 1){ $pr_desc= $all_product->post->post_content; preg_match('/.+)[\'"].*>/i', $pr_desc, $pr_desc_image); $pr_desc_with_out_image = strip_tags($pr_desc); if(strlen($pr_desc_with_out_image)> $description_excerpt_count){ $pr_desc_with_out_image = substr($pr_desc_with_out_image, 0, $description_excerpt_count)."..."; $pr_desc = $pr_desc_image[0].$pr_desc_with_out_image; }else{ $pr_desc; } }else{ $pr_desc = $all_product->post->post_content; } $div_data['first_div'] .= $pr_desc ; $div_data['first_div'] .= ''; } } } $div_data['first_div'] .=''; //image Row $div_data['first_div'] .= ''; foreach($compare_data as $com_pro_id){ $_pf = new WC_Product_Factory(); $all_product=$_pf->get_product($com_pro_id); $all_product->get_availability(); $pur = $all_product->is_purchasable() && $all_product->is_in_stock() ? 'add_to_cart_button' : ''; $product_type = esc_attr( $all_product->product_type ); $src = wp_get_attachment_image_src( get_post_thumbnail_id($com_pro_id),'full'); $product_image=$src[0]; if($product_image!=''){ $product_image; }else{ $product_image = plugins_url()."/woocommerce/assets/images/placeholder.png"; } if(isset($fields_attr) && !empty($fields_attr)){ if(in_array('image',$fields_attr)){ $div_data['first_div'] .= 'Placeholder'; } } } $div_data['first_div'] .=''; //price Row $div_data['first_div'] .= ''; foreach($compare_data as $com_pro_id){ $_pf = new WC_Product_Factory(); $all_product=$_pf->get_product($com_pro_id); $all_product->get_availability(); $pur = $all_product->is_purchasable() && $all_product->is_in_stock() ? 'add_to_cart_button' : ''; $product_type = esc_attr( $all_product->product_type ); $src = wp_get_attachment_image_src( get_post_thumbnail_id($com_pro_id),'full'); $product_image=$src[0]; if(isset($fields_attr) && !empty($fields_attr)){ if(in_array('price',$fields_attr)){ $div_data['first_div'] .= ''; $pr_price= $all_product->price; if(!empty($pr_price)){ $div_data['first_div'] .= get_woocommerce_currency_symbol(); $div_data['first_div'] .= $pr_price; }else{ $div_data['first_div'] .= "-"; } $div_data['first_div'] .= ''; } } } $div_data['first_div'] .=''; //stock Row $div_data['first_div'] .= ''; foreach($compare_data as $com_pro_id){ $_pf = new WC_Product_Factory(); $all_product=$_pf->get_product($com_pro_id); $all_product->get_availability(); $pur = $all_product->is_purchasable() && $all_product->is_in_stock() ? 'add_to_cart_button' : ''; $product_type = esc_attr( $all_product->product_type ); $src = wp_get_attachment_image_src( get_post_thumbnail_id($com_pro_id),'full'); $product_image=$src[0]; if(isset($fields_attr) && !empty($fields_attr)){ if(in_array('stock',$fields_attr)){ $div_data['first_div'] .= ''; $pr_stock=$all_product->stock_status; $div_data['first_div'] .= $pr_stock ; $div_data['first_div'] .= ''; } } } $div_data['first_div'] .=''; //all attributes row if(isset($dynamic_attributes)&&!empty($dynamic_attributes)){ foreach($dynamic_attributes as $dynamic_attribute => $dynamic_attribute_value){ $div_data['first_div'] .= ''; foreach($compare_data as $com_pro_id){ $_pf = new WC_Product_Factory(); $all_product=$_pf->get_product($com_pro_id); $all_product->get_availability(); $pr_type = $all_product->product_type; $related = $all_product->get_related(); $pur = $all_product->is_purchasable() && $all_product->is_in_stock() ? 'add_to_cart_button' : ''; $product_type = esc_attr( $all_product->product_type ); $attributes = $all_product->get_attributes(); $src = wp_get_attachment_image_src( get_post_thumbnail_id($com_pro_id),'full'); $product_image=$src[0]; if ( get_option( 'woocommerce_enable_review_rating' ) === 'no' ) { return; } //$rating_count = $review_count = count( get_product_reviews( $com_pro_id ) ); //$average = get_average_rating( $com_pro_id ); $pcp_colors = wc_get_product_terms( $all_product->id, $dynamic_attribute_value ); $comma_pcp_color = array(); foreach($pcp_colors as $pcp_color){ $comma_pcp_color[] = $pcp_color->name; } $comma_pcp_color = implode(',',$comma_pcp_color); $div_data['first_div'] .= ''; if(isset($comma_pcp_color) && !empty($comma_pcp_color)){ $div_data['first_div'] .= $comma_pcp_color; }else{ $div_data['first_div'] .= "-"; } $div_data['first_div'] .= ''; } $div_data['first_div'] .=''; } } //Add to cart row $div_data['first_div'] .= ''; foreach($compare_data as $com_pro_id){ $_pf = new WC_Product_Factory(); $all_product=$_pf->get_product($com_pro_id); $all_product->get_availability(); $pur = $all_product->is_purchasable() && $all_product->is_in_stock() ? 'add_to_cart_button' : ''; $product_type = esc_attr( $all_product->product_type ); $src = wp_get_attachment_image_src( get_post_thumbnail_id($com_pro_id),'full'); $product_image=$src[0]; if(isset($fields_attr) && !empty($fields_attr)){ if(in_array('add-to-cart',$fields_attr)){ $div_data['first_div'].=''.$all_product->add_to_cart_text().''; } } } $div_data['first_div'] .=''; } else{ //remove button row $div_data['first_div'] = ''; foreach($compare_data as $com_pro_id){ $_pf = new WC_Product_Factory(); $all_product=$_pf->get_product($com_pro_id); $all_product->get_availability(); $pur = $all_product->is_purchasable() && $all_product->is_in_stock() ? 'add_to_cart_button' : ''; $product_type = esc_attr( $all_product->product_type ); $src = wp_get_attachment_image_src( get_post_thumbnail_id($com_pro_id),'full'); $product_image=$src[0]; $div_data['first_div'] .= ' Remove '; } $div_data['first_div'] .=''; //title row $div_data['first_div'] .= ''; foreach($compare_data as $com_pro_id){ $_pf = new WC_Product_Factory(); $all_product=$_pf->get_product($com_pro_id); $all_product->get_availability(); $pur = $all_product->is_purchasable() && $all_product->is_in_stock() ? 'add_to_cart_button' : ''; $product_type = esc_attr( $all_product->product_type ); $src = wp_get_attachment_image_src( get_post_thumbnail_id($com_pro_id),'full'); $product_image=$src[0]; if(isset($fields_attr) && !empty($fields_attr)){ if(in_array('title',$fields_attr)){ $div_data['first_div'] .= ''; $pr_title= get_the_title($com_pro_id) ; /* if(strlen($pr_title)>20){ */ $div_data['first_div'] .= $pr_title ;//= substr($pr_title, 0, 20)."..."; /* }else{ $div_data['first_div'] .= $pr_title; } */ $div_data['first_div'] .= ''; } } } $div_data['first_div'] .=''; //description Row $div_data['first_div'] .= ''; foreach($compare_data as $com_pro_id){ $_pf = new WC_Product_Factory(); $all_product=$_pf->get_product($com_pro_id); $all_product->get_availability(); $pur = $all_product->is_purchasable() && $all_product->is_in_stock() ? 'add_to_cart_button' : ''; $product_type = esc_attr( $all_product->product_type ); $src = wp_get_attachment_image_src( get_post_thumbnail_id($com_pro_id),'full'); $product_image=$src[0]; if(isset($fields_attr) && !empty($fields_attr)){ if(in_array('description',$fields_attr)){ $div_data['first_div'] .= ''; $pr_desc= $all_product->post->post_content; if($description_excerpt_enable == 1){ $pr_desc= $all_product->post->post_content; preg_match('/.+)[\'"].*>/i', $pr_desc, $pr_desc_image); $pr_desc_with_out_image = strip_tags($pr_desc); if(strlen($pr_desc_with_out_image)> $description_excerpt_count){ $pr_desc_with_out_image = substr($pr_desc_with_out_image, 0, $description_excerpt_count)."..."; $pr_desc = $pr_desc_image[0].$pr_desc_with_out_image; }else{ $pr_desc; } }else{ $pr_desc = $all_product->post->post_content; } $div_data['first_div'] .= $pr_desc ; $div_data['first_div'] .= ''; } } } $div_data['first_div'] .=''; //image Row $div_data['first_div'] .= ''; foreach($compare_data as $com_pro_id){ $_pf = new WC_Product_Factory(); $all_product=$_pf->get_product($com_pro_id); $all_product->get_availability(); $pur = $all_product->is_purchasable() && $all_product->is_in_stock() ? 'add_to_cart_button' : ''; $product_type = esc_attr( $all_product->product_type ); $src = wp_get_attachment_image_src( get_post_thumbnail_id($com_pro_id),'full'); $product_image=$src[0]; if($product_image!=''){ $product_image; }else{ $product_image = plugins_url()."/woocommerce/assets/images/placeholder.png"; } if(isset($fields_attr) && !empty($fields_attr)){ if(in_array('image',$fields_attr)){ $div_data['first_div'] .= 'Placeholder'; } } } $div_data['first_div'] .=''; //price Row $div_data['first_div'] .= ''; foreach($compare_data as $com_pro_id){ $_pf = new WC_Product_Factory(); $all_product=$_pf->get_product($com_pro_id); $all_product->get_availability(); $pur = $all_product->is_purchasable() && $all_product->is_in_stock() ? 'add_to_cart_button' : ''; $product_type = esc_attr( $all_product->product_type ); $src = wp_get_attachment_image_src( get_post_thumbnail_id($com_pro_id),'full'); $product_image=$src[0]; if(isset($fields_attr) && !empty($fields_attr)){ if(in_array('price',$fields_attr)){ $div_data['first_div'] .= ''; $pr_price= $all_product->price; if(!empty($pr_price)){ $div_data['first_div'] .= get_woocommerce_currency_symbol(); $div_data['first_div'] .= $pr_price; }else{ $div_data['first_div'] .= "-"; } $div_data['first_div'] .= ''; } } } $div_data['first_div'] .=''; //stock Row $div_data['first_div'] .= ''; foreach($compare_data as $com_pro_id){ $_pf = new WC_Product_Factory(); $all_product=$_pf->get_product($com_pro_id); $all_product->get_availability(); $pur = $all_product->is_purchasable() && $all_product->is_in_stock() ? 'add_to_cart_button' : ''; $product_type = esc_attr( $all_product->product_type ); $src = wp_get_attachment_image_src( get_post_thumbnail_id($com_pro_id),'full'); $product_image=$src[0]; if(isset($fields_attr) && !empty($fields_attr)){ if(in_array('stock',$fields_attr)){ $div_data['first_div'] .= ''; $pr_stock=$all_product->stock_status; $div_data['first_div'] .= $pr_stock ;//= substr($pr_stock, 0, 20)."..."; $div_data['first_div'] .= ''; } } } $div_data['first_div'] .=''; //Add to cart row $div_data['first_div'] .= ''; foreach($compare_data as $com_pro_id){ $_pf = new WC_Product_Factory(); $all_product=$_pf->get_product($com_pro_id); $all_product->get_availability(); $pur = $all_product->is_purchasable() && $all_product->is_in_stock() ? 'add_to_cart_button' : ''; $src = wp_get_attachment_image_src( get_post_thumbnail_id($com_pro_id),'full'); $product_image=$src[0]; if(isset($fields_attr) && !empty($fields_attr)){ if(in_array('add-to-cart',$fields_attr)){ $div_data['first_div'].=''.$all_product->add_to_cart_text().''; } } } $div_data['first_div'] .=''; } echo json_encode($div_data); } } die(); } if($is_button == 'Button' && $pcpp_button_in_image_ == 1){ add_action( 'woocommerce_before_shop_loop_item_title', create_function('', 'echo "
";'), 5, 2); add_action( 'woocommerce_before_shop_loop_item_title',create_function('', 'echo "
";'), 12, 2); } add_action('woocommerce_single_product_summary','pcp_product_display_compare',37); function pcp_product_display_compare(){ $pcp_compare_data=get_option('data_compare_product'); $pcp_table_dataa = get_option('data_compare_table_product'); if(!empty($pcp_compare_data) || !empty($pcp_table_dataa)){ extract($pcp_table_dataa); extract($pcp_compare_data); if(isset($fields_attr) || $fields_attr!=''){ $fields_attr=unserialize($fields_attr); } } if(isset($bt_product_list)&& ($bt_product_list==1)){ global $product; if(isset($fields_attr) || $fields_attr!=''){ $fields_attr; } if(isset($auto_open)&& ($auto_open==1)){ wp_enqueue_script("pcp-quick-js", plugin_dir_url(__FILE__)."js/quick_display.js",array('jquery'),'',true); } if(!isset($_SESSION['compare_data'])){ $compare_data=array(); $_SESSION['compare_data']=$compare_data; } $compare_product=$_SESSION['compare_data']; wp_enqueue_style( 'style_custom_request', plugin_dir_url(__FILE__).'css/custom_css.css' ); if($is_enable==1){ ?> id,$compare_product)){ echo "Added"; }else{ if(isset($bt_lk_text)){ echo ($bt_lk_text!='')?$bt_lk_text:'compare' ;}}?>

Please Activate WooCommerce Plugin First, to use it.