software-license-manager/woocommerce/includes/hooks/slm-create-pages.php
Michel 3d6a5b3d10 Add new license renewal workflow and enhanced templates
Features:

Added new license renewal workflow to track historical orders and update associated_orders column for licenses.
Introduced improved handling for WooCommerce order IDs during license renewal.
Added new templates for license management, including renewal pages and license product display suggestions for empty carts.
Improvements:

Enhanced wc_slm_create_new_license to manage expiration dates, logging, and associated orders seamlessly.
Refactored license renewal logic to ensure existing orders are appended to the associated_orders column.
Improved database schema management for adding missing columns like associated_orders, ensuring backward compatibility and smoother upgrades.
Introduced structured retrieval of associated orders with the SLM_Utility::slm_get_associated_orders function to return well-formatted data.
Fixes:

Addressed metadata dependency by replacing _slm_lic_key usage with database lookups for better accuracy and reliability.
Fixed database version handling logic to ensure schema updates are properly applied during version upgrades.
Templates:

Added license cart template with suggested license products display for empty cart scenarios.
Included robust template structure to handle renewal messages and new license purchases dynamically.
Notes:

The new renewal workflow improves traceability by appending historical orders to the license's associated_orders.
Templates are designed to integrate seamlessly with WooCommerce workflows, providing a consistent user experience.
2024-11-25 15:03:33 -05:00

49 lines
1.6 KiB
PHP

<?php
/**
*
* Handles Page Creation
*/
if (!defined('ABSPATH')) {
exit;
}
/**
* Create License Cart page on plugin activation if it doesn't exist.
*/
function slm_create_license_cart_page() {
// Check if the License Cart page already exists
$query = new WP_Query(array(
'post_type' => 'page',
'name' => 'license-cart', // Check for the slug
'post_status' => 'publish',
'posts_per_page' => 1,
));
if (!$query->have_posts()) {
// Create the License Cart page
$page_id = wp_insert_post(array(
'post_title' => 'License Cart',
'post_content' => '', // Empty content for now
'post_status' => 'publish',
'post_type' => 'page',
'post_name' => 'license-cart', // Set the slug
'meta_input' => array('_wp_page_template' => 'page-license-cart.php'), // Assign the custom template
));
if ($page_id && !is_wp_error($page_id)) {
// Optionally, hide the page from menus/navigation
update_post_meta($page_id, '_menu_item_visibility', 'hidden');
error_log(__('License Cart page created successfully with ID: ', 'slm-plus') . $page_id);
} else {
error_log(__('Failed to create License Cart page.', 'slm-plus'));
}
} else {
error_log(__('License Cart page already exists.', 'slm-plus'));
}
}
/**
* Hook into plugin activation to create the License Cart page.
*/
register_activation_hook(__FILE__, 'slm_create_license_cart_page');