fix: plugin activation no longer modifies WooCommerce pages
- Removed shortcode replacement for Cart, Checkout, My Account pages - WooCommerce pages now keep their original [woocommerce_*] shortcodes - Plugin only creates dedicated SPA page (/store) with [woonoow_spa] - Auto-sets spa_page in appearance settings This aligns with template override approach - WC pages render normally when SPA is disabled, and redirect to SPA when mode is 'full'.
This commit is contained in:
@@ -23,100 +23,56 @@ class Installer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create or update WooNooW pages
|
||||
* Smart detection: reuses existing WooCommerce pages if they exist
|
||||
* Create WooNooW SPA page only
|
||||
* No longer modifies WooCommerce pages - we use template overrides instead
|
||||
*/
|
||||
private static function create_pages() {
|
||||
$pages = [
|
||||
'shop' => [
|
||||
'title' => 'Shop',
|
||||
'content' => '[woonoow_shop]',
|
||||
'wc_option' => 'woocommerce_shop_page_id',
|
||||
],
|
||||
'cart' => [
|
||||
'title' => 'Cart',
|
||||
'content' => '[woonoow_cart]',
|
||||
'wc_option' => 'woocommerce_cart_page_id',
|
||||
],
|
||||
'checkout' => [
|
||||
'title' => 'Checkout',
|
||||
'content' => '[woonoow_checkout]',
|
||||
'wc_option' => 'woocommerce_checkout_page_id',
|
||||
],
|
||||
'account' => [
|
||||
'title' => 'My Account',
|
||||
'content' => '[woonoow_account]',
|
||||
'wc_option' => 'woocommerce_myaccount_page_id',
|
||||
],
|
||||
];
|
||||
// Only create the main SPA page (Store)
|
||||
// WooCommerce pages are NOT modified - we use template overrides
|
||||
|
||||
foreach ($pages as $key => $page_data) {
|
||||
$page_id = null;
|
||||
$spa_page_id = get_option('woonoow_store_page_id');
|
||||
|
||||
// Strategy 1: Check if WooCommerce already has a page set
|
||||
if (isset($page_data['wc_option'])) {
|
||||
$wc_page_id = get_option($page_data['wc_option']);
|
||||
if ($wc_page_id && get_post($wc_page_id)) {
|
||||
$page_id = $wc_page_id;
|
||||
}
|
||||
}
|
||||
// Check if SPA page already exists
|
||||
if ($spa_page_id && get_post($spa_page_id)) {
|
||||
return; // Already exists
|
||||
}
|
||||
|
||||
// Strategy 2: Check if WooNooW already created a page
|
||||
if (!$page_id) {
|
||||
$woonoow_page_id = get_option('woonoow_' . $key . '_page_id');
|
||||
if ($woonoow_page_id && get_post($woonoow_page_id)) {
|
||||
$page_id = $woonoow_page_id;
|
||||
}
|
||||
}
|
||||
// Search for existing "Store" page
|
||||
$existing_page = get_page_by_title('Store', OBJECT, 'page');
|
||||
if ($existing_page) {
|
||||
$spa_page_id = $existing_page->ID;
|
||||
|
||||
// Strategy 3: Search for page by title
|
||||
if (!$page_id) {
|
||||
$existing_page = get_page_by_title($page_data['title'], OBJECT, 'page');
|
||||
if ($existing_page) {
|
||||
$page_id = $existing_page->ID;
|
||||
}
|
||||
}
|
||||
|
||||
// If page exists, update its content with our shortcode
|
||||
if ($page_id) {
|
||||
$current_post = get_post($page_id);
|
||||
|
||||
// Only update if it doesn't already have our shortcode
|
||||
if (!has_shortcode($current_post->post_content, 'woonoow_' . $key)) {
|
||||
// Backup original content
|
||||
update_post_meta($page_id, '_woonoow_original_content', $current_post->post_content);
|
||||
|
||||
// Update with our shortcode
|
||||
wp_update_post([
|
||||
'ID' => $page_id,
|
||||
'post_content' => $page_data['content'],
|
||||
]);
|
||||
|
||||
} else {
|
||||
}
|
||||
} else {
|
||||
// No existing page found, create new one
|
||||
$page_id = wp_insert_post([
|
||||
'post_title' => $page_data['title'],
|
||||
'post_content' => $page_data['content'],
|
||||
'post_status' => 'publish',
|
||||
'post_type' => 'page',
|
||||
'post_author' => get_current_user_id(),
|
||||
'comment_status' => 'closed',
|
||||
// Update with SPA shortcode if needed
|
||||
if (!has_shortcode($existing_page->post_content, 'woonoow_spa')) {
|
||||
update_post_meta($spa_page_id, '_woonoow_original_content', $existing_page->post_content);
|
||||
wp_update_post([
|
||||
'ID' => $spa_page_id,
|
||||
'post_content' => '[woonoow_spa]',
|
||||
]);
|
||||
|
||||
if ($page_id && !is_wp_error($page_id)) {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Create new SPA page
|
||||
$spa_page_id = wp_insert_post([
|
||||
'post_title' => 'Store',
|
||||
'post_content' => '[woonoow_spa]',
|
||||
'post_status' => 'publish',
|
||||
'post_type' => 'page',
|
||||
'post_author' => get_current_user_id() ?: 1,
|
||||
'comment_status' => 'closed',
|
||||
]);
|
||||
}
|
||||
|
||||
// Store page ID and update WooCommerce settings
|
||||
if ($page_id && !is_wp_error($page_id)) {
|
||||
update_option('woonoow_' . $key . '_page_id', $page_id);
|
||||
// Save SPA page ID
|
||||
if ($spa_page_id && !is_wp_error($spa_page_id)) {
|
||||
update_option('woonoow_store_page_id', $spa_page_id);
|
||||
|
||||
if (isset($page_data['wc_option'])) {
|
||||
update_option($page_data['wc_option'], $page_id);
|
||||
}
|
||||
// Also set it in appearance settings
|
||||
$appearance_settings = get_option('woonoow_appearance_settings', []);
|
||||
if (!isset($appearance_settings['general'])) {
|
||||
$appearance_settings['general'] = [];
|
||||
}
|
||||
$appearance_settings['general']['spa_page'] = $spa_page_id;
|
||||
update_option('woonoow_appearance_settings', $appearance_settings);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user