无法使用AJAX更改添加到购物车按钮

时间:2015-06-25 09:33:20

标签: php jquery ajax woocommerce

点击category button

,我正在拨打产品列表

如下:

$id = $_GET['ServiceId'];
?>
<ul class="products">
    <?php
        $args = array( 'post_type' => 'product', 'posts_per_page' => 10, 'product_cat' => $id, 'orderby' => 'rand' );
        $loop = new WP_Query( $args );
        while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
            <div>
            <li class="food_menu">
                    <a href="<?php echo get_permalink( $loop->post->ID ) ?>" title="<?php echo esc_attr($loop->post->post_title ? $loop->post->post_title : $loop->post->ID); ?>">

                        <?php woocommerce_show_product_sale_flash( $post, $product ); ?>

                        <?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog'); else echo '<img src="'.woocommerce_placeholder_img_src().'" alt="Placeholder" />'; ?>
                  <div class="heading_food">
                   <h3 class="food_head"><?php the_title(); ?></h3>
                    <p class="food_head1">Description 1</p>
                   <p class="food_head1">Description 2</p>
                  </div>
               <div class="price"><?php echo $product->get_price_html(); ?></div>
               <div class="qty1" style="width:100%;margin-top:60px">
                 <?php woocommerce_template_loop_add_to_cart( $loop->post, $product ); ?>
               </div>

           </li>
                </div>
    <?php endwhile; ?>
    <?php wp_reset_query(); ?>

它显示了该类别的产品列表,它显示了一个Add to cart按钮,我想要的是,如果有人点击此按钮,那么它应该转到added to cartadd to cart按钮应该被禁用。我怎么能这样做?

1 个答案:

答案 0 :(得分:-1)

试试这个代码。我希望,它会帮助你......

<强> HTML:

<input type="submit" value="Add to cart" class="add_cart">

<强>脚本:

jQuery('.add_cart').on('click', function () {
    jQuery(this).prop('disabled', true); // for disabled button
    jQuery(this).val('Added to cart'); // for change button as Added to cart
}

谢谢!!