fix: Detect shortcode on WooCommerce Shop page correctly

Problem: Customer SPA not loading on Shop page despite having [woonoow_shop] shortcode
Root Cause: WooCommerce Shop page is an archive page - when visiting /shop/, WordPress sets $post to the first product in the loop, not the Shop page itself. So shortcode check was checking product content instead of Shop page content.

Solution: Add special handling for is_shop() - get Shop page content directly using woocommerce_shop_page_id option and check for shortcode there.

Changes:
- Check is_shop() first before checking $post content
- Get Shop page via get_option('woocommerce_shop_page_id')
- Check shortcode on actual Shop page content
- Falls back to regular $post check for other pages

Result:
 Shop page shortcode detection now works correctly
 Customer SPA will load on Shop page with [woonoow_shop] shortcode
 Other WooCommerce pages (Cart, Checkout, Account) still work
This commit is contained in:
Dwindi Ramadhana
2025-12-30 18:02:48 +07:00
parent c8ce892d15
commit b2ac2996f9

View File

@@ -262,7 +262,19 @@ class Assets {
// If disabled, don't load // If disabled, don't load
if ($mode === 'disabled') { if ($mode === 'disabled') {
// Still check for shortcodes // Special handling for WooCommerce Shop page (it's an archive, not a regular post)
if (function_exists('is_shop') && is_shop()) {
$shop_page_id = get_option('woocommerce_shop_page_id');
if ($shop_page_id) {
$shop_page = get_post($shop_page_id);
if ($shop_page && has_shortcode($shop_page->post_content, 'woonoow_shop')) {
error_log('[WooNooW Customer] Found woonoow_shop shortcode on Shop page (ID: ' . $shop_page_id . ')');
return true;
}
}
}
// Check for shortcodes on regular pages
if ($post) { if ($post) {
error_log('[WooNooW Customer] Checking post content for shortcodes'); error_log('[WooNooW Customer] Checking post content for shortcodes');
error_log('[WooNooW Customer] Post content: ' . substr($post->post_content, 0, 200)); error_log('[WooNooW Customer] Post content: ' . substr($post->post_content, 0, 200));