At last i solved it myself. Hope someone will get benefit form this answer. I merge $default
variables all array (quantity
, class
, attributes
) directly into link. I changed whole block of if ( $product ) {}
.
if ( $product ) {
$output .= sprintf( '<a href="%s" data-quantity="1" class="%s" %s>%s</a>',
esc_url( $product->add_to_cart_url() ),
esc_attr(
implode(
' ',
array_filter(
array(
'button', 'product_type_' . $product->get_type(),
$product->is_purchasable() && $product->is_in_stock() ? 'add_to_cart_button' : '',
$product->supports( 'ajax_add_to_cart' ) ? 'ajax_add_to_cart' : '',
)
)
)
),
wc_implode_html_attributes(
array(
'data-product_id' => $product->get_id(),
'data-product_sku' => $product->get_sku(),
'aria-label' => $product->add_to_cart_description(),
'rel' => 'nofollow',
)
),
esc_html( $product->add_to_cart_text() )
);
}