【问题标题】:Unable to change add to cart button using AJAX无法使用 AJAX 更改添加到购物车按钮
【发布时间】:2015-06-25 09:33:20
【问题描述】:

点击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 按钮应该被禁用。我该怎么做?

【问题讨论】:

    标签: php jquery ajax woocommerce


    【解决方案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
    }
    

    谢谢!!

    【讨论】:

      猜你喜欢
      • 2023-03-06
      • 1970-01-01
      • 2021-04-21
      • 2021-02-03
      • 1970-01-01
      • 2021-12-31
      • 2018-10-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多