Implement Phase 1: global templates and notices (Bootstrap 5)

Add 9 Twig template overrides for WooCommerce's global and notice templates:
- global/wrapper-start, wrapper-end: conditional container with _theme_wrapped
- global/breadcrumb: Bootstrap breadcrumb component with aria-current
- global/sidebar: offcanvas-lg for mobile, standard aside for desktop
- global/quantity-input: input-group with +/- buttons
- global/form-login: responsive form with form-control, form-check
- notices/notice, error, success: Bootstrap alert-dismissible with icons

Supporting changes:
- assets/js/quantity.js: +/- button handler respecting min/max/step
- assets/css/wc-bootstrap.css: WooCommerce notice fallback styles, spinner removal
- functions.php: register quantity.js script

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-28 10:19:10 +01:00
parent 9592b8cae5
commit 01b807a769
14 changed files with 477 additions and 16 deletions

View File

@@ -0,0 +1,37 @@
{#
# Shop Breadcrumb (Bootstrap 5 Override)
#
# Replaces WooCommerce's breadcrumb with Bootstrap 5 breadcrumb component.
# Skipped when parent theme is wrapping (base.html.twig handles breadcrumbs).
#
# Expected context (from WooCommerce woocommerce_breadcrumb()):
# breadcrumb - Array of [label, url] tuples
# wrap_before - Opening HTML (ignored, we use Bootstrap markup)
# wrap_after - Closing HTML (ignored)
# before - Before each item (ignored)
# after - After each item (ignored)
# delimiter - Between items (ignored, Bootstrap uses CSS)
#
# WooCommerce PHP equivalent: global/breadcrumb.php
#
# @package WcBootstrap
# @since 0.1.0
#}
{% if breadcrumb is defined and breadcrumb|length > 0 %}
<nav aria-label="{{ __('Breadcrumb') }}">
<ol class="breadcrumb">
{% for crumb in breadcrumb %}
{% if not loop.last and crumb[1] is defined and crumb[1] %}
<li class="breadcrumb-item">
<a href="{{ crumb[1]|esc_url }}">{{ crumb[0]|esc_html }}</a>
</li>
{% else %}
<li class="breadcrumb-item active" aria-current="page">
{{ crumb[0]|esc_html }}
</li>
{% endif %}
{% endfor %}
</ol>
</nav>
{% endif %}

View File

@@ -0,0 +1,89 @@
{#
# Global Login Form (Bootstrap 5 Override)
#
# Inline login form used on checkout and other pages (not the My Account login).
# Can be initially hidden and toggled via a link.
#
# Expected context (from WooCommerce wc_get_template('global/form-login.php')):
# hidden - Whether form is initially hidden (boolean)
# message - Optional message to display above the form
# redirect - URL to redirect after login
#
# WooCommerce PHP equivalent: global/form-login.php
#
# @package WcBootstrap
# @since 0.1.0
#}
{% if not is_user_logged_in() %}
<form class="woocommerce-form woocommerce-form-login login{% if hidden %} d-none{% endif %}" method="post">
{{ do_action('woocommerce_login_form_start') }}
{% if message %}
<div class="mb-3">
{{ message|wpautop }}
</div>
{% endif %}
<div class="row g-3 mb-3">
<div class="col-sm-6">
<label for="username" class="form-label">
{{ __('Username or email') }}&nbsp;<span class="text-danger" aria-hidden="true">*</span>
<span class="visually-hidden">{{ __('Required') }}</span>
</label>
<input type="text"
class="form-control"
name="username"
id="username"
autocomplete="username"
required
aria-required="true" />
</div>
<div class="col-sm-6">
<label for="password" class="form-label">
{{ __('Password') }}&nbsp;<span class="text-danger" aria-hidden="true">*</span>
<span class="visually-hidden">{{ __('Required') }}</span>
</label>
<input type="password"
class="form-control"
name="password"
id="password"
autocomplete="current-password"
required
aria-required="true" />
</div>
</div>
{{ do_action('woocommerce_login_form') }}
<div class="d-flex align-items-center justify-content-between flex-wrap gap-2">
<div class="form-check">
<input class="form-check-input"
type="checkbox"
name="rememberme"
id="rememberme"
value="forever" />
<label class="form-check-label" for="rememberme">
{{ __('Remember me') }}
</label>
</div>
{{ wp_nonce_field('woocommerce-login', 'woocommerce-login-nonce') }}
<input type="hidden" name="redirect" value="{{ redirect|esc_url }}" />
<button type="submit"
class="btn btn-primary"
name="login"
value="{{ __('Login') }}">
{{ __('Login') }}
</button>
</div>
<p class="mt-3 mb-0">
<a href="{{ wp_lostpassword_url()|esc_url }}">{{ __('Lost your password?') }}</a>
</p>
{{ do_action('woocommerce_login_form_end') }}
</form>
{% endif %}

View File

@@ -0,0 +1,74 @@
{#
# Quantity Input (Bootstrap 5 Override)
#
# Replaces WooCommerce's quantity input with a Bootstrap 5 input-group
# featuring decrement/increment buttons.
#
# Expected context (from WooCommerce woocommerce_quantity_input()):
# input_id - Input element ID
# input_name - Input element name attribute
# input_value - Current quantity value
# min_value - Minimum allowed quantity
# max_value - Maximum allowed quantity (0 = no max)
# step - Step increment
# placeholder - Placeholder text
# inputmode - Input mode (e.g., 'numeric')
# classes - CSS class(es) for the input
# readonly - Whether input is read-only
# type - Input type attribute
# args - Additional args (product_name for accessible label)
# autocomplete - Autocomplete attribute value
#
# WooCommerce PHP equivalent: global/quantity-input.php
#
# @package WcBootstrap
# @since 0.1.0
#}
{% set label = args.product_name is defined and args.product_name
? __('%s quantity')|format(args.product_name)
: __('Quantity')
%}
<div class="quantity input-group input-group-sm" style="max-width: 140px;">
{{ do_action('woocommerce_before_quantity_input_field') }}
<label class="visually-hidden" for="{{ input_id|esc_attr }}">{{ label|esc_attr }}</label>
{% if not readonly %}
<button type="button"
class="btn btn-outline-secondary wc-qty-minus"
aria-label="{{ __('Decrease quantity') }}"
data-target="#{{ input_id|esc_attr }}">
<i class="bi bi-dash" aria-hidden="true"></i>
</button>
{% endif %}
<input type="{{ type|default('number')|esc_attr }}"
{% if readonly %}readonly="readonly"{% endif %}
id="{{ input_id|esc_attr }}"
class="form-control text-center {{ classes is iterable ? classes|join(' ')|esc_attr : classes|default('')|esc_attr }}"
name="{{ input_name|esc_attr }}"
value="{{ input_value|esc_attr }}"
aria-label="{{ __('Product quantity')|esc_attr }}"
min="{{ min_value|esc_attr }}"
{% if max_value is defined and max_value > 0 %}max="{{ max_value|esc_attr }}"{% endif %}
{% if not readonly %}
step="{{ step|esc_attr }}"
placeholder="{{ placeholder|esc_attr }}"
inputmode="{{ inputmode|default('numeric')|esc_attr }}"
autocomplete="{{ autocomplete|default('on')|esc_attr }}"
{% endif %}
/>
{% if not readonly %}
<button type="button"
class="btn btn-outline-secondary wc-qty-plus"
aria-label="{{ __('Increase quantity') }}"
data-target="#{{ input_id|esc_attr }}">
<i class="bi bi-plus" aria-hidden="true"></i>
</button>
{% endif %}
{{ do_action('woocommerce_after_quantity_input_field') }}
</div>

View File

@@ -0,0 +1,40 @@
{#
# Shop Sidebar (Bootstrap 5 Override)
#
# Renders the WooCommerce shop sidebar using Bootstrap 5 offcanvas for mobile
# and a standard aside column for desktop.
#
# Expected context:
# sidebar_content - Pre-rendered sidebar widget HTML (from get_sidebar('shop'))
#
# WooCommerce PHP equivalent: global/sidebar.php
#
# @package WcBootstrap
# @since 0.1.0
#}
{% if sidebar_content is defined and sidebar_content %}
{# Mobile: offcanvas trigger button (visible below lg breakpoint) #}
<button class="btn btn-outline-secondary d-lg-none mb-3"
type="button"
data-bs-toggle="offcanvas"
data-bs-target="#shopSidebar"
aria-controls="shopSidebar">
<i class="bi bi-funnel" aria-hidden="true"></i>
{{ __('Filters') }}
</button>
{# Mobile: offcanvas panel #}
<div class="offcanvas offcanvas-start offcanvas-lg"
tabindex="-1"
id="shopSidebar"
aria-labelledby="shopSidebarLabel">
<div class="offcanvas-header">
<h5 class="offcanvas-title" id="shopSidebarLabel">{{ __('Filters') }}</h5>
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="{{ __('Close') }}"></button>
</div>
<div class="offcanvas-body">
{{ sidebar_content|raw }}
</div>
</div>
{% endif %}

View File

@@ -0,0 +1,18 @@
{#
# Content Wrapper End (Bootstrap 5 Override)
#
# Closes the wrapper divs opened by wrapper-start.html.twig.
#
# WooCommerce PHP equivalent: global/wrapper-end.php
#
# @package WcBootstrap
# @since 0.1.0
#}
{% set _wrapped = _theme_wrapped is defined and _theme_wrapped %}
{% if not _wrapped %}
</main>
</div>
</div>
{% endif %}

View File

@@ -0,0 +1,20 @@
{#
# Content Wrapper Start (Bootstrap 5 Override)
#
# Replaces WooCommerce's theme-specific wrapper divs with Bootstrap 5 layout.
# When the parent theme wraps the page (_theme_wrapped), this outputs nothing
# since base.html.twig already provides the container.
#
# WooCommerce PHP equivalent: global/wrapper-start.php
#
# @package WcBootstrap
# @since 0.1.0
#}
{% set _wrapped = _theme_wrapped is defined and _theme_wrapped %}
{% if not _wrapped %}
<div class="container my-4">
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
{% endif %}