我通过自定义WP_Query加载变量产品
$args = array(
'post_type' => 'product',
'posts_per_page' => 100,
'product_cat' => 'beast-balls',
'orderby' => 'date',
'order' => 'desc'
);
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<div class="product-node cat-beast-balls">
<?php wc_get_template_part( 'content', 'single-product' ); ?>
</div>
<?php endwhile;
}
wp_reset_postdata();
Run Code Online (Sandbox Code Playgroud)
这似乎工作正常.但是,我使用ajax重新加载产品,但使用不同的循环,例如这个.
$args = array(
'post_type' => 'product',
'posts_per_page' => 100,
'product_cat' => 'beast-balls',
'orderby' => 'price',
'order' => 'asc'
);
$loop = new WP_Query( $args );
if ( …Run Code Online (Sandbox Code Playgroud) 我想更新,然后当购物车中的商品数量发生变化时,通过AJAX重新加载我的购物车.
我已经可以通过AJAX成功加载到我的购物车中.
要加载我的购物车我的PHP功能看起来像这样.(在我的functions.php中)
function enqueue_cart_show_ajax() {
wp_register_script( 'cart-show-ajax-js', get_template_directory_uri() . '/js/cart-show-ajax.js', array( 'jquery' ), '', true );
wp_localize_script( 'cart-show-ajax-js', 'cart_show_ajax', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );
wp_enqueue_script( 'cart-show-ajax-js' );
}
add_action('wp_enqueue_scripts', 'enqueue_cart_show_ajax');
function ajax_show_cart() {
echo do_shortcode( '[woocommerce_cart]' );
die();
}
add_action('wp_ajax_show_cart', 'ajax_show_cart');
add_action('wp_ajax_nopriv_show_cart', 'ajax_show_cart');
Run Code Online (Sandbox Code Playgroud)
我的Jquery代码看起来像这样(在cart-show-ajax.js中)
jQuery(function($) {
//If view-cart is clicked, fill the view-cart-popup window with the cart
$( '.view-cart' ).on('click', function(){
show_cart();
});
//Main ajax function
function show_cart() {
$.ajax({
type: 'GET',
url: cart_show_ajax.ajax_url,
data: { …Run Code Online (Sandbox Code Playgroud) 我创建了一个在Chrome上工作正常的功能,但似乎在firefox上产生错误
ReferenceError: playNextClip is not defined
Run Code Online (Sandbox Code Playgroud)
您可以在以下网址查看该网站:http://thewild.com.au/caleboys/
我的JS如下.
function queueVideos(num, amount) {
if (num < amount) {
document.getElementById('video-element-'+num).addEventListener(
'ended',
playNextClip,
false);
function playNextClip() {
var nextVid = num + 1;
$( '#video-element-' + nextVid ).show().get(0).play();
$( '#video-element-' + num ).hide();
document.getElementById( 'video-element-' + num ).pause();
document.getElementById( 'video-element-' + num ).currentTime = 0;
queueVideos(nextVid, amount)
}
}
if (num == amount) {
document.getElementById('video-element-'+num).addEventListener(
'ended',
playFirst,
false);
function playFirst() {
$( '#video-element-1' ).show().get(0).play();
$( '#video-element-' + num ).hide();
document.getElementById( …Run Code Online (Sandbox Code Playgroud)