You've already forked wc-bootstrap
Add Bootstrap 5 product archive with card grid and sidebar
Replace WooCommerce's default shop/category page rendering with a Bootstrap 5 card grid layout featuring responsive columns, sale badges, star ratings, and an offcanvas sidebar for filters on mobile. Key implementation details: - Bypass parent theme's TemplateController for product archives via wp_bootstrap_should_render_template filter, render at template_redirect priority 11 using the same page shell injection pattern as plugin pages - Add archive-product.php (Bootstrap layout with optional sidebar) and content-product.php (PHP bridge for wc_get_template_part interception) - Inject global $product into Twig context in TemplateOverride to fix empty price/add-to-cart/rating/sale-flash in loop sub-templates — Twig has isolated variable scopes and cannot access PHP globals directly - Fix pagination URLs: use get_pagenum_link() instead of ?page= query param (WordPress uses 'paged' for archive pagination, not 'page') - Fix double-escaped – in result count by adding |raw filter - Reset WooCommerce float-based layout CSS (woocommerce-layout.css) for shop pages to prevent conflicts with Bootstrap flex grid - Register shop-sidebar widget area with Bootstrap-styled markup Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
33
content-product.php
Normal file
33
content-product.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* Product Content in Loop — PHP Bridge to Twig
|
||||
*
|
||||
* Bridge file that renders the Bootstrap 5 card template (content-product.html.twig)
|
||||
* via the parent theme's TwigService instead of WooCommerce's default <li> markup.
|
||||
*
|
||||
* WooCommerce's wc_get_template_part('content', 'product') uses locate_template()
|
||||
* which finds this file in the child theme before falling back to the plugin template.
|
||||
* Unlike wc_get_template(), wc_get_template_part() does NOT fire the
|
||||
* woocommerce_before_template_part / woocommerce_after_template_part hooks,
|
||||
* so the TemplateOverride class cannot intercept it — this bridge file is needed.
|
||||
*
|
||||
* @package WcBootstrap
|
||||
* @since 0.1.0
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
global $product;
|
||||
|
||||
// Ensure the product is valid and visible (same guard as WooCommerce's default template).
|
||||
if ( ! is_a( $product, WC_Product::class ) || ! $product->is_visible() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( class_exists( '\WPBootstrap\Twig\TwigService' ) ) {
|
||||
$twig = \WPBootstrap\Twig\TwigService::getInstance();
|
||||
echo $twig->render( 'content-product.html.twig', [] );
|
||||
} else {
|
||||
// Fallback: include WooCommerce's default template directly.
|
||||
include WC()->plugin_path() . '/templates/content-product.php';
|
||||
}
|
||||
Reference in New Issue
Block a user