Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save thagxt/9955380 to your computer and use it in GitHub Desktop.
Save thagxt/9955380 to your computer and use it in GitHub Desktop.
AJAX add to cart button on Shop page in WooCommerce
WTF: Get the AJAX add to cart button on Shop/Category/Search pages in WooCommerce. (AJAX works only for simple products)
HOW:
1) create a directory, name it "woocommerce" put it in your theme root.
2) copy/pasta from woocommerce plugin directory the content-product.php file
3) at the end of the (content-product.php) file, paste the code below:
<?php
global $product;
echo apply_filters( 'woocommerce_loop_add_to_cart_link',
sprintf( '<a href="%s" rel="nofollow" data-product_id="%s" data-product_sku="%s" class="button %s product_type_%s">%s</a>',
esc_url( $product->add_to_cart_url() ),
esc_attr( $product->id ),
esc_attr( $product->get_sku() ),
$product->is_purchasable() ? 'add_to_cart_button' : '',
esc_attr( $product->product_type ),
esc_html( $product->add_to_cart_text() )
),
$product );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment