Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Check if product can be added to cart before adding ajax class to but…
Browse files Browse the repository at this point in the history
…ton (#4265)
  • Loading branch information
opr authored and grogou committed Aug 20, 2021
1 parent a1ccaf4 commit 6de68e4
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/BlockTypes/AbstractProductGrid.php
Expand Up @@ -485,7 +485,11 @@ protected function get_add_to_cart( $product ) {
'class' => 'wp-block-button__link add_to_cart_button',
);

if ( $product->supports( 'ajax_add_to_cart' ) ) {
if (
$product->supports( 'ajax_add_to_cart' ) &&
$product->is_purchasable() &&
( $product->is_in_stock() || $product->backorders_allowed() )
) {
$attributes['class'] .= ' ajax_add_to_cart';
}

Expand Down

0 comments on commit 6de68e4

Please sign in to comment.