Fix 10 known bugs: catalog, single product, and account pages (v0.1.5)
All checks were successful
Create Release Package / PHP Lint (push) Successful in 44s
Create Release Package / Build Release (push) Successful in 52s

Catalog: page title via woocommerce_page_title(), breadcrumbs, category
template rename (underscore), 3-column grid, single chevron on sort.

Single product: variable form data attributes + disabled CSS class fix
(WC JS only toggles CSS classes, not HTML disabled attribute), dark mode
select specificity (0,5,1) to beat WC's (0,4,3) background shorthand,
gallery main image in thumbnail strip with empty URL guard, related/
upsells setup_postdata for correct global $product, grouped product
loop logic rewrite.

Account: downloads via wc_get_customer_available_downloads().

New: product-gallery.js, sanitize_title filter, wc_setup_product_data()
and wp_reset_postdata() Twig functions, product-thumbnails.html.twig
suppressor. Removed obsolete PLAN.md and SETUP.md.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-01 03:33:31 +01:00
parent 98359d4cfb
commit 784b400c46
23 changed files with 340 additions and 922 deletions

View File

@@ -37,6 +37,9 @@ class WooCommerceExtension extends AbstractExtension {
new TwigFilter( 'esc_attr', 'esc_attr', [ 'is_safe' => [ 'html' ] ] ),
new TwigFilter( 'esc_url', 'esc_url', [ 'is_safe' => [ 'html' ] ] ),
// Slug/sanitize filters.
new TwigFilter( 'sanitize_title', 'sanitize_title' ),
// Text processing filters.
new TwigFilter( 'wpautop', 'wpautop', [ 'is_safe' => [ 'html' ] ] ),
new TwigFilter( 'wp_kses_post', 'wp_kses_post', [ 'is_safe' => [ 'html' ] ] ),
@@ -107,6 +110,10 @@ class WooCommerceExtension extends AbstractExtension {
// Dynamic function calls.
new TwigFunction( 'call_user_func', [ $this, 'callUserFunc' ], [ 'is_safe' => [ 'html' ] ] ),
new TwigFunction( 'fn', [ $this, 'callFunction' ] ),
// Product loop helpers (set global $product for WC hooks in Twig loops).
new TwigFunction( 'wc_setup_product_data', [ $this, 'setupProductData' ] ),
new TwigFunction( 'wp_reset_postdata', 'wp_reset_postdata' ),
];
}
@@ -248,6 +255,8 @@ class WooCommerceExtension extends AbstractExtension {
'wc_review_ratings_enabled',
'wc_get_product_category_list',
'wc_get_product_tag_list',
'woocommerce_page_title',
'wc_get_customer_available_downloads',
];
/**
@@ -275,6 +284,25 @@ class WooCommerceExtension extends AbstractExtension {
return $name( ...$args );
}
/**
* Set up global product data for WC hook-based rendering in Twig loops.
*
* WooCommerce hooks (woocommerce_before_shop_loop_item, etc.) read from
* the global $product. When iterating products in Twig (related, upsells),
* the global must be updated before rendering each product card.
*
* @param \WC_Product $product Product object.
* @return string Empty string (Twig requires a return value).
*/
public function setupProductData( \WC_Product $product ): string {
$GLOBALS['product'] = $product;
$post = get_post( $product->get_id() );
if ( $post ) {
setup_postdata( $GLOBALS['post'] = $post );
}
return '';
}
/**
* Capture wc_print_notices() output.
*