Files
wc-bootstrap/templates/loop/add-to-cart.html.twig

48 lines
1.7 KiB
Twig
Raw Normal View History

{#
# Loop Add to Cart Button (Bootstrap 5 Override)
#
# Renders the add-to-cart button within the product loop.
#
# Expected context:
# product - WC_Product object with:
# .add_to_cart_url() - Add to cart URL
# .add_to_cart_text() - Button label
# .is_purchasable() - Whether product can be purchased
# .is_in_stock() - Whether product is in stock
# .supports('ajax_add_to_cart') - Whether AJAX add to cart is supported
# .get_id() - Product ID
# args - Array with:
# .quantity - Quantity (default: 1)
# .class - CSS classes
# .attributes - Additional HTML attributes
# .aria-describedby_text - Accessibility description
#
# WooCommerce PHP equivalent: loop/add-to-cart.php
#
# @package WcBootstrap
# @since 0.1.0
#}
{% set quantity = args.quantity|default(1) %}
{% set btn_class = 'btn btn-primary btn-sm w-100' %}
<a href="{{ product.add_to_cart_url()|esc_url }}"
class="{{ btn_class }} {{ args.class|default('') }}"
data-quantity="{{ quantity }}"
data-product_id="{{ product.get_id() }}"
{% if args.attributes is defined %}
{% for attr, value in args.attributes %}
{{ attr }}="{{ value|esc_attr }}"
{% endfor %}
{% endif %}
aria-label="{{ product.add_to_cart_text()|esc_attr }}"
rel="nofollow">
{{ product.add_to_cart_text() }}
</a>
{% if args['aria-describedby_text'] is defined and args['aria-describedby_text'] %}
<span id="woocommerce_loop_add_to_cart_link_describedby_{{ product.get_id() }}" class="visually-hidden">
{{ args['aria-describedby_text'] }}
</span>
{% endif %}