You've already forked wc-composable-product
Add custom page template for composable products, bump to v1.3.2
All checks were successful
All checks were successful
- 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:
@@ -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
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user