function is_fancy_product($post_id)
{
    $fpd_meta = get_post_meta($post_id, '_fancy_product', true);
    if (empty($fpd_meta)) {
        //check if wpml plugin is activated
        global $sitepress;
        if ($sitepress && method_exists($sitepress, 'get_original_element_id')) {
            $post_id = $sitepress->get_original_element_id($post_id, 'post_product');
        }
    }
    if (get_post_type($post_id) == 'product') {
        return get_post_meta($post_id, '_fancy_product', true) === 'yes';
    } else {
        return fpd_has_content($post_id) !== false;
    }
}
        public function add_customize_button()
        {
            global $post;
            $product_settings = new FPD_Product_Settings($post->ID);
            $open_in_lightbox = $product_settings->get_option('open_in_lightbox') && trim($product_settings->get_option('start_customizing_button')) != '';
            $fancy_content_ids = fpd_has_content($post->ID);
            if (!is_array($fancy_content_ids) || sizeof($fancy_content_ids) === 0) {
                return;
            }
            if (is_fancy_product($post->ID) && ($product_settings->customize_button_enabled || $open_in_lightbox)) {
                $button_class = trim(fpd_get_option('fpd_start_customizing_css_class')) == '' ? 'fpd-start-customizing-button' : fpd_get_option('fpd_start_customizing_css_class');
                $button_class .= $open_in_lightbox ? ' fpd-disabled' : '';
                $button_class .= fpd_get_option('fpd_start_customizing_button_position') === 'under-short-desc' ? ' fpd-block' : ' fpd-inline';
                $label = $open_in_lightbox ? '' : $product_settings->get_option('start_customizing_button');
                ?>
				<a href="<?php 
                echo esc_url(add_query_arg('start_customizing', 'yes'));
                ?>
" id="fpd-start-customizing-button" class="<?php 
                echo $button_class;
                ?>
" title="<?php 
                echo $product_settings->get_option('start_customizing_button');
                ?>
"><?php 
                echo $label;
                ?>
</a>
				<?php 
            }
        }
        public function add_product_designer()
        {
            global $post;
            $product_settings = new FPD_Product_Settings($post->ID);
            $open_in_lightbox = $product_settings->get_option('open_in_lightbox') && trim($product_settings->get_option('start_customizing_button')) != '';
            if (is_fancy_product($product_settings->master_id) && (!$product_settings->customize_button_enabled || $open_in_lightbox)) {
                FPD_Scripts_Styles::$add_script = true;
                $selector = 'fancy-product-designer-' . $product_settings->master_id . '';
                //get availabe fonts
                $available_fonts = $product_settings->get_option('font_families[]') === false ? FPD_Fonts::get_enabled_fonts() : $product_settings->get_option('font_families[]');
                if (!is_array($available_fonts)) {
                    $available_fonts = str_split($available_fonts, strlen($available_fonts));
                }
                //woocommerce
                if (get_post_type($post) === 'product') {
                    $this->output_wc_start();
                }
                //get assigned categories
                $fancy_content_ids = fpd_has_content($product_settings->master_id);
                if (!is_array($fancy_content_ids) || sizeof($fancy_content_ids) === 0) {
                    return;
                }
                //define the designer margins
                $designer_margins = $product_settings->get_option('designer_margin');
                $margin_styles = '';
                if (!empty($designer_margins)) {
                    @parse_str($designer_margins, $designer_margins);
                    foreach ($designer_margins as $margin_key => $margin_val) {
                        $margin_styles .= 'margin-' . $margin_key . ':' . $margin_val . 'px;';
                    }
                }
                //add class if lightbox is enabled
                $modal_box_css = $open_in_lightbox ? ' fpd-lightbox-enabled' : '';
                $source_type = get_post_meta($product_settings->master_id, 'fpd_source_type', true);
                ?>
				<div id="<?php 
                echo $selector;
                ?>
" class="[ fpd-container ][ margin-bottom ][ xmall-12 medium-8 ][ center ] <?php 
                echo $product_settings->get_option('frame_shadow');
                echo $modal_box_css;
                ?>
">
					<?php 
                foreach ($fancy_content_ids as $fancy_content_id) {
                    if (empty($source_type) || $source_type == 'category') {
                        $fancy_category = new Fancy_Category($fancy_content_id);
                        echo '<div class="fpd-category" title="' . esc_attr($fancy_category->get_data()->title) . '">';
                        $fancy_products_data = $fancy_category->get_products();
                        foreach ($fancy_products_data as $fancy_product_data) {
                            echo $this->get_product_html($fancy_product_data->ID);
                        }
                        echo '</div>';
                        //category
                    } else {
                        echo $this->get_product_html($fancy_content_id);
                    }
                }
                //output designs
                if (!intval($product_settings->get_option('hide_designs_tab'))) {
                    require_once FPD_PLUGIN_DIR . '/inc/class-designs.php';
                    $fpd_designs = new FPD_Designs($product_settings->get_option('design_categories[]') ? $product_settings->get_option('design_categories[]') : array(), $product_settings->get_image_parameters());
                    $fpd_designs->output();
                }
                ?>

				</div>
				<p class="fpd-not-supported-device-info">
					<strong><?php 
                echo fpd_get_option('fpd_not_supported_device_info');
                ?>
</strong>
				</p>

				<script type="text/javascript">

					var fancyProductDesigner,
						$selector,
						$productWrapper,
						$cartForm,
						productCreated = false,
						fpdPrice = 0,
						isReady = false,
						$modalWrapper = null;

					jQuery(document).ready(function() {

						//return;

						$selector = jQuery('#<?php 
                echo $selector;
                ?>
');
						$productWrapper = jQuery('.post-<?php 
                echo $post->ID;
                ?>
');
						$cartForm = jQuery('[name="fpd_product"]:first').parents('form:first');

						var buttonClass = "<?php 
                echo esc_attr(fpd_get_option('fpd_start_customizing_css_class')) == '' ? 'fpd-modal-button' : trim(fpd_get_option('fpd_start_customizing_css_class'));
                ?>
",
							productDesignerWidth = <?php 
                echo $product_settings->get_option('stage_width');
                ?>
,
							customizeBtn = jQuery('#fpd-start-customizing-button');

						if(jQuery('.fpd-lightbox-enabled').size() > 0) {

							$modalWrapper = jQuery('body').append('<div class="fpd-modal-overlay"><div class="fpd-modal-wrapper"><div class="fpd-modal-buttons"><a href="#" id="fpd-modal-done" class="'+buttonClass+'"><?php 
                echo fpd_get_option('fpd_label_lightbox_submit_button');
                ?>
</a><a href="#" id="fpd-modal-cancel" class="'+buttonClass+'"><?php 
                echo fpd_get_option('fpd_label_lightbox_cancel_button');
                ?>
</a></div></div></div>').find('.fpd-modal-wrapper');

							$selector.clone().prependTo($modalWrapper);
							$selector.remove();
							$selector = jQuery('#<?php 
                echo $selector;
                ?>
');

							jQuery(window).resize(function() {
								$modalWrapper.css('margin-left', -($modalWrapper.outerWidth() / 2)+'px');
							});

							customizeBtn.click(function(evt) {

								if(!isReady) { return false; }

								jQuery('html,body').addClass('fpd-modal-open');
								$modalWrapper.parent('.fpd-modal-overlay').fadeIn(300, function() {
									jQuery('.fpd-context-dialog').removeClass('fpd-modal-hidden');
								});
								jQuery(window).resize();

								evt.preventDefault();

							});

							$modalWrapper.on('click', '#fpd-modal-done', function(evt) {

								jQuery('#fpd-modal-cancel').click();

								if(<?php 
                echo intval(fpd_get_option('fpd_lightbox_add_to_cart'));
                ?>
) {
									$cartForm.find(':submit').click();
								}

								evt.preventDefault();

							})
							.on('click', '#fpd-modal-cancel', function(evt) {

								fancyProductDesigner.closeDialog();
								jQuery('html,body').removeClass('fpd-modal-open');
								$modalWrapper.parent('.fpd-modal-overlay').fadeOut(200);
								evt.preventDefault();

							});

						}

						if(jQuery('.fpd-share-design').size() > 0) {

							jQuery('#fpd-share-button').click(function(evt) {

								evt.preventDefault();

								var scale = $selector.width() > 800 ? Number(800 / $selector.width()).toFixed(2) : 1;
								var data = {
									action: 'fpd_createshareurl',
									image: fancyProductDesigner.getProductDataURL('png', 'transparent', scale),
									product: JSON.stringify(fancyProductDesigner.getProduct()),
								};

								jQuery(".fpd-share-widget, .fpd-share-url").addClass('fpd-hidden');
								jQuery('.fpd-share-process').removeClass('fpd-hidden');

								jQuery.post("<?php 
                echo admin_url('admin-ajax.php');
                ?>
", data, function(response) {

									if(response.share_id !== undefined) {

										var pattern = new RegExp('(share_id=).*?(&|$)'),
											shareUrl = window.location.href;

										if(shareUrl.search(pattern) >= 0){
											shareUrl = shareUrl.replace(pattern,'$1' + response.share_id + '$2');
										}
										else{
											shareUrl = shareUrl + (shareUrl.indexOf('?')>0 ? '&' : '?') + 'share_id=' + response.share_id;
										}
										<?php 
                $shares = fpd_get_option('fpd_sharing_social_networks');
                ?>
										jQuery(".fpd-share-widget").empty().jsSocials({
											url: shareUrl,
											shares: <?php 
                echo is_array($shares) ? json_encode($shares) : '[' . $shares . ']';
                ?>
,
										    showLabel: false,
										    text: "<?php 
                echo fpd_get_option('fpd_label_sharing_default_text');
                ?>
"
										}).removeClass('fpd-hidden');
									}

									jQuery('.fpd-share-process').addClass('fpd-hidden');
									jQuery('.fpd-share-url').attr('href', shareUrl).text(shareUrl).removeClass('fpd-hidden');

								}, 'json');



							});

						}

						var customImagesParams = jQuery.extend(<?php 
                echo $product_settings->get_image_parameters_string();
                ?>
, <?php 
                echo $product_settings->get_custom_image_parameters_string();
                ?>
 );

						//call fancy product designer plugin
						fancyProductDesigner = $selector.fancyProductDesigner({
							width: productDesignerWidth,
							stageHeight: <?php 
                echo $product_settings->get_option('stage_height');
                ?>
,
							imageDownloadable: <?php 
                echo $this->disable_export_btns ? 0 : fpd_get_option('fpd_download_product_image');
                ?>
,
							saveAsPdf: <?php 
                echo $this->disable_export_btns ? 0 : fpd_get_option('fpd_pdf_button');
                ?>
,
							printable: <?php 
                echo $this->disable_export_btns ? 0 : fpd_get_option('fpd_print');
                ?>
,
							allowProductSaving: <?php 
                echo fpd_get_option('fpd_allow_product_saving');
                ?>
,
							fonts: [<?php 
                echo '"' . implode('", "', $available_fonts) . '"';
                ?>
],
							templatesDirectory: "<?php 
                echo plugins_url('/templates/', FPD_PLUGIN_ROOT_PHP);
                ?>
",
							phpDirectory: "<?php 
                echo plugins_url('/inc/', FPD_PLUGIN_ROOT_PHP);
                ?>
",
							facebookAppId: "<?php 
                echo fpd_get_option('fpd_facebook_app_id');
                ?>
",
							instagramClientId: "<?php 
                echo fpd_get_option('fpd_instagram_client_id');
                ?>
",
							instagramRedirectUri: "<?php 
                echo fpd_get_option('fpd_instagram_redirect_uri');
                ?>
",
							patterns: [<?php 
                echo implode(',', $this->get_pattern_urls());
                ?>
],
							viewSelectionPosition: "<?php 
                echo $product_settings->get_option('view_selection_position');
                ?>
",
							viewSelectionFloated: <?php 
                echo $product_settings->get_option('view_selection_floated');
                ?>
,
							zoomStep: <?php 
                echo fpd_get_option('fpd_zoom_step');
                ?>
,
							maxZoom: <?php 
                echo fpd_get_option('fpd_max_zoom');
                ?>
,
							tooltips: <?php 
                echo intval(fpd_get_option('fpd_tooltips'));
                ?>
,
							hexNames: <?php 
                echo FPD_Settings_Advanced_Colors::get_hex_names_object_string();
                ?>
,
							selectedColor:  "<?php 
                echo fpd_get_option('fpd_selected_color');
                ?>
",
							boundingBoxColor:  "<?php 
                echo fpd_get_option('fpd_bounding_box_color');
                ?>
",
							outOfBoundaryColor:  "<?php 
                echo fpd_get_option('fpd_out_of_boundary_color');
                ?>
",
							paddingControl:  <?php 
                echo fpd_get_option('fpd_padding_controls');
                ?>
,
							replaceInitialElements: <?php 
                echo $product_settings->get_option('replace_initial_elements');
                ?>
,
							lazyLoad: <?php 
                echo fpd_get_option('fpd_lazy_load');
                ?>
,
							dialogBoxPositioning: "<?php 
                echo $product_settings->get_option('dialog_box_positioning');
                ?>
",
							elementParameters: {
								originX: "<?php 
                echo fpd_get_option('fpd_common_parameter_originX');
                ?>
",
								originY: "<?php 
                echo fpd_get_option('fpd_common_parameter_originY');
                ?>
"
							},
							imageParameters: {
								colorPrices: <?php 
                echo $product_settings->get_option('enable_image_color_prices') ? FPD_Settings_Advanced_Colors::get_color_prices() : '{}';
                ?>
							},
							textParameters: {
								font: "<?php 
                echo fpd_get_option('fpd_font');
                ?>
",
								colorPrices: <?php 
                echo $product_settings->get_option('enable_text_color_prices') ? FPD_Settings_Advanced_Colors::get_color_prices() : '{}';
                ?>
							},
							customImageParameters: customImagesParams,
							customTextParameters: <?php 
                echo $product_settings->get_custom_text_parameters_string();
                ?>
,
							labels: <?php 
                echo FPD_Settings_Labels::get_labels_object_string(array('fpd_label_uploadedDesignSizeAlert' => array('minW' => $product_settings->get_option('uploaded_designs_parameter_minW'), 'minH' => $product_settings->get_option('uploaded_designs_parameter_minH'), 'maxW' => $product_settings->get_option('uploaded_designs_parameter_maxW'), 'maxH' => $product_settings->get_option('uploaded_designs_parameter_maxH'))));
                ?>
,
							customAdds: {
								uploads: <?php 
                echo $product_settings->get_option('hide_custom_image_upload') ? 0 : intval(fpd_get_option('fpd_upload_designs'));
                ?>
,
								texts: <?php 
                echo $product_settings->get_option('hide_custom_text') ? 0 : intval(fpd_get_option('fpd_custom_texts'));
                ?>
,
								facebook: <?php 
                echo $product_settings->get_option('hide_facebook_tab') ? 0 : 1;
                ?>
,
								instagram: <?php 
                echo $product_settings->get_option('hide_instagram_tab') ? 0 : 1;
                ?>
							}
						}).data('fancy-product-designer');

						//when load from cart or order, use loadProduct
						$selector.on('ready', function() {

							if(jQuery('.fpd-lightbox-enabled').size() > 0) {
								jQuery('.fpd-context-dialog').addClass('fpd-modal-hidden');
							}

							if(<?php 
                echo $this->form_views === null ? 0 : 1;
                ?>
) {
								var views = <?php 
                echo $this->form_views === null ? 0 : $this->form_views;
                ?>
;
								fancyProductDesigner.clear();
								fancyProductDesigner.loadProduct(views);
							}

							//replace filereader uploader with php uploader
							if("<?php 
                echo fpd_get_option('fpd_type_of_uploader');
                ?>
" == 'php') {

								var $imageInput = jQuery('body').find('.fpd-input-image');

								jQuery('body').find('.fpd-upload-form').off('change').change(function() {

									jQuery('body').find('.fpd-upload-form').ajaxSubmit({
										url: "<?php 
                echo admin_url('admin-ajax.php');
                ?>
",
										dataType: 'json',
										data: {
											action: 'fpduploadimage',
											product_id: <?php 
                echo $post->ID;
                ?>
										},
										type: 'post',
										beforeSubmit: function(arr, $form, options) {
											$phpUploaderInfo.addClass('fpd-show-up')
											.children('p:first').text('<?php 
                _e('Uploading', 'radykal');
                ?>
'+': '+arr[0].value.name);

											$progressBar.children('.fpd-progress-bar-move').css('width', 0);
										},
										success: function(responseText, statusText) {

											if(responseText.code == 200) {
												//successfully uploaded
												fancyProductDesigner.addCustomImage(responseText.url, responseText.filename);
											}
											else if(responseText.code == 500) {
												//failed
												alert(responseText.message);
											}
											else {
												//failed
												alert("<?php 
                _e('You need to be logged in to upload images!', 'radykal');
                ?>
");
											}
											$imageInput.val('');
											$phpUploaderInfo.removeClass('fpd-show-up');

										},
										error: function() {
											$imageInput.val('');
											$phpUploaderInfo.removeClass('fpd-show-up');
											alert("<?php 
                _e('Server error: Image could not be uploaded, please try again!', 'radykal');
                ?>
");
										},
										uploadProgress: function(evt, pos, total, percentComplete) {
											$progressBar.children('.fpd-progress-bar-move').css('width', percentComplete+'%');
										}
									});

								})

								jQuery('body').append('<div class="fpd-php-uploader-info fpd-snackbar fpd-shadow-1"><p></p><div class="fpd-upload-progess-bar"><div class="fpd-progress-bar-bg"></div><div class="fpd-progress-bar-move"></div></div></div>');

								$phpUploaderInfo = jQuery('body').children('.fpd-php-uploader-info');
								$progressBar = $phpUploaderInfo.children('.fpd-upload-progess-bar');

							}

							//hide loading icon in customize btn
							customizeBtn.removeClass('fpd-disabled')
							.text(customizeBtn.attr('title')).removeAttr('title');

							isReady = true;

						});

					});

				</script>

				<?php 
                //woocommerce
                if (get_post_type($post) === 'product') {
                    $this->output_wc_js();
                } else {
                    $this->output_shortcode_js();
                }
            }
        }