<?php
/**
 * The public-specific functionality of the plugin.
 *
 * @link       www.redefiningtheweb.com
 * @since      1.0.0
 *
 * @package    Rtwwpcp_Woocommerce_Pdf_Catalog_Pro
 * @subpackage Rtwwpcp_Woocommerce_Pdf_Catalog_Pro/public
 */
/**
 * The public-specific functionality of the plugin.
 *
 * Defines the plugin name, version, and two examples hooks for how to
 * enqueue the public-specific stylesheet and JavaScript.
 *
 * @package    Rtwwpcp_Woocommerce_Pdf_Catalog_Pro
 * @subpackage Rtwwpcp_Woocommerce_Pdf_Catalog_Pro/public
 * @author     RedefiningTheWeb <developer@redefiningtheweb.com>
 */
class Rtwwpcp_Woocommerce_Pdf_Catalog_Pro_Public {
	/**
	 * The ID of this plugin.
	 *
	 * @since    1.0.0
	 * @access   private
	 * @var      string    $rtwwpcp_plugin_name    The ID of this plugin.
	 */
	private $rtwwpcp_plugin_name;
	/**
	 * The version of this plugin.
	 *
	 * @since    1.0.0
	 * @access   private
	 * @var      string    $rtwwpcp_version    The current version of this plugin.
	 */
	private $rtwwpcp_version;
	/**
	 * Initialize the class and set its properties.
	 *
	 * @since    1.0.0
	 * @param      string    $rtwwpcp_plugin_name       The name of this plugin.
	 * @param      string    $rtwwpcp_version    The version of this plugin.
	 */
	public function __construct( $rtwwpcp_plugin_name, $rtwwpcp_version ) {
		$this->rtwwpcp_plugin_name = $rtwwpcp_plugin_name;
		$this->rtwwpcp_version = $rtwwpcp_version;
		$this->rtwwpcp_pdf_url = '';
		add_shortcode( 'rtwwpcp_catalog_shortcode', array( $this, 'rtwwpcp_add_shortcode_for_catalog' ) );
	}
	/**
	 * Register the stylesheets for the public area.
	 *
	 * @since    1.0.0
	 */
	public function rtwwpcp_enqueue_styles() {
		/**
		 * This function is provided for demonstration purposes only.
		 *
		 * An instance of this class should be passed to the rtwwpcp_run() function
		 * defined in Woocommerce_Pdf_Catalog_Pro_Loader as all of the hooks are defined
		 * in that particular class.
		 *
		 * The Woocommerce_Pdf_Catalog_Pro_Loader will then create the relationship
		 * between the defined hooks and the functions defined in this
		 * class.
		 */
		wp_enqueue_style( $this->rtwwpcp_plugin_name, plugin_dir_url( __FILE__ ) . 'css/rtwwpcp-woocommerce-pdf-catalog-pro-public.css', array(), $this->rtwwpcp_version, 'all' );
	}
	/**
	 * Register the JavaScript for the public area.
	 *
	 * @since    1.0.0
	 */
	public function rtwwpcp_enqueue_scripts() {
		/**
		 * This function is provided for demonstration purposes only.
		 *
		 * An instance of this class should be passed to the rtwwpcp_run() function
		 * defined in Woocommerce_Pdf_Catalog_Pro_Loader as all of the hooks are defined
		 * in that particular class.
		 *
		 * The Woocommerce_Pdf_Catalog_Pro_Loader will then create the relationship
		 * between the defined hooks and the functions defined in this
		 * class.
		 */
		wp_enqueue_script( $this->rtwwpcp_plugin_name, plugin_dir_url( __FILE__ ) . 'js/rtwwpcp-woocommerce-pdf-catalog-pro-public.js', array( 'jquery' ), $this->rtwwpcp_version, false );
	}
	/**
	 * callback function for PDF catalog shortcode button.
	 *
	 * @since    1.0.0
	 */
	public function rtwwpcp_generate_pdf_catalog()
	{
		$rtwwpcp_format_stng = get_option('rtwwpcp_format_setting_opt');
		$rtwwpcp_get_setting = get_option('rtwwpcp_basic_setting_opt');
		if ( isset($_GET['rtwwpcp_generate_catalog']) && $_GET['rtwwpcp_generate_catalog'] == 'true' ) 
		{
			if ( isset($rtwwpcp_get_setting['include_instock_product']) && $rtwwpcp_get_setting['include_instock_product'] == '1') 
			{
				$args = array(
				    'post_type' => 'product',
				    'status' => 'publish',
				    'visibility' => 'visible',
				    'posts_per_page' => -1,
				    'meta_query' => array(
				    	array(
					        'key' => '_stock_status',
					        'value' => 'instock',
				        ),
				    )
				);
			}
			else
			{
				$args = array(
				    'post_type' => 'product',
				    'status' => 'publish',
				    'visibility' => 'visible',
				    'posts_per_page' => -1
				);
			}
			$rtwwpcp_pdf_name = 'Catalog';
		}
		else if ( isset($_GET['rtwwpcp_generate_cat_catalog']) && $_GET['rtwwpcp_generate_cat_catalog'] == true ) 
		{
			if(isset($_GET['sub_cat']) && $_GET['sub_cat'] != '' )
			{
				$args = array(
				    'posts_per_page' => -1,
				    'product_cat' => $_GET['sub_cat'],
				    'post_type' => 'product',
				    'visibility' => 'visible',
				    'orderby' => 'title',
				);
				$rtwwpcp_pdf_name = 'Category-catalog';
			}
			else
			{
				if ( isset($rtwwpcp_get_setting['include_instock_product']) && $rtwwpcp_get_setting['include_instock_product'] == '1' ) 
				{
					if ( isset($_GET['cat']) && $_GET['cat'] != '' ) {
						$args = array(
						    'posts_per_page' => -1,
						    'product_cat' => $_GET['cat'],
						    'post_type' => 'product',
						    'visibility' => 'visible',
						    'orderby' => 'title',
						    'meta_query' => array(
						    	array(
							        'key' => '_stock_status',
							        'value' => 'instock',
						        ),
						    )
						);
					}else{
						$args = array(
						    'posts_per_page' => -1,
						    'product_cat' => implode( ',', $rtwwpcp_get_setting['product_catgry']),
						    'post_type' => 'product',
						    'visibility' => 'visible',
						    'orderby' => 'title',
						    'meta_query' => array(
						    	array(
							        'key' => '_stock_status',
							        'value' => 'instock',
						        ),
						    )
						);
					}
				}
				else
				{
					if ( isset($_GET['cat']) && $_GET['cat'] != '' ) {
						$args = array(
						    'posts_per_page' => -1,
						    'product_cat' => $_GET['cat'],
						    'post_type' => 'product',
						    'visibility' => 'visible',
						    'orderby' => 'title',
						);
					}else{
						$args = array(
						    'posts_per_page' => -1,
						    'product_cat' => implode( ',', $rtwwpcp_get_setting['product_catgry']),
						    'post_type' => 'product',
						    'visibility' => 'visible',
						    'orderby' => 'title',
						);
					}
				}
			}
			$rtwwpcp_pdf_name = 'Category-catalog';
		}
		$the_query = new WP_Query( $args );
		$wp_query = $the_query->posts;
		$rtwwpcp_dir = RTWWPCP_PDF_DIR.$rtwwpcp_pdf_name.'.pdf';
		$rtwwpcp_url = RTWWPCP_PDF_URL.$rtwwpcp_pdf_name.'.pdf';
		if ( file_exists($rtwwpcp_dir) ) {
			header('Content-Type: application/octet-stream');
			header("Content-Transfer-Encoding: Binary"); 
			header("Content-disposition: attachment; filename=\"".$rtwwpcp_pdf_name."\"");
			readfile( $rtwwpcp_dir );
			exit;
		}
		$rtwwpcp_catalog_html_array = array();
		if(isset($rtwwpcp_format_stng['pdf_format']))
		{
			if ($rtwwpcp_format_stng['pdf_format'] == 1 ) 
			{
				$rtwwpcp_pdf_format = $rtwwpcp_format_stng['pdf_format_1'];
			}
			else if( $rtwwpcp_format_stng['pdf_format'] == 2 )
			{
				$rtwwpcp_pdf_format = $rtwwpcp_format_stng['pdf_format_2'];
			}
			else if( $rtwwpcp_format_stng['pdf_format'] == 3 )
			{
				$rtwwpcp_pdf_format = $rtwwpcp_format_stng['pdf_format_3'];
			}
			else
			{
				$rtwwpcp_pdf_format = $rtwwpcp_format_stng['pdf_format_4'];
			}
		}
		else
		{
			$rtwwpcp_pdf_format = get_option( 'default_catalog_format', array());
		}
		if (! class_exists ( 'simple_html_dom_node' )) 
		{
			require_once (RTWWPCP_DIR .'/includes/simplehtmldom/simple_html_dom.php');
		}
		if ( $rtwwpcp_format_stng['pdf_format'] == 3 ) 
		{
			$rtwwpcp_final_str = '';
			$rtwwpcp_data = array();
			foreach ($wp_query as $k => $val) 
			{
				$rtwwpcp_product_obj = '';
				$rtwwpcp_product_obj = wc_get_product( $val->ID );
				if(is_object($rtwwpcp_product_obj))
				{
					$product_name  = $rtwwpcp_product_obj->get_name();
					$product_price  = wc_price( $rtwwpcp_product_obj->get_regular_price() );
					$product_img = wp_get_attachment_image_src( get_post_thumbnail_id( $rtwwpcp_product_obj->get_id() ), 'single-post-thumbnail' );
				    $add_to_cart  = add_query_arg('add-to-cart', $rtwwpcp_product_obj->get_id(), wc_get_cart_url()) ;

				    $rtwwpcp_pdf_format = htmlspecialchars_decode ( htmlentities ( $rtwwpcp_pdf_format, ENT_NOQUOTES, 'UTF-8', false ), ENT_NOQUOTES );
					$rtwwpcp_str = '';
					$rtwwpcp_dom = new simple_html_dom ();
					$rtwwpcp_dom->load ( trim($rtwwpcp_pdf_format) );
					foreach ($rtwwpcp_dom->find('#rtwwpcp_relat_prod') as $val) 
					{
						$rtwwpcp_str = $val->outertext;
					}
					$rtwwpcp_final_str .= '
					<div style="float: left; border: 1px solid gray; border-radius: 5px;margin-left:10px;margin-bottom:10px; width:23.5%; height:auto;">
						<div style="width: 100%; height: 250px;">
							<img class="alignnone size-medium wp-image-51" style="width:100%; height:100%;" src="'.$product_img[0].'" alt="" />
						</div>
						<div style="padding: 5px; width:100%;margin-top: -40px;margin-bottom:20px;">
							<span style="width:70%;  font-size:12px;">'.$product_name.'</span>
							<div style="font-size:12px; float:left;width:27%;margin-left:70%;margin-top:-10%">'.$product_price.'</div>
						</div>';
					if ( !isset($rtwwpcp_get_setting['hide_add_to_cart_button']) ) 
					{
						$rtwwpcp_final_str .= '
						<div id="add_to_cart_btn" style="width:46%;margin-left:25%;padding:5px;background-color:#0a2239;; border-radius:5px;margin-bottom:10px;">
							<a style="text-decoration: none;color: white; font-size: 14px;border-radius: 5px; border: none; text-transform: capitalize; font-weight: 600; font-family: sans-serif;" href="'.$add_to_cart.'">Add to cart</a>
						</div>';
					}
					$rtwwpcp_final_str .= '</div>';
				};
			}
			$rtwwpcp_dom = new simple_html_dom ();
			$rtwwpcp_dom->load ( $rtwwpcp_pdf_format );
			foreach ($rtwwpcp_dom->find('#rtwwpcp_relat_prod') as $val) 
			{
				$val->outertext = trim($rtwwpcp_final_str);
			}
			$rtwwpcp_pdf_format = $rtwwpcp_dom->save();
			$rtwwpcp_catalog_data = rtwwpcp_convert_in_pdf( $rtwwpcp_pdf_format,'Catalog');
			$rtwwpcp_catalog_name 	= $rtwwpcp_pdf_name.'.pdf';
			$rtwwpcp_catalog_url 	= $rtwwpcp_catalog_data['dir_path'];
			header('Content-Type: application/octet-stream');
			header("Content-Transfer-Encoding: Binary"); 
			header("Content-disposition: attachment; filename=\"".$rtwwpcp_catalog_name."\"");
			readfile( $rtwwpcp_catalog_url );
			exit;
		}
		if ( $rtwwpcp_format_stng['pdf_format'] == 4 )
		{
			$rtwwpcp_final_str = '';
			$rtwwpcp_data = array();
			foreach ($wp_query as $k => $val) 
			{
				$rtwwpcp_category = array();
				$rtwwpcp_attr_data = array();
				$rtwwpcp_categry_str = '';
				$rtwwpcp_attributes_str = '';
				$rtwwpcp_product_obj = wc_get_product( $val->ID );
				$attr = $rtwwpcp_product_obj->get_attributes();
				if (!empty($attr)) {
					$product_attribute_slugs = array_keys($attr);
					foreach ($attr as $key => $value) {
						if ( strpos($value->get_name(), 'pa_') !== false ) {
							$strng = str_replace('pa_', '', $value->get_name());
						}
						else{
							$strng = $value->get_name();
						}
			            $rtwwpcp_attr_data[$strng] = $value->get_options($value->get_name());
					} 
				}
				$product_name  = $rtwwpcp_product_obj->get_name();
				$product_price  = wc_price( $rtwwpcp_product_obj->get_regular_price() );
				$product_img = wp_get_attachment_image_src( get_post_thumbnail_id( $rtwwpcp_product_obj->get_id() ), 'single-post-thumbnail' );
				$add_to_cart  = add_query_arg('add-to-cart', $rtwwpcp_product_obj->get_id(), wc_get_cart_url()) ;
				$rtwwpcp_product_sku = $rtwwpcp_product_obj->get_sku();
				$rtwwpcp_product_short_desc  = $rtwwpcp_product_obj->get_short_description();
				$rtwwpcp_cat = $rtwwpcp_product_obj->get_category_ids();
				foreach ($rtwwpcp_cat as $cat_key => $cat_val) {
					$rtwwpcp_category[]  = get_term_by( 'id', $cat_val, 'product_cat' )->name;
				}
				if ( $rtwwpcp_product_obj ) 
				{
					$rtwwpcp_pdf_format = htmlspecialchars_decode ( htmlentities ( $rtwwpcp_pdf_format, ENT_NOQUOTES, 'UTF-8', false ), ENT_NOQUOTES );
					$rtwwpcp_str = '';
					$rtwwpcp_str_2 = '';
					$rtwwpcp_dom = new simple_html_dom ();
					$rtwwpcp_dom->load ( trim($rtwwpcp_pdf_format ));
					foreach ($rtwwpcp_dom->find('#rtwwpcp_prod_table tbody') as $val) 
					{
						$rtwwpcp_str = $val->outertext;
					}
					$rtwwpcp_final_str .= '
					<tr>
						<td style="border-left: 1px solid #ddd; border-right: 1px solid #ddd; border-bottom: 1px solid #ddd; padding: 8px 10px;"><img style="width: 100px; height: 100px;" src="'.$product_img[0].'" /></td>
						<td style="border-right: 1px solid #ddd; border-bottom: 1px solid #ddd; padding: 8px 10px;">'.$product_name.'</td>
						<td style="border-right: 1px solid #ddd; border-bottom: 1px solid #ddd; padding: 8px 10px;">'.$rtwwpcp_product_sku.'</td>
						<td style="text-align: center; border-right: 1px solid #ddd; border-bottom: 1px solid #ddd;">'.$rtwwpcp_product_short_desc.'</td>
						<td style="border-right: 1px solid #ddd; border-bottom: 1px solid #ddd; padding: 8px 10px;">
							<table id="rtwwpcp_prod_cat">
								<tbody>
									<tr>
										<td style="background-color: #656dff; color: white; padding: 5px;">[product_category]</td>
									</tr>
								</tbody>
							</table>
						</td>
						<td id="rtwwpcp_prod_attr" style="border-right: 1px solid #ddd; border-bottom: 1px solid #ddd; padding: 8px 10px;">
							<div><b>Size:</b><span>S,M,L,XL,XXL</span></div>
						</td>
						<td style="border-right: 1px solid #ddd; border-bottom: 1px solid #ddd; padding: 8px 10px;">'.$product_price.'</td>
						<td style="border-right: 1px solid #ddd; border-bottom: 1px solid #ddd; padding: 8px 10px;">
							<table>
								<tbody>
									<tr>
										<td style="width: 150px; background-color: #ff7c52; padding: 10px 8px; text-align: center; font-size: 16px;"><a style="color: white; text-decoration: none; text-align: center; font-size: 16px;" href="'.$add_to_cart.'"><b>Add to cart</b></a></td>
									</tr>
								</tbody>
							</table>
						</td>
					</tr>';
					$rtwwpcp_final_str = htmlspecialchars_decode ( htmlentities ( $rtwwpcp_final_str, ENT_NOQUOTES, 'UTF-8', false ), ENT_NOQUOTES );
					$rtwwpcp_str_2 = '';
					$rtwwpcp_str_3 = '';
					$rtwwpcp_dom = new simple_html_dom ();
					$rtwwpcp_dom->load ( trim($rtwwpcp_final_str ));
					foreach ($rtwwpcp_dom->find('#rtwwpcp_prod_cat') as $vals) 
					{
						$rtwwpcp_str_2 = $vals->outertext;
					}
					foreach ($rtwwpcp_dom->find('#rtwwpcp_prod_attr div') as $v) 
					{
						$rtwwpcp_str_3 = $v->outertext;
					}
					foreach ($rtwwpcp_attr_data as $attr_k => $attr_val) 
					{
						if ( is_array($attr_val) ) 
						{
							$attr_str_array = array();
							$attr_str = '';
							foreach ($attr_val as $ke => $vals) 
							{
								if ( get_term($vals)->name ) 
								{
									array_push($attr_str_array, get_term($vals)->name);
								}
							}
							$attr_str = implode(',',$attr_str_array);
							$rtwwpcp_attributes_str .= '<div><b>'.$attr_k.' :</b><span>'.$attr_str.'</span></div>';
						}
						else
						{
							$rtwwpcp_attributes_str .= '<div><b>'.$attr_k.' :</b><span>'.get_term( $attr_val[0])->name.'</span></div>';
						}
					}
					$rtwwpcp_dom = new simple_html_dom ();
					$rtwwpcp_dom->load ( trim($rtwwpcp_final_str ));
					foreach ($rtwwpcp_dom->find('#rtwwpcp_prod_attr div') as $val) 
					{
						$val->outertext = trim($rtwwpcp_attributes_str);
					}
					$rtwwpcp_final_str = $rtwwpcp_dom->save();
					$rtwwpcp_categry_str = '<table>';
					$rtwwpcp_categry_str .= '<tbody>';
					$rtwwpcp_categry_str .= '<tr>';
					foreach ($rtwwpcp_category as $cat_key => $cat_val) 
					{
						if ( is_array($cat_val )) 
						{
							foreach ($cat_val as $k => $v) 
							{
								$cat_str = implode(',',$v);
							}
							$rtwwpcp_categry_str .= '<td style="background-color:#656dff; color:white; padding:2px;">'.$cat_str.'</td>';
						}
						else
						{
							$rtwwpcp_categry_str .= '<td style="background-color:#656dff; color:white; padding:2px;">'.$cat_val.'</td>';
						}
					}
					$rtwwpcp_categry_str .= '</tr>';
					$rtwwpcp_categry_str .= '</tbody>';
					$rtwwpcp_categry_str .= '</table>';
					$rtwwpcp_dom = new simple_html_dom ();
					$rtwwpcp_dom->load ( trim($rtwwpcp_final_str ));
					foreach ($rtwwpcp_dom->find('#rtwwpcp_prod_cat') as $val) 
					{
						$val->outertext = trim($rtwwpcp_categry_str);
					}
					$rtwwpcp_final_str = $rtwwpcp_dom->save();
				}
			}
			//end of foreach.
			$rtwwpcp_dom = new simple_html_dom ();
			$rtwwpcp_dom->load ( $rtwwpcp_pdf_format );
			foreach ($rtwwpcp_dom->find('#rtwwpcp_prod_table tbody') as $val) 
			{
				$val->outertext = trim($rtwwpcp_final_str);
			}
			$rtwwpcp_pdf_format = $rtwwpcp_dom->save();
			//End HTML DOM
			$rtwwpcp_catalog_data = rtwwpcp_convert_in_pdf( $rtwwpcp_pdf_format,'Catalog');
			$rtwwpcp_catalog_name 	= $rtwwpcp_pdf_name.'.pdf';
			$rtwwpcp_catalog_url 	= $rtwwpcp_catalog_data['dir_path'];
			header('Content-Type: application/octet-stream');
			header("Content-Transfer-Encoding: Binary"); 
			header("Content-disposition: attachment; filename=\"".$rtwwpcp_catalog_name."\"");
			readfile( $rtwwpcp_catalog_url );
			exit;
		}
		else
		{
			foreach ($wp_query as $key => $val) 
			{
				$rtwwpcp_attr_data = array();
				$rtwwpcp_color = array();
				$rtwwpcp_relate_img = array();
				$rtwwpcp_atchmnt_id = array();
				$rtwwpcp_catlog_format = '';
				$rtwwpcp_catlog_format = $rtwwpcp_pdf_format;
				$rtwwpcp_data = array();
				$rtwwpcp_product_obj = wc_get_product( $val->ID );
				$rtwwpcp_data['product_id']  = $rtwwpcp_product_obj->get_id();
				$attchmnt_id = $rtwwpcp_product_obj->get_gallery_image_ids();
				foreach ($attchmnt_id as $key => $value) {
					array_push($rtwwpcp_atchmnt_id, wp_get_attachment_url( $value ));
				}
				$rtwwpcp_data['product_name']  = $rtwwpcp_product_obj->get_name();
				$attr = $rtwwpcp_product_obj->get_attributes();
				if (!empty($attr)) {
					$product_attribute_slugs = array_keys($attr);
					foreach ($attr as $key => $value) {
						if ( strpos($value->get_name(), 'pa_') !== false ) {
							$strng = str_replace('pa_', '', $value->get_name());
						}
						else{
							$strng = $value->get_name();
						}
			            $rtwwpcp_attr_data[$strng] = $value->get_options($value->get_name());
					} 
				}
				$rtwwpcp_data['related_products'] = wc_get_related_products( $rtwwpcp_product_obj->get_id(), 4 );
				$cnt = 1;
				foreach ($rtwwpcp_data['related_products'] as $relat_key => $relat_val) {
					$rtwwpcp_relate_img[(wc_get_product( $relat_val ))->get_name()] = wp_get_attachment_image_src( get_post_thumbnail_id( $relat_val ), 'single-post-thumbnail' );
					$rtwwpcp_data['add_to_cart_'.$cnt] =  add_query_arg('add-to-cart', $relat_val, wc_get_cart_url()) ;
					$cnt++;
				}
				$count = 1;
				foreach ($rtwwpcp_relate_img as $relat_k => $relate_v) {
					$rtwwpcp_data['relate_img_'.$count]  = $relate_v[0];
					$rtwwpcp_data['relate_prod_'.$count]  = $relat_k;
					$count++;
				}
				$image = wp_get_attachment_image_src( get_post_thumbnail_id( $rtwwpcp_product_obj->get_id() ), 'single-post-thumbnail' );
				$rtwwpcp_data['add_to_cart']  = add_query_arg('add-to-cart', $rtwwpcp_product_obj->get_id(), wc_get_cart_url()) ;
				$rtwwpcp_data['thumb_img_1']  = isset($image[0])?$image[0]:'';
				if (!empty($rtwwpcp_atchmnt_id))
				{
					$rtwwpcp_data['thumb_img_2']  = isset($rtwwpcp_atchmnt_id[0])?$rtwwpcp_atchmnt_id[0]:'';
					$rtwwpcp_data['thumb_img_3']  = isset($rtwwpcp_atchmnt_id[1])?$rtwwpcp_atchmnt_id[1]:'';
					$rtwwpcp_data['thumb_img_4']  = isset($rtwwpcp_atchmnt_id[2])?$rtwwpcp_atchmnt_id[2]:'';
				}
				$rtwwpcp_data['product_slug']  = $rtwwpcp_product_obj->get_slug();
				$rtwwpcp_data['product_type']  = $rtwwpcp_product_obj->get_type();
				if ( $rtwwpcp_pdf_format == 2 ) 
				{
					if ( $rtwwpcp_product_obj->is_on_sale() ) 
					{
						if( $rtwwpcp_product_obj->is_type( 'variable' ) ) {
							$available_variations = $rtwwpcp_product_obj->get_available_variations();
							$percent_off = ( ( 100 * ( $available_variations[0]['display_regular_price'] - $available_variations[0]['display_price'] ) ) / $available_variations[0]['display_regular_price'] );
							$percent_off = wc_format_decimal( $percent_off, 2 );
							$rtwwpcp_data['product_price'] = '<td style="font-size:16px;padding-top: 10px;font-weight: bold;color: #212121;">'.wc_price(floor($available_variations[0]['display_price'])).' <del style="font-weight: normal;"> '.wc_price(floor($available_variations[0]['display_regular_price'])).'</del> <span style="color:#FF905A;">( '.$percent_off.'% OFF)</span></td>';
						}else{
							$product_sale_price  = wc_price( $rtwwpcp_product_obj->get_sale_price() );
							$product_regular_price  = wc_price( $rtwwpcp_product_obj->get_regular_price() );
							$percent_off = ( ( 100 * ( $rtwwpcp_product_obj->get_regular_price() - $rtwwpcp_product_obj->get_sale_price() ) ) / $rtwwpcp_product_obj->get_regular_price() );
							$percent_off = wc_format_decimal( $percent_off, 2 );
							$rtwwpcp_data['product_price'] = '<td style="font-size:16px;padding-top: 10px;font-weight: bold;color: #212121;">'.$product_sale_price.' <del style="font-weight: normal;"> '.$product_regular_price.'</del> <span style="color:#FF905A;">( '.$percent_off.'% OFF)</span></td>';
						}
					}
					else
					{
						$rtwwpcp_data['product_price']  = wc_price( $rtwwpcp_product_obj->get_price() );
					}
				}
				else
				{
					$rtwwpcp_data['product_price']  = wc_price( $rtwwpcp_product_obj->get_price() );
				}
				$rtwwpcp_data['product_sku']  = $rtwwpcp_product_obj->get_sku();
				$rtwwpcp_data['permalinks']  = get_permalink( $rtwwpcp_product_obj->get_id() );
				$rtwwpcp_cat = $rtwwpcp_product_obj->get_category_ids();
				foreach ($rtwwpcp_cat as $cat_key => $cat_val) {
					$rtwwpcp_data['product_category'][]  = get_term_by( 'id', $cat_val, 'product_cat' )->name;
				}
			    $rtwwpcp_data['status']  = $rtwwpcp_product_obj->get_status();
				$rtwwpcp_data['product_desc']  = $rtwwpcp_product_obj->get_description();
				$rtwwpcp_data['product_short_desc']  = $rtwwpcp_product_obj->get_short_description();
			    $args = array ('post_type' => 'product', 'post_id' => $val->ID );
				$comments = get_comments( $args );
				$image = wp_get_attachment_image_src( get_post_thumbnail_id( $rtwwpcp_product_obj->get_id() ), 'single-post-thumbnail' );
			    $rtwwpcp_data['product_img'] = $image[0];
			    $rtwwpcp_data['product_rating'] = wc_get_rating_html( $rtwwpcp_product_obj->get_review_count() );
				if( $rtwwpcp_data['product_rating'] == '' )
				{
					$rtwwpcp_data['product_rating'] = 'No Rating Is Available';
				}
				$rtwwpcp_data['product_review'] = array();
				if( !empty( $comments ) && is_array( $comments ) )
				{
					$count = 0;
					foreach ($comments as $key => $value) 
					{
					 	$rtwwpcp_data['product_review'][$count] = $value->comment_content;
					 	$count = ++$count;
					}
				}
				$rtwwpcp_data['avrg_rating'] = $rtwwpcp_product_obj->get_average_rating();
				if ( $rtwwpcp_catlog_format != '' ) 
				{
					foreach ($rtwwpcp_data as $key => $value) 
					{	
						if ( strpos($rtwwpcp_catlog_format, $key)!== false ) 
						{
							if ( $key == 'product_review' ) 
							{
								$strng = '';
								if( is_array($rtwwpcp_data['product_review']) && !empty($rtwwpcp_data['product_review']) )
								{
									$cont = 1;
									foreach ($rtwwpcp_data['product_review'] as $k => $val) 
									{
										$strng .= '<p>'.$cont.' : '.$val.'</p>';
										$cont = ++$cont;
									}
								}
								else
								{
									$strng = 'No Review Available';
								}
							    $rtwwpcp_catlog_format = str_replace('['.$key.']', $strng, $rtwwpcp_catlog_format);
							}
							if ( $key == 'product_category' ) {
								$cat_name = '';
								if ( is_array($rtwwpcp_data['product_category']) && !empty($rtwwpcp_data['product_category'] )) 
								{
									if ( $rtwwpcp_pdf_format == 1 ) 
									{
										$rtwwpcp_catlog_format = htmlspecialchars_decode ( htmlentities ( $rtwwpcp_catlog_format, ENT_NOQUOTES, 'UTF-8', false ), ENT_NOQUOTES );
										$rtwwpcp_catgry_str = '';
										$rtwwpcp_dom = new simple_html_dom ();
										$rtwwpcp_dom->load ( $rtwwpcp_catlog_format );
										foreach ($rtwwpcp_dom->find('#rtwwpcp_cat_list') as $val) 
										{
											$rtwwpcp_catgry_str = $val->outertext;
										}
										$cat_name .= '<tr><td><div style="width: 100%;"><table><tr>';
										foreach ($rtwwpcp_data['product_category'] as $catgry_k => $catgry_val) 
										{
											if ( $catgry_k > 0 ) 
											{
												$cat_name .= '<td style="width: 4px;"></td>';
											}
											$cat_name .= '<td style="width: 90px; text-align: center; padding: 4px; background-color: #009688; border-radius: 2px; color: white;font-size: 12px;">'.$catgry_val.'</td>';
										}
										$cat_name .= '</tr></table></div></td></tr>';
										$rtwwpcp_dom = new simple_html_dom ();
										$rtwwpcp_dom->load ( $rtwwpcp_catlog_format );
										foreach ($rtwwpcp_dom->find('#rtwwpcp_cat_list') as $val) 
										{
											$val->outertext = $cat_name;
										}
										$rtwwpcp_catlog_format = $rtwwpcp_dom->save();
									}
									else
									{
										foreach ($rtwwpcp_data['product_category'] as $cat_k => $cat_value) 
										{
											if ($cat_key == 0) 
											{
												$cat_name .= '<div style="float:left; width: 25%; text-align: center; padding: 4px; background-color: #009688; border-radius: 2px; color: white;font-size: 12px;">'.$cat_value.'</div>';
											}
											else
											{
												$cat_name .= '<div style="float:left; width: 25%; text-align: center; padding: 4px; background-color: #009688; border-radius: 2px; color: white;margin-left: 5px;font-size: 12px;">'.$cat_value.'</div>';
											}
										}
										$rtwwpcp_catlog_format = str_replace('['.$key.']', $cat_name, $rtwwpcp_catlog_format);
									}
								}
							}
							else
							{
								$rtwwpcp_catlog_format = str_replace('['.$key.']', $value, $rtwwpcp_catlog_format);
							}
						}
						else
						{
							$rtwwpcp_catlog_format = str_replace($key, ' ', $rtwwpcp_catlog_format);
						}
					}
					if ( strpos($rtwwpcp_catlog_format, '[variation]')!== false ) 
					{
						$rtwwpcp_catlog_format = htmlspecialchars_decode ( htmlentities ( $rtwwpcp_catlog_format, ENT_NOQUOTES, 'UTF-8', false ), ENT_NOQUOTES );
						$rtwwpcp_string2 = '';
						$rtwwpcp_dom = new simple_html_dom ();
						$rtwwpcp_dom->load ( $rtwwpcp_catlog_format );
						$rtwwpcp_prod_tr = '';
						foreach ($rtwwpcp_dom->find('#rtwwpcp_variation_list') as $val) 
						{
							$rtwwpcp_prod_tr = $val->outertext;
						}
						$attr_final_text = '';
						foreach ($rtwwpcp_attr_data as $key_attr => $value_attr) 
						{ 
							if ( $rtwwpcp_format_stng == 1 ) 
							{
								$attr_final_text .= '<tr style="font-size: 16px; font-weight: bold; margin-top: 25px; color: #000000;">';
								$attr_final_text .= '<td style="font-size: 16px; font-weight: bold; margin-top: 25px; padding-top: 10px; color: #000000;">'.ucfirst($key_attr);
								$attr_final_text .= '</td>';
								$attr_final_text .= '</tr>';
								if ( is_array($value_attr) ) 
								{
									$attr_string  = '';
									$attr_string .= '<tr>';
									$attr_string .= '<td style="padding-top: 10px;">';
									$attr_string .= '<table style="300px;" cellspacing="0" cellpadding="0">';
									$attr_string .= '<tr>';
									foreach ($value_attr as $k_attr => $val_attr) 
									{
										if ( $key_attr == 'color' ) 
										{
											$attr_string .= '<td style="padding-right: 15px; padding-bottom: 15px;"><table style="border-spacing: 0;" cellspacing="0" cellpadding="0"><tr><td style="width: 40px;border: 2px solid #ddd; height: 40px;text-align: center; font-size: 12px; background-color: '.get_term( $val_attr)->slug.';"></td></tr></table></td>'; 
										}
										else if($key_attr == 'Size')
										{
											$val = substr($val_attr, 0,1);
											$attr_string .= '<td style="padding-right: 15px;"><table style="border-spacing: 0;" cellspacing="0" cellpadding="0"><tr><td style="width: 50px;border: 2px solid #2874f0; height: 35px;text-align: center; font-size: 12px; background-color: #efefefe;">'.$val.'</td></tr></table></td>'; 
										}
										else
										{
											$attr_string .= '<td style="padding-right: 15px;"><table style="border-spacing: 0;" cellspacing="0" cellpadding="0"><tr><td style="width: 50px;border: 2px solid #2874f0; height: 35px;text-align: center; font-size: 12px; background-color: #efefefe;">'.get_term( $val_attr)->name.'</td></tr></table></td>'; 
										}
									}
									$attr_string .= '</tr>';
									$attr_string .= '</table>';
									$attr_string .= '</td>';
									$attr_string .= '</tr>';
								}
								$attr_final_text .= $attr_string;
							}
							else
							{
								$attr_final_text .= '<div>';
								$attr_final_text .= '<div style="font-size: 16px;padding-top: 15px; color: #878787;">'.ucfirst($key_attr).'</div>';
								$attr_final_text .= '</div>';
								if (  is_array($value_attr) ) 
								{
									$attr_string = '';
									$attr_string .= '<div style="width: 100%;">';
									foreach ($value_attr as $k_attr => $val_attr) 
									{
										if ( $key_attr == 'color' ) 
										{
											if($k_attr == 0)
											{
												$attr_string .= '<div style="float: left;width:30px; height: 30px;text-align: center; font-size: 14px;border: 1px solid #ddd;background-color: '.get_term( $val_attr)->slug.';">
													</div>';
											}
											else
											{
												$attr_string .= '<div style="float: left; margin-left: 10px;width:30px; height: 30px;text-align: center; font-size: 14px;border: 1px solid #ddd;background-color: '.get_term( $val_attr)->slug.';">
													</div>';
											}
										}
										else if ( $key_attr == 'Size' ) 
										{
											$val = substr($val_attr, 0,1);
											$attr_string .= '<div style="float: left; padding-right: 10px;width:55px;"><div style="border: 2px solid #2874f0; border-style: dotted;width: 45px; height: 27px;text-align: center; font-size: 14px;line-height: 27px;">'.$val.'</div></div>';
										}
										else
										{
											$attr_string .= '<div style="float: left; padding-right: 10px;width:55px;"><div style="border: 2px solid #2874f0;border-style: dotted;width: 50px; height: 27px;text-align: center; font-size: 14px;line-height: 27px;">'.get_term( $val_attr)->name.'</div></div>';
										}
									}
									$attr_string .= '</div>';	
								}
								$attr_final_text .= $attr_string;
							}
						} 
					}
					$rtwwpcp_dom = new simple_html_dom ();
					$rtwwpcp_dom->load ( $rtwwpcp_catlog_format );
					foreach ($rtwwpcp_dom->find('#rtwwpcp_variation_list') as $val) 
					{
						$val->outertext = $attr_final_text;
					}
					$rtwwpcp_catlog_format = $rtwwpcp_dom->save();
					if ( empty($rtwwpcp_relate_img) ) 
					{
						$rtwwpcp_catlog_format = htmlspecialchars_decode ( htmlentities ( $rtwwpcp_catlog_format, ENT_NOQUOTES, 'UTF-8', false ), ENT_NOQUOTES );
						$rtwwpcp_string2 = '';
						$rtwwpcp_string = '';
						$rtwwpcp_dom = new simple_html_dom ();
						$rtwwpcp_dom->load ( $rtwwpcp_catlog_format );
						$rtwwpcp_relat_prod = '';
						foreach ($rtwwpcp_dom->find('#rtwwpcp_relat_prod tbody') as $val) 
						{
							$rtwwpcp_string2 = $val->outertext;
						}
						foreach ($rtwwpcp_dom->find('#rtwwpcp_similar_prod td') as $val) 
						{
							$rtwwpcp_string = $val->outertext;
						}
						$rtwwpcp_dom = new simple_html_dom ();
						$rtwwpcp_dom->load ( $rtwwpcp_catlog_format );
						foreach ($rtwwpcp_dom->find('#rtwwpcp_relat_prod tbody') as $val) 
						{
							$val->outertext ='';
						}
						foreach ($rtwwpcp_dom->find('#rtwwpcp_similar_prod td') as $val) 
						{
							$val->outertext ='';
						}
						$rtwwpcp_catlog_format = $rtwwpcp_dom->save();
					}



					$rtwwpcp_catlog_format = htmlspecialchars_decode ( htmlentities ( $rtwwpcp_catlog_format, ENT_NOQUOTES, 'UTF-8', false ), ENT_NOQUOTES );
					$img_string2 = '';
					$img_string = '';
					$rtwwpcp_dom = new simple_html_dom ();
					$rtwwpcp_dom->load ( $rtwwpcp_catlog_format );
					$relate_img = '';
					foreach ($rtwwpcp_dom->find('#rtwwcpcp_img img') as $val) 
					{
						$img_string2 = $val->getAttribute('src');
						if ( $img_string2 == '' ) 
						{
							$val->outertext ='';
						}
					}
					$rtwwpcp_catlog_format = $rtwwpcp_dom->save();
					$rtwwpcp_catlog_format = htmlspecialchars_decode ( htmlentities ( $rtwwpcp_catlog_format, ENT_NOQUOTES, 'UTF-8', false ), ENT_NOQUOTES );
					$img_str = '';
					$str = '';
					$rtwwpcp_dom = new simple_html_dom ();
					$rtwwpcp_dom->load ( $rtwwpcp_catlog_format );
					foreach ($rtwwpcp_dom->find('#rtwwpcp_relat_prod tbody tr img') as $val) 
					{
						$img_str = $val->getAttribute('src');
						if ( strpos($img_str, 'img') || $img_str == '' ) 
						{
							$val->outertext ='';
						}
					}
					if ( isset($rtwwpcp_get_setting['hide_add_to_cart_button']) && $rtwwpcp_get_setting['hide_add_to_cart_button'] == '1') 
					{
						foreach( $rtwwpcp_dom->find('#add_to_cart_btn') as $val )
						{
							$val->outertext ='';
						}
					}
					
					foreach ($rtwwpcp_dom->find('#rtwwpcp_relat_prod tr[id=rtwwpcp_relat_prod_tr]') as $val) 
					{
						$str = $val->outertext;
						if ( strpos($str, 'prod') ) 
						{
							$val->outertext ='';
						}
					}
					$rtwwpcp_catlog_format = $rtwwpcp_dom->save();
					if ( strpos($rtwwpcp_catlog_format, '[add_to_cart') ) 
					{
						$rtwwpcp_catlog_format = str_replace('<td id="rtwwpcp_add_to_cart" style="font-size: 16px; font-weight: normal; background-color: #d93c50; height: 30px;"><a style="color: #ffffff; text-decoration: none;" href="[add_to_cart_2]">Buy Now</a></td>', '', $rtwwpcp_catlog_format);
						$rtwwpcp_catlog_format = str_replace('<td id="rtwwpcp_add_to_cart" style="font-size: 16px; font-weight: normal; background-color: #d93c50; height: 30px;"><a style="color: #ffffff; text-decoration: none;" href="[add_to_cart_3]">Buy Now</a></td>', '', $rtwwpcp_catlog_format);
						$rtwwpcp_catlog_format = str_replace('<td id="rtwwpcp_add_to_cart" style="font-size: 16px; font-weight: normal; background-color: #d93c50; height: 30px;"><a style="color: #ffffff; text-decoration: none;" href="[add_to_cart_4]">Buy Now</a></td>', '', $rtwwpcp_catlog_format);
					}



					$rtwwpcp_catlog_format = htmlspecialchars_decode ( htmlentities ( $rtwwpcp_catlog_format, ENT_NOQUOTES, 'UTF-8', false ), ENT_NOQUOTES );
					$img_string2 = '';
					$img_string = '';
					$rtwwpcp_dom = new simple_html_dom ();
					$rtwwpcp_dom->load ( $rtwwpcp_catlog_format );
					$relate_img = '';
					foreach ($rtwwpcp_dom->find('#rtwwcpcp_img img') as $val) 
					{
						$img_string2 = $val->getAttribute('src');
						if ( $img_string2 == '' ) {
							$val->outertext ='';
						}
						if ( strpos($img_string2, 'thumb_') !== false ) {
							$val->outertext ='';
						}
					}
					$rtwwpcp_catlog_format = $rtwwpcp_dom->save();
				}
				array_push($rtwwpcp_catalog_html_array, $rtwwpcp_catlog_format);
			}
			if ( isset($rtwwpcp_get_setting['cvr_img_url']) && $rtwwpcp_get_setting['cvr_img_url'] != '' ) 
			{
				$rtwwpcp_catalg_cover_img = '<img src='.$rtwwpcp_get_setting['cvr_img_url'].'>';
				array_unshift($rtwwpcp_catalog_html_array, $rtwwpcp_catalg_cover_img );
			}
			if ( isset($rtwwpcp_get_setting['bck_cvr_img_url']) && $rtwwpcp_get_setting['bck_cvr_img_url'] != '' ) 
			{
				$rtwwpcp_catalg_back_img = '<img src='.$rtwwpcp_get_setting['bck_cvr_img_url'].'>';
				array_push( $rtwwpcp_catalog_html_array, $rtwwpcp_catalg_back_img );
			}
			$rtwwpcp_catalog_data = rtwwpcp_convert_in_pdf( $rtwwpcp_catalog_html_array,'Catalog');
			$this->rtwwpcp_version = $rtwwpcp_catalog_data['file_url'];
			$rtwwpcp_catalog_name 	= $rtwwpcp_pdf_name.'.pdf';
			$rtwwpcp_catalog_url 	= $rtwwpcp_catalog_data['dir_path'];
			header('Content-Type: application/octet-stream');
			header("Content-Transfer-Encoding: Binary"); 
			header("Content-disposition: attachment; filename=\"".$rtwwpcp_catalog_name."\"");
			readfile( $rtwwpcp_catalog_url );
			exit;
		}
	}
	/**
	 * function for generate button html for catalog for pdf cataog .
	 *
	 * @since    1.0.0
	 */
	public function rtwwpcp_add_shortcode_for_catalog()
	{
		$user_role = get_option( 'rtwwpcp_basic_setting_opt', array() );

		if (!isset($user_role['enbl_ctgry_catlog']) && isset($user_role['enabl_catalog']) && !empty($user_role['enabl_catalog']) ) 
		{
			$catalog_button = '';
			$curr_user = wp_get_current_user();
			if ( isset($user_role['user_roles']) && !empty($user_role['user_roles'])) {
				if ( in_array( $curr_user->roles[0] , $user_role['user_roles'] ) || $user_role['user_roles'][0] == 'all_users') {
					global $wp;
					if ( isset($user_role['catalog_btn_txt']) && $user_role['catalog_btn_txt'] != '' ) {
						$catlog_btn = $user_role['catalog_btn_txt'];
					}else{
						$catlog_btn = "Download PDF Catalog";
					}
					$catalog_button = "<div class='rtw-flipbook-form-wrapper'>";
					$catalog_button .= '<a class="rtw-button" href="'.esc_url ( add_query_arg ( 'rtwwpcp_generate_catalog', 'true', home_url( $wp->request ) ) ).'">'.$catlog_btn.'</a>';
					$catalog_button .= "</div>";
					return $catalog_button;
				}
			}else{
				global $wp;
				if ( isset($user_role['catalog_btn_txt']) && $user_role['catalog_btn_txt'] != '' ) {
					$catlog_btn = $user_role['catalog_btn_txt'];
				}else{
					$catlog_btn = "Download PDF Catalog";
				}
				$catalog_button = "<div class='rtw-flipbook-form-wrapper'>";
				$catalog_button .= '<a class="rtw-button" href="'.esc_url ( add_query_arg ( 'rtwwpcp_generate_catalog', 'true', home_url( $wp->request ) ) ).'">'.$catlog_btn.'</a>';
				$catalog_button .= "</div>";
				return $catalog_button;
			}
		}
	}
	public function rtwwpcp_add_shortcode_for_flipbook()
	{
		$flpbook_button = "<div class='rtw-flipbook-form-wrapper'>";
		$flpbook_button .= '<a class="rtw-button" href="#">Coming Soon</a>';
		$flpbook_button .= "</div>";
		return $flpbook_button;
	}
	/**
	 * Generate the button shortcode for flipbook & single product pdf download.
	 *
	 * @since    1.0.0
	 */
	public function rtwwpcp_genrate_shrtcode_function()
	{
		if ( is_product() ) 
		{
			add_shortcode( 'rtwwpcp_product_shortcode', array( $this, 'rtwwpcp_add_shortcode_for_singlr_product' ) );
		}
		add_shortcode( 'rtwwpcp_flipbook_shortcode', array( $this, 'rtwwpcp_add_shortcode_for_flipbook' ) );
	}
	/**
	 *  function for generate button html for download single product pdf. 
	 *
	 * @since    1.0.0
	 */
	public function rtwwpcp_add_shortcode_for_singlr_product()
	{
		$prnt_product_button = '';
		$user_role = get_option( 'rtwwpcp_basic_setting_opt', array() );
		if ( isset($user_role['enabl_sngl_prdct_pdf']) && $user_role['enabl_sngl_prdct_pdf'] != '' ) 
		{
			$curr_user = wp_get_current_user();
			global $wp;
			global $product;
			if ( isset($user_role['user_roles']) && $user_role['user_roles'] != '' ) {
				if ( in_array( $curr_user->roles[0] , $user_role['user_roles'] ) || $user_role['user_roles'][0] == 'all_users' ) 
				{
					if ( is_product() ) 
					{
						$rtwwpcp_prod_id = $product->get_id();
						$rtwwpcp_get_setting = get_option('rtwwpcp_basic_setting_opt');
						if ( isset($rtwwpcp_get_setting['prodct_pdf_btn_txt']) && $rtwwpcp_get_setting['prodct_pdf_btn_txt'] != '' ) {
							$prnt_prodct_btn = $rtwwpcp_get_setting['prodct_pdf_btn_txt'];
						}else{
							$prnt_prodct_btn = "Download Product PDF";
						}
						$prnt_product_button = "<div class='rtw-flipbook-form-wrapper'>";
						$prnt_product_button .= '<a class="rtw-button" href="'.esc_url ( add_query_arg ( 'rtwwpcp_generate_sngl_pdf', $rtwwpcp_prod_id, home_url( $wp->request ) ) ).'">'.$prnt_prodct_btn.'</a>';
						$prnt_product_button .= "</div>";
						return $prnt_product_button;
					}	
				}
			}else{
				if ( is_product() ) 
				{
					$rtwwpcp_prod_id = $product->get_id();
					$rtwwpcp_get_setting = get_option('rtwwpcp_basic_setting_opt');
					if ( isset($rtwwpcp_get_setting['prodct_pdf_btn_txt']) && $rtwwpcp_get_setting['prodct_pdf_btn_txt'] != '' ) {
						$prnt_prodct_btn = $rtwwpcp_get_setting['prodct_pdf_btn_txt'];
					}else{
						$prnt_prodct_btn = "Download Product PDF";
					}
					$prnt_product_button = "<div class='rtw-flipbook-form-wrapper'>";
					$prnt_product_button .= '<a class="rtw-button" href="'.esc_url ( add_query_arg ( 'rtwwpcp_generate_sngl_pdf', $rtwwpcp_prod_id, home_url( $wp->request ) ) ).'">'.$prnt_prodct_btn.'</a>';
					$prnt_product_button .= "</div>";
					return $prnt_product_button;
				}	
			}
		}
	}
	/**
	 *  function for generate pdf for single product. 
	 *
	 * @since    1.0.0
	 */
	public function rtwwpcp_prnt_sngl_prdct_pdf()
	{
		if ( isset($_GET['rtwwpcp_generate_sngl_pdf']) && !empty($_GET['rtwwpcp_generate_sngl_pdf']) ) 
		{
			$single_product = rtwwpcp_creat_sngl_prdct_pdf($_GET['rtwwpcp_generate_sngl_pdf']);
		}
	}
	/**
	 *  function for show catalog button on shop page. 
	 *
	 * @since    1.0.0
	 */
	public function rtwwpcp_show_catalog_btn_on_shop_page()
	{
		echo $this->rtwwpcp_add_shortcode_for_catalog();
	}
	/**
	 *  function for show product pdf button on product page. 
	 *
	 * @since    1.0.0
	 */
	public function rtwwpcp_show_prodct_btn()
	{
		echo $this->rtwwpcp_add_shortcode_for_singlr_product();
	}
	/**
	 *  function for show pdf catalog button on product category archive page. 
	 *
	 * @since    2.1.0
	 */
	public function rtwwpcp_show_btn_on_categry_page()
	{
		if (is_product_category()) 
		{
			global $wp;
			global $wp_query;
			$catalog_button = '';
			$rtwwpcp_get_setting = get_option('rtwwpcp_basic_setting_opt', array());
			if (is_product_category()) 
			{
				$rtwwpcp_cat = $wp_query->get_queried_object()->slug;
				if ( $wp_query->get_queried_object()->parent > 0 ) {
					if ( isset($rtwwpcp_get_setting['enbl_ctgry_catlog']) ) 
					{
						if ( isset($rtwwpcp_get_setting['catalog_btn_txt']) && $rtwwpcp_get_setting['catalog_btn_txt'] != '' ) {
							$catlog_btn = $rtwwpcp_get_setting['catalog_btn_txt'];
						}else{
							$catlog_btn = "Download PDF Catalog";
						}
						$catalog_button = "<div class='rtw-flipbook-form-wrapper'>";
						$catalog_button .= '<a class="rtw-button" href="'.esc_url ( add_query_arg ( array('rtwwpcp_generate_cat_catalog'=> 'true','sub_cat' => $wp_query->get_queried_object()->slug), home_url( $wp->request ) ) ).'">'.$catlog_btn.'</a>';
						$catalog_button .= "</div>";
						echo $catalog_button;
					}
				}else{
					if ( isset($rtwwpcp_get_setting['enbl_ctgry_catlog']) ) 
					{
						if (in_array($rtwwpcp_cat,$rtwwpcp_get_setting['product_catgry'])) 
						{
							if ( isset($rtwwpcp_get_setting['catalog_btn_txt']) && $rtwwpcp_get_setting['catalog_btn_txt'] != '' ) {
								$catlog_btn = $rtwwpcp_get_setting['catalog_btn_txt'];
							}else{
								$catlog_btn = "Download PDF Catalog";
							}
							$catalog_button = "<div class='rtw-flipbook-form-wrapper'>";
							$catalog_button .= '<a class="rtw-button" href="'.esc_url ( add_query_arg ( array('rtwwpcp_generate_cat_catalog'=> 'true','cat' => $rtwwpcp_cat), home_url( $wp->request ) ) ).'">'.$catlog_btn.'</a>';
							$catalog_button .= "</div>";
							echo $catalog_button;
						}
					}
				}
			}
		}
	}
	/**
	 * Delete pdf when post updated.
	 *
	 * @since    1.4.0
	 */
	function rtwwpcp_delete_pdf( $rtwwpge_post_id )
	{
		global $post;
		if ($post) 
		{
			if( file_exists( RTWWPCP_PDF_DIR.'/'.$rtwwpcp_post_id.'.pdf' ) )
			{
				unlink(RTWWPCP_PDF_DIR.'/'.$rtwwpcp_post_id.'.pdf');
			}
			if( file_exists( RTWWPCP_PDF_DIR.'/'.$post->rtwwpcp_post_name.'.pdf' ) )
			{
				unlink(RTWWPCP_PDF_DIR.'/'.$post->rtwwpcp_post_name.'.pdf');
			}
		}
		if( file_exists( RTWWPCP_PDF_DIR.'Category-catalog.pdf' ) )
		{
			unlink(RTWWPCP_PDF_DIR.'Category-catalog.pdf');
		}
		if( file_exists( RTWWPCP_PDF_DIR.'Catalog.pdf' ) )
		{
			unlink(RTWWPCP_PDF_DIR.'Catalog.pdf');
		}	
	}
}
