Add custom page template for composable products, bump to v1.3.2
All checks were successful
Create Release Package / PHP Lint (push) Successful in 48s
Create Release Package / PHP CodeSniffer (push) Successful in 1m0s
Create Release Package / PHP Unit (push) Successful in 59s
Create Release Package / build-release (push) Successful in 1m4s

- Custom WooCommerce template with compact header + full-width selector
- Twig layout template (single-product-composable.html.twig) + PHP loader
- Body class 'single-product-composable' for CSS scoping
- Renamed *.twig to *.html.twig (proper naming convention)
- Refreshed .pot with accurate file refs, merged all .po files

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-01 14:08:44 +01:00
parent 8877ce976a
commit 3ac1e0d6f7
15 changed files with 2145 additions and 1568 deletions

View File

@@ -64,6 +64,10 @@ class Plugin {
// Admin settings
add_filter( 'woocommerce_get_settings_pages', array( $this, 'add_settings_page' ) );
// Custom page template for composable products
add_filter( 'wc_get_template_part', array( $this, 'override_single_product_template' ), 10, 3 );
add_filter( 'body_class', array( $this, 'add_composable_body_class' ) );
}
/**
@@ -224,6 +228,43 @@ class Plugin {
return $settings;
}
/**
* Override single product template for composable products
*
* @param string $template Template path
* @param string $slug Template slug
* @param string $name Template name
* @return string
*/
public function override_single_product_template( $template, $slug, $name ) {
if ( 'content' === $slug && 'single-product' === $name ) {
global $product;
if ( $product && $product->get_type() === 'composable' ) {
$custom_template = WC_COMPOSABLE_PRODUCT_PATH . 'templates/content-single-product-composable.php';
if ( file_exists( $custom_template ) ) {
return $custom_template;
}
}
}
return $template;
}
/**
* Add body class for composable product pages
*
* @param array $classes Body CSS classes
* @return array
*/
public function add_composable_body_class( $classes ) {
if ( is_product() ) {
global $product;
if ( $product && $product->get_type() === 'composable' ) {
$classes[] = 'single-product-composable';
}
}
return $classes;
}
/**
* Get Twig environment
*

View File

@@ -73,6 +73,6 @@ class ProductSelector {
// Render template — Twig handles escaping via registered esc_html/esc_attr/esc_url functions.
$plugin = Plugin::instance();
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- output escaped by Twig template.
echo $plugin->render_template( 'product-selector.twig', $context );
echo $plugin->render_template( 'product-selector.html.twig', $context );
}
}