Answers for "php ajax add to cart woocommerce"

C
0

add_to_cart how to call it woocommerce

add_action( 'template_redirect', 'quadlayers_add_to_cart_function' );

function quadlayers_add_to_cart_function () {

    $product_id = 1326;

    if ( WC()->cart->get_cart_contents_count() == 0 ) {

        WC()->cart->add_to_cart( $product_id );

    }

}
Posted by: Guest on December-08-2020
0

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

//header or woocommerce.php
<div class="header-cart-count"><?php echo WC()->cart->get_cart_contents_count(); ?></div>
//function file
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;
    
}
Posted by: Guest on January-09-2022

Code answers related to "php ajax add to cart woocommerce"

Code answers related to "C"

Browse Popular Code Answers by Language