You've already forked wc-bootstrap
Add Bootstrap 5 single product page layout
Add two-column responsive grid (image gallery + product summary) for
single product pages, following the same bridge pattern used for
product archives.
Key changes:
- Create content-single-product.php bridge and Twig layout template
- Add single product renderer at template_redirect priority 11
- Disable WooCommerce block compatibility layer that strips classic
hooks when parent theme has theme.json
- Move PHP templates to woocommerce/ subfolder for cleaner structure
- Fix Twig templates to self-compute context data not passed by
wc_get_template() (tabs, short-description, meta, rating)
- Fix Underscore.js triple-brace syntax conflict in variation template
by wrapping in {% verbatim %}
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
104
woocommerce/archive-product.php
Normal file
104
woocommerce/archive-product.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
/**
|
||||
* Product Archive / Shop Page (Bootstrap 5 Layout)
|
||||
*
|
||||
* Renders the WooCommerce product archive content with a Bootstrap 5 layout
|
||||
* featuring a responsive sidebar (offcanvas on mobile) and product card grid.
|
||||
*
|
||||
* This file is NOT included directly by WordPress. Instead, it is captured via
|
||||
* output buffering by wc_bootstrap_render_product_archive() and injected into
|
||||
* the parent theme's page shell (pages/page.html.twig). Therefore it does NOT
|
||||
* call get_header()/get_footer() or render the wrapper hooks.
|
||||
*
|
||||
* @package WcBootstrap
|
||||
* @since 0.1.0
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
// Fire structured data hook (normally on woocommerce_before_main_content at priority 30).
|
||||
do_action( 'woocommerce_shop_loop_header' );
|
||||
|
||||
$has_sidebar = is_active_sidebar( 'shop-sidebar' );
|
||||
|
||||
if ( woocommerce_product_loop() ) {
|
||||
|
||||
/**
|
||||
* Hook: woocommerce_before_shop_loop.
|
||||
*
|
||||
* @hooked woocommerce_output_all_notices - 10
|
||||
* @hooked woocommerce_result_count - 20
|
||||
* @hooked woocommerce_catalog_ordering - 30
|
||||
*/
|
||||
do_action( 'woocommerce_before_shop_loop' );
|
||||
|
||||
?>
|
||||
<div class="row g-4">
|
||||
<?php if ( $has_sidebar ) : ?>
|
||||
<aside class="col-lg-3 mb-4 mb-lg-0">
|
||||
<button class="btn btn-outline-secondary w-100 d-lg-none mb-3"
|
||||
type="button"
|
||||
data-bs-toggle="offcanvas"
|
||||
data-bs-target="#shopSidebar"
|
||||
aria-controls="shopSidebar">
|
||||
<i class="bi bi-funnel me-1" aria-hidden="true"></i>
|
||||
<?php esc_html_e( 'Filters', 'wc-bootstrap' ); ?>
|
||||
</button>
|
||||
|
||||
<div class="offcanvas-lg offcanvas-start"
|
||||
id="shopSidebar"
|
||||
tabindex="-1"
|
||||
aria-labelledby="shopSidebarLabel">
|
||||
<div class="offcanvas-header d-lg-none">
|
||||
<h5 class="offcanvas-title" id="shopSidebarLabel">
|
||||
<?php esc_html_e( 'Filters', 'wc-bootstrap' ); ?>
|
||||
</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="<?php esc_attr_e( 'Close', 'wc-bootstrap' ); ?>"></button>
|
||||
</div>
|
||||
<div class="offcanvas-body p-0">
|
||||
<?php dynamic_sidebar( 'shop-sidebar' ); ?>
|
||||
</div>
|
||||
</div>
|
||||
</aside>
|
||||
<div class="col-lg-9">
|
||||
<?php else : ?>
|
||||
<div class="col-12">
|
||||
<?php endif; ?>
|
||||
|
||||
<?php
|
||||
woocommerce_product_loop_start();
|
||||
|
||||
if ( wc_get_loop_prop( 'total' ) ) {
|
||||
while ( have_posts() ) {
|
||||
the_post();
|
||||
|
||||
/**
|
||||
* Hook: woocommerce_shop_loop.
|
||||
*/
|
||||
do_action( 'woocommerce_shop_loop' );
|
||||
|
||||
wc_get_template_part( 'content', 'product' );
|
||||
}
|
||||
}
|
||||
|
||||
woocommerce_product_loop_end();
|
||||
|
||||
/**
|
||||
* Hook: woocommerce_after_shop_loop.
|
||||
*
|
||||
* @hooked woocommerce_pagination - 10
|
||||
*/
|
||||
do_action( 'woocommerce_after_shop_loop' );
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
|
||||
} else {
|
||||
/**
|
||||
* Hook: woocommerce_no_products_found.
|
||||
*
|
||||
* @hooked wc_no_products_found - 10
|
||||
*/
|
||||
do_action( 'woocommerce_no_products_found' );
|
||||
}
|
||||
33
woocommerce/content-product.php
Normal file
33
woocommerce/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';
|
||||
}
|
||||
46
woocommerce/content-single-product.php
Normal file
46
woocommerce/content-single-product.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/**
|
||||
* Single Product Content — PHP Bridge to Twig
|
||||
*
|
||||
* Bridge file that renders the Bootstrap 5 single product template
|
||||
* (content-single-product.html.twig) via the parent theme's TwigService
|
||||
* instead of WooCommerce's default flat layout.
|
||||
*
|
||||
* WooCommerce's wc_get_template_part('content', 'single-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;
|
||||
|
||||
/**
|
||||
* Hook: woocommerce_before_single_product.
|
||||
*
|
||||
* @hooked woocommerce_output_all_notices - 10
|
||||
*/
|
||||
do_action( 'woocommerce_before_single_product' );
|
||||
|
||||
if ( post_password_required() ) {
|
||||
echo get_the_password_form(); // WPCS: XSS ok.
|
||||
return;
|
||||
}
|
||||
|
||||
if ( class_exists( '\WPBootstrap\Twig\TwigService' ) ) {
|
||||
$twig = \WPBootstrap\Twig\TwigService::getInstance();
|
||||
echo $twig->render( 'content-single-product.html.twig', [
|
||||
'product' => $product,
|
||||
'product_id' => $product->get_id(),
|
||||
'product_class' => implode( ' ', wc_get_product_class( '', $product ) ),
|
||||
] );
|
||||
} else {
|
||||
// Fallback: include WooCommerce's default template directly.
|
||||
include WC()->plugin_path() . '/templates/content-single-product.php';
|
||||
}
|
||||
35
woocommerce/single-product.php
Normal file
35
woocommerce/single-product.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* Single Product Page (Bootstrap 5 Layout)
|
||||
*
|
||||
* Renders the WooCommerce single product content. This file is NOT included
|
||||
* directly by WordPress. Instead, it is captured via output buffering by
|
||||
* wc_bootstrap_render_single_product() and injected into the parent theme's
|
||||
* page shell (pages/page.html.twig). Therefore it does NOT call
|
||||
* get_header()/get_footer() or render the wrapper hooks.
|
||||
*
|
||||
* @package WcBootstrap
|
||||
* @since 0.1.0
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Hook: woocommerce_before_main_content.
|
||||
*
|
||||
* @hooked woocommerce_output_content_wrapper - 10 (outputs opening divs for the content)
|
||||
* @hooked woocommerce_breadcrumb - 20
|
||||
*/
|
||||
do_action( 'woocommerce_before_main_content' );
|
||||
|
||||
while ( have_posts() ) {
|
||||
the_post();
|
||||
wc_get_template_part( 'content', 'single-product' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook: woocommerce_after_main_content.
|
||||
*
|
||||
* @hooked woocommerce_output_content_wrapper_end - 10 (outputs closing divs for the content)
|
||||
*/
|
||||
do_action( 'woocommerce_after_main_content' );
|
||||
Reference in New Issue
Block a user