You've already forked wc-composable-product
Initial implementation of WooCommerce Composable Products plugin
Implemented custom WooCommerce product type allowing customers to build their own product bundles by selecting from predefined sets of products. Features: - Custom "Composable Product" type with admin interface - Product selection by category, tag, or SKU - Configurable selection limits (global and per-product) - Dual pricing modes: fixed price or sum of selected products - Modern responsive frontend with Twig templates - AJAX add-to-cart functionality - Full internationalization support (.pot file) - WooCommerce settings integration - Comprehensive documentation Technical implementation: - PHP 8.3+ with PSR-4 autoloading - Twig 3.0 templating engine via Composer - Vanilla JavaScript with jQuery for frontend interactions - WordPress and WooCommerce hooks for seamless integration - Security: input sanitization, validation, and output escaping - Translation-ready with text domain 'wc-composable-product' Documentation: - README.md: Project overview and features - INSTALL.md: Installation and usage guide - IMPLEMENTATION.md: Technical architecture - CHANGELOG.md: Version history 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
65
includes/Product_Selector.php
Normal file
65
includes/Product_Selector.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
/**
|
||||
* Product Selector
|
||||
*
|
||||
* @package WC_Composable_Product
|
||||
*/
|
||||
|
||||
namespace WC_Composable_Product;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Product Selector Class
|
||||
*
|
||||
* Handles rendering the product selection interface
|
||||
*/
|
||||
class Product_Selector {
|
||||
/**
|
||||
* Render product selector
|
||||
*
|
||||
* @param Product_Type $product Composable product
|
||||
*/
|
||||
public static function render($product) {
|
||||
if (!$product || $product->get_type() !== 'composable') {
|
||||
return;
|
||||
}
|
||||
|
||||
$available_products = $product->get_available_products();
|
||||
$selection_limit = $product->get_selection_limit();
|
||||
$pricing_mode = $product->get_pricing_mode();
|
||||
|
||||
$show_images = get_option('wc_composable_show_images', 'yes') === 'yes';
|
||||
$show_prices = get_option('wc_composable_show_prices', 'yes') === 'yes';
|
||||
$show_total = get_option('wc_composable_show_total', 'yes') === 'yes';
|
||||
|
||||
// Prepare product data for template
|
||||
$products_data = [];
|
||||
foreach ($available_products as $available_product) {
|
||||
$products_data[] = [
|
||||
'id' => $available_product->get_id(),
|
||||
'name' => $available_product->get_name(),
|
||||
'price' => $available_product->get_price(),
|
||||
'price_html' => $available_product->get_price_html(),
|
||||
'image_url' => wp_get_attachment_image_url($available_product->get_image_id(), 'thumbnail'),
|
||||
'permalink' => $available_product->get_permalink(),
|
||||
];
|
||||
}
|
||||
|
||||
$context = [
|
||||
'product_id' => $product->get_id(),
|
||||
'products' => $products_data,
|
||||
'selection_limit' => $selection_limit,
|
||||
'pricing_mode' => $pricing_mode,
|
||||
'show_images' => $show_images,
|
||||
'show_prices' => $show_prices,
|
||||
'show_total' => $show_total,
|
||||
'fixed_price' => $product->get_price(),
|
||||
'currency_symbol' => get_woocommerce_currency_symbol(),
|
||||
];
|
||||
|
||||
// Render template
|
||||
$plugin = Plugin::instance();
|
||||
echo $plugin->render_template('product-selector.twig', $context);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user