最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

wp query - Ajax buttons not working properly in WooCommerce when using wc_get_template_part

programmeradmin2浏览0评论

I have a custom loop on my website home page of best selling products.

I am using wc_get_template_part('content', 'product'); to pull in the products.

But when I click the buy button, the buy button does not get the tick added to it, so it doesn't look the purchase has worked for users. The item is added to the cart. The buttons work as they should on other pages.

I have checked that "Enable AJAX add to basket buttons on archives" is ticked.

I have tried adding global to my code to see if that makes a difference.

There are no JS errors being logged.

Any ideas why it's not working as expected?

Here is my code:

<?php
    global $woocommerce_loop;
    global $product;
    $args = array(
    'post_type' => 'product',
    'meta_key' => 'total_sales',
    'orderby' => 'meta_value_num',
    'posts_per_page' => 12
    );
    $product = new WP_Query( $args );

    if ($product->have_posts()) {
    while ($product->have_posts()) {
        $product->the_post();
        wc_get_template_part('content', 'product');
    }
    ?>

I have a custom loop on my website home page of best selling products.

I am using wc_get_template_part('content', 'product'); to pull in the products.

But when I click the buy button, the buy button does not get the tick added to it, so it doesn't look the purchase has worked for users. The item is added to the cart. The buttons work as they should on other pages.

I have checked that "Enable AJAX add to basket buttons on archives" is ticked.

I have tried adding global to my code to see if that makes a difference.

There are no JS errors being logged.

Any ideas why it's not working as expected?

Here is my code:

<?php
    global $woocommerce_loop;
    global $product;
    $args = array(
    'post_type' => 'product',
    'meta_key' => 'total_sales',
    'orderby' => 'meta_value_num',
    'posts_per_page' => 12
    );
    $product = new WP_Query( $args );

    if ($product->have_posts()) {
    while ($product->have_posts()) {
        $product->the_post();
        wc_get_template_part('content', 'product');
    }
    ?>
Share Improve this question asked Apr 26, 2019 at 10:29 thetwopctthetwopct 2913 silver badges12 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 0

The answer was that I had dequeued the woocommerce style sheets and fonts, adding the CSS back in made the tick marks appear

.added:after {
    font-family: WooCommerce;
    content: '\e017';
    margin-left: .53em;
    vertical-align: bottom;
    display: inline-block;
}
发布评论

评论列表(0)

  1. 暂无评论