admin管理员组

文章数量:1435858

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;
}

本文标签: wp queryAjax buttons not working properly in WooCommerce when using wcgettemplatepart