prefix . 'woonoow_software_versions'; if ($wpdb->get_var("SHOW TABLES LIKE '$table'") !== $table) { SoftwareManager::create_tables(); } } /** * Handle module enable */ public static function on_module_enabled($module_id) { if ($module_id === 'software') { SoftwareManager::create_tables(); } } /** * Add software distribution fields to product edit page */ public static function add_product_software_fields() { global $post; if (!ModuleRegistry::is_enabled('software')) { return; } // Check if licensing is enabled for this product $licensing_enabled = get_post_meta($post->ID, '_woonoow_licensing_enabled', true) === 'yes'; echo '
'; // Software Distribution section header echo '

' . esc_html__('Software Distribution', 'woonoow') . '

'; woocommerce_wp_checkbox([ 'id' => '_woonoow_software_enabled', 'label' => __('Enable Software Updates', 'woonoow'), 'description' => __('Allow customers to check for updates via API', 'woonoow'), ]); woocommerce_wp_text_input([ 'id' => '_woonoow_software_slug', 'label' => __('Software Slug', 'woonoow'), 'description' => __('Unique identifier (e.g., "my-plugin"). Used in update check API.', 'woonoow'), 'desc_tip' => true, 'placeholder' => 'my-software', ]); woocommerce_wp_text_input([ 'id' => '_woonoow_software_current_version', 'label' => __('Current Version', 'woonoow'), 'description' => __('Latest version number (e.g., "1.2.3")', 'woonoow'), 'desc_tip' => true, 'placeholder' => '1.0.0', ]); // WordPress Integration section echo '

' . esc_html__('WordPress Integration (Optional)', 'woonoow') . '

'; woocommerce_wp_checkbox([ 'id' => '_woonoow_software_wp_enabled', 'label' => __('WordPress Plugin/Theme', 'woonoow'), 'description' => __('Enable WordPress-specific update fields', 'woonoow'), ]); // WordPress-specific fields (shown via JS when checkbox is checked) echo '
'; woocommerce_wp_text_input([ 'id' => '_woonoow_software_requires_wp', 'label' => __('Requires WP', 'woonoow'), 'placeholder' => '6.0', ]); woocommerce_wp_text_input([ 'id' => '_woonoow_software_tested_wp', 'label' => __('Tested WP', 'woonoow'), 'placeholder' => '6.7', ]); woocommerce_wp_text_input([ 'id' => '_woonoow_software_requires_php', 'label' => __('Requires PHP', 'woonoow'), 'placeholder' => '7.4', ]); echo '
'; // .woonoow-wp-fields // Inline JS to toggle WP fields ?> '; // .options_group } /** * Save software distribution fields */ public static function save_product_software_fields($post_id) { // Software enabled $software_enabled = isset($_POST['_woonoow_software_enabled']) ? 'yes' : 'no'; update_post_meta($post_id, '_woonoow_software_enabled', $software_enabled); // Software slug if (isset($_POST['_woonoow_software_slug'])) { $slug = sanitize_title($_POST['_woonoow_software_slug']); update_post_meta($post_id, '_woonoow_software_slug', $slug); } // Current version if (isset($_POST['_woonoow_software_current_version'])) { $version = sanitize_text_field($_POST['_woonoow_software_current_version']); update_post_meta($post_id, '_woonoow_software_current_version', $version); } // WordPress integration $wp_enabled = isset($_POST['_woonoow_software_wp_enabled']) ? 'yes' : 'no'; update_post_meta($post_id, '_woonoow_software_wp_enabled', $wp_enabled); // WordPress-specific fields $wp_fields = [ '_woonoow_software_requires_wp', '_woonoow_software_tested_wp', '_woonoow_software_requires_php', ]; foreach ($wp_fields as $field) { if (isset($_POST[$field])) { update_post_meta($post_id, $field, sanitize_text_field($_POST[$field])); } } } }