<?php
/**
 * Related Products
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/single-product/related.php.
 *
 * HOWEVER, on occasion WooCommerce will need to update template files and you
 * (the theme developer) will need to copy the new files to your theme to
 * maintain compatibility. We try to do this as little as possible, but it does
 * happen. When this occurs the version of the template file will be bumped and
 * the readme will list any important changes.
 *
 * @see 	    https://docs.woocommerce.com/document/template-structure/
 * @author 		WooThemes
 * @package 	WooCommerce/Templates
 * @version   8.0.0
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
global $post;
 ?>
<?php if (get_theme_mod( 'charsoogh_ad_user_related') != 'no') : ?>
 <div class="show_related_by_user">
	 <div class="load-related-user"><?php _e('Loading ...' , 'charsoogh'); ?></div>
 </div>
<?php endif; ?>
<?php if (get_theme_mod( 'charsoogh_ad_related') != 'no') : ?>
 <div class="show_related">
 	 <div class="load-related"><?php _e('Loading ...' , 'charsoogh'); ?></div>
 </div>
<?php endif; ?>
<?php add_action('wp_footer',function(){ ?>
<script>var ajaxurl = '<?php echo admin_url("admin-ajax.php") ?>';</script>
<?php
});
add_action('wp_footer','wp_ajax_related');
add_action('admin_footer','wp_ajax_related');
function wp_ajax_related(){
		?>
		<script>
		jQuery(".load-related").css("display", "block");
		jQuery(".load-related-user").css("display", "block");
				jQuery(document).ready(function($) {
							// Related ads
								var data = {
										action: 'load_related_by_ajax',
										postID: <?php echo get_the_ID(); ?>
								}
								jQuery.post(ajaxurl,data,function(response){
										jQuery(".show_related").html(response);
										$('[data-toggle="tooltip"]').tooltip();
										$(".ribbon-featured").each(function() {
												var thisText = $(this).text();
												$(this).html("");
												$(this).append(
														"<div class='ribbon-start'></div>" +
														"<div class='ribbon-content'>" + thisText + "</div>" +
														"<div class='ribbon-end'>" +
																"<figure class='ribbon-shadow'></figure>" +
														"</div>"
												);
										});
										jQuery(".load-related").css("display", "none");
										<?php if (get_theme_mod( 'charsoogh_related_ad_layout' )) : $related_item = get_theme_mod( 'charsoogh_related_ad_layout'); else: $related_item = 4; endif;
										if($related_item == 'featured'){$related_item = 3;}else{$related_item = 4;} ?>
										 <?php if (get_theme_mod( 'charsoogh_visit_ad_show') == 'no') : ?>
										 jQuery('.ad_visit').hide();
										<?php endif; ?>
										jQuery(".featured-carousel").owlCarousel({loop:!1,margin:0,nav:!0,<?php if(is_rtl()): echo 'rtl:!0'; else: echo 'ltr:!0'; endif; ?>,dots:!1,items:<?php echo $related_item; ?>,navText:["<i class='fa fa-chevron-left'></i>","<i class='fa fa-chevron-right'></i>"],URLhashListener:!0,responsive:{768:{items:<?php echo $related_item; ?>},0:{items:1,dots:1,nav:false,center:!1,margin:0,autoWidth:!1}}});
								});

								// Related By User
								var Userdata = {
										action: 'load_related_user_by_ajax',
										userID: '<?php echo get_queried_object()->post_author;; ?>',
										postID: <?php echo get_the_ID(); ?>
								}
								jQuery.post(ajaxurl,Userdata,function(response){
										jQuery(".show_related_by_user").html(response);
										$('[data-toggle="tooltip"]').tooltip();
										$(".ribbon-featured").each(function() {
												var thisText = $(this).text();
												$(this).html("");
												$(this).append(
														"<div class='ribbon-start'></div>" +
														"<div class='ribbon-content'>" + thisText + "</div>" +
														"<div class='ribbon-end'>" +
																"<figure class='ribbon-shadow'></figure>" +
														"</div>"
												);
										});
										jQuery(".load-related-user").css("display", "none");
										<?php if (get_theme_mod( 'charsoogh_related_ad_layout' )) : $related_item = get_theme_mod( 'charsoogh_related_ad_layout'); else: $related_item = 4; endif;
										if($related_item == 'featured'){$related_item = 3;}else{$related_item = 4;} ?>
										 <?php if (get_theme_mod( 'charsoogh_visit_ad_show') == 'no') : ?>
										 jQuery('.ad_visit').hide();
										<?php endif; ?>
										jQuery(".featured-carousel").owlCarousel({loop:!1,margin:0,nav:!0,<?php if(is_rtl()): echo 'rtl:!0'; else: echo 'ltr:!0'; endif; ?>,dots:!1,items:<?php echo $related_item; ?>,navText:["<i class='fa fa-chevron-left'></i>","<i class='fa fa-chevron-right'></i>"],URLhashListener:!0,responsive:{768:{items:<?php echo $related_item; ?>},0:{items:1,dots:1,nav:false,center:!1,margin:0,autoWidth:!1}}});
								});
				});
		</script>
		<?php } ?>
