2025-12-31 00:38:29 +01:00
|
|
|
<?php
|
2025-12-31 23:32:21 +01:00
|
|
|
|
2025-12-31 00:38:29 +01:00
|
|
|
/**
|
|
|
|
|
* Plugin Name: WooCommerce Composable Products
|
2025-12-31 23:32:21 +01:00
|
|
|
* Plugin URI: https://src.bundespruefstelle.ch/magdev/wc-composable-product
|
2025-12-31 00:38:29 +01:00
|
|
|
* Description: Create composable products where customers select a limited number of items from a configurable set
|
2026-03-01 14:08:44 +01:00
|
|
|
* Version: 1.3.2
|
2025-12-31 00:38:29 +01:00
|
|
|
* Author: Marco Graetsch
|
2025-12-31 23:32:21 +01:00
|
|
|
* Author URI: https://src.bundespruefstelle.ch/magdev
|
2025-12-31 00:38:29 +01:00
|
|
|
* License: GPL v3 or later
|
|
|
|
|
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
|
|
|
|
|
* Text Domain: wc-composable-product
|
|
|
|
|
* Domain Path: /languages
|
|
|
|
|
* Requires at least: 6.0
|
|
|
|
|
* Requires PHP: 8.3
|
|
|
|
|
* WC requires at least: 8.0
|
|
|
|
|
* WC tested up to: 10.0
|
|
|
|
|
*/
|
|
|
|
|
|
2026-03-01 13:25:02 +01:00
|
|
|
defined( 'ABSPATH' ) || exit;
|
2025-12-31 00:38:29 +01:00
|
|
|
|
|
|
|
|
// Define plugin constants
|
2026-03-01 14:08:44 +01:00
|
|
|
define( 'WC_COMPOSABLE_PRODUCT_VERSION', '1.3.2' );
|
2026-03-01 13:25:02 +01:00
|
|
|
define( 'WC_COMPOSABLE_PRODUCT_FILE', __FILE__ );
|
|
|
|
|
define( 'WC_COMPOSABLE_PRODUCT_PATH', plugin_dir_path( __FILE__ ) );
|
|
|
|
|
define( 'WC_COMPOSABLE_PRODUCT_URL', plugin_dir_url( __FILE__ ) );
|
|
|
|
|
define( 'WC_COMPOSABLE_PRODUCT_BASENAME', plugin_basename( __FILE__ ) );
|
2025-12-31 00:38:29 +01:00
|
|
|
|
|
|
|
|
// Load Composer autoloader
|
2026-03-01 13:25:02 +01:00
|
|
|
if ( file_exists( WC_COMPOSABLE_PRODUCT_PATH . 'vendor/autoload.php' ) ) {
|
|
|
|
|
require_once WC_COMPOSABLE_PRODUCT_PATH . 'vendor/autoload.php';
|
2025-12-31 00:38:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check if WooCommerce is active
|
|
|
|
|
*/
|
|
|
|
|
function wc_composable_product_check_woocommerce() {
|
2026-03-01 13:25:02 +01:00
|
|
|
if ( ! class_exists( 'WooCommerce' ) ) {
|
|
|
|
|
add_action(
|
|
|
|
|
'admin_notices',
|
|
|
|
|
function () {
|
|
|
|
|
?>
|
|
|
|
|
<div class="notice notice-error">
|
|
|
|
|
<p><?php esc_html_e( 'WooCommerce Composable Products requires WooCommerce to be installed and active.', 'wc-composable-product' ); ?></p>
|
|
|
|
|
</div>
|
|
|
|
|
<?php
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2025-12-31 00:38:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Initialize the plugin
|
|
|
|
|
*/
|
|
|
|
|
function wc_composable_product_init() {
|
2026-03-01 13:25:02 +01:00
|
|
|
if ( ! wc_composable_product_check_woocommerce() ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-12-31 00:38:29 +01:00
|
|
|
|
2026-03-01 13:25:02 +01:00
|
|
|
// Load text domain
|
|
|
|
|
load_plugin_textdomain( 'wc-composable-product', false, dirname( WC_COMPOSABLE_PRODUCT_BASENAME ) . '/languages' );
|
2025-12-31 00:38:29 +01:00
|
|
|
|
2026-03-01 13:25:02 +01:00
|
|
|
// Initialize main plugin class
|
|
|
|
|
Magdev\WcComposableProduct\Plugin::instance();
|
2025-12-31 00:38:29 +01:00
|
|
|
}
|
2025-12-31 16:50:35 +01:00
|
|
|
// Use woocommerce_init to ensure all WooCommerce classes including settings are loaded
|
2026-03-01 13:25:02 +01:00
|
|
|
add_action( 'woocommerce_init', 'wc_composable_product_init' );
|
2025-12-31 00:38:29 +01:00
|
|
|
|
2025-12-31 17:11:29 +01:00
|
|
|
/**
|
|
|
|
|
* Declare HPOS compatibility
|
|
|
|
|
*/
|
2026-03-01 13:25:02 +01:00
|
|
|
add_action(
|
|
|
|
|
'before_woocommerce_init',
|
|
|
|
|
function () {
|
|
|
|
|
if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
|
|
|
|
|
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
2025-12-31 17:11:29 +01:00
|
|
|
|
2025-12-31 00:38:29 +01:00
|
|
|
/**
|
|
|
|
|
* Activation hook
|
|
|
|
|
*/
|
|
|
|
|
function wc_composable_product_activate() {
|
2026-03-01 13:25:02 +01:00
|
|
|
if ( ! class_exists( 'WooCommerce' ) ) {
|
|
|
|
|
deactivate_plugins( WC_COMPOSABLE_PRODUCT_BASENAME );
|
|
|
|
|
wp_die(
|
|
|
|
|
esc_html__( 'This plugin requires WooCommerce to be installed and active.', 'wc-composable-product' ),
|
|
|
|
|
esc_html__( 'Plugin Activation Error', 'wc-composable-product' ),
|
|
|
|
|
array( 'back_link' => true )
|
|
|
|
|
);
|
|
|
|
|
}
|
2025-12-31 00:38:29 +01:00
|
|
|
}
|
2026-03-01 13:25:02 +01:00
|
|
|
register_activation_hook( __FILE__, 'wc_composable_product_activate' );
|