Skip to content

Instantly share code, notes, and snippets.

@nfmohit
Created May 14, 2020 00:40
Show Gist options
  • Select an option

  • Save nfmohit/80fefce7ed2463e827194bf577eaa52e to your computer and use it in GitHub Desktop.

Select an option

Save nfmohit/80fefce7ed2463e827194bf577eaa52e to your computer and use it in GitHub Desktop.
<?php
if ( ! function_exists( 'woocommerce_template_loop_add_to_cart' ) ) {
function woocommerce_template_loop_add_to_cart( $args = array() ) {
global $product;
if ( !$product->is_in_stock() ) {
echo '<a href="' . get_permalink() . '" class="button">Out of Stock</a>';
} else {
$defaults = array(
'quantity' => 1,
'class' => implode( ' ', array_filter( array(
'button',
'product_type_' . $product->product_type,
$product->is_purchasable() && $product->is_in_stock() ? 'add_to_cart_button' : '',
$product->supports( 'ajax_add_to_cart' ) ? 'ajax_add_to_cart' : ''
) ) )
);
$args = apply_filters( 'woocommerce_loop_add_to_cart_args', wp_parse_args( $args, $defaults ), $product );
wc_get_template( 'loop/add-to-cart.php', $args );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment