Last active
December 29, 2020 07:38
-
-
Save jahir07/2bf95e9e81804fec61e456e28aac6018 to your computer and use it in GitHub Desktop.
WordPress: Owl Carousel in magnificPopup with ajax request
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(".quickview").magnificPopup({ | |
type: "ajax", | |
removalDelay: 300, | |
mainClass: "mfp-fade mfp-quickview", | |
closeOnBgClick: false, | |
preloader: true, | |
tLoading: "", | |
callbacks: { | |
ajaxContentAdded: function () { | |
$(".owl-carousel").each(function (index) { | |
var items = $(this).data('items'); | |
var autoplay = $(this).data('autoplay'); | |
$(this).owlCarousel({ | |
items: items, | |
autoplay: autoplay | |
}); | |
}); | |
} | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="quickview-area"> | |
<a class="quickview" href="<?php echo admin_url( 'admin-ajax.php' ); ?>?action=product_quick_view&post_id=<?php echo get_the_ID() ?>"><span class="arrow_expand_alt"></span></a> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="owl-carousel-gallery" class="owl-carousel" data-autoplay="true" data-items="1"> | |
<div class="item-image"> | |
<img class="img-fluid" src="1.jpg" alt=""> | |
</div> | |
<div class="item-image"> | |
<img class="img-fluid" src="2.jpg" alt=""> | |
</div> | |
<div class="item-image"> | |
<img class="img-fluid" src="3.jpg" alt=""> | |
</div> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action ( 'wp_ajax_nopriv_product_quick_view', 'daisy_product_quick_view' ); | |
add_action ( 'wp_ajax_product_quick_view', 'daisy_product_quick_view' ); | |
function daisy_product_quick_view () { | |
$pid = intval($_GET['post_id']); | |
$the_query = new WP_Query(array( | |
'post_type' => 'product', | |
'posts_per_page' => 1, | |
'p' => $pid | |
)); | |
if ($the_query->have_posts()) { | |
while ( $the_query->have_posts() ) { | |
$the_query->the_post(); | |
//template file | |
get_template_part( 'template-parts/quick-view/quickview', 'content' ); | |
} | |
} else { | |
echo '<div id="postdata">'.esc_html__('Didnt find anything', 'daisy').'</div>'; | |
} | |
wp_reset_postdata(); | |
die(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment