Friday 31 March 2023

Reviews Tab always show on single product page.

     $args = array(

        'post_type'      => 'product',

        'posts_per_page' => -1

    );


    $loop = new WP_Query( $args );


    while ( $loop->have_posts() ) : $loop->the_post();

              global $product;

$product->set_reviews_allowed( 'yes' );

$product->save();

    endwhile;


    wp_reset_query();

Wednesday 29 March 2023

Update Custom Cart Count (or any HTML) after AJAX Add to Cart in WooCommerce

 

Template Code

Let’s say you’ve added an element in your header that displays the total cart count, like so:

<div class="header-cart-count"><?php echo WC()->cart->get_cart_contents_count(); ?></div>


add_filter( 'woocommerce_add_to_cart_fragments', 'iconic_cart_count_fragments', 10, 1 );

function iconic_cart_count_fragments( $fragments ) {
    
    $fragments['div.header-cart-count'] = '<div class="header-cart-count">' . WC()->cart->get_cart_contents_count() . '</div>';
    
    return $fragments;
    
}