From cbcb53314ff5cb73dd7875e775f681aab44f7c98 Mon Sep 17 00:00:00 2001 From: Jasper Frumau Date: Sat, 20 Jun 2026 06:38:59 +0700 Subject: [PATCH] Add function_exists() guards for WooCommerce functions to prevent fatal errors Wraps all WooCommerce-specific function calls in functions.php with function_exists() checks so the theme works safely on sites without WooCommerce installed. Bumps version to 4.6.2. --- CHANGELOG.md | 11 +++++++++++ functions.php | 14 +++++++++++--- readme.txt | 7 ++++++- style.css | 2 +- 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 684800b..2e27356 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [4.6.2] - 2026-06-20 + +### Fixed + +**WooCommerce Function Guards:** +- Added `function_exists()` checks around all WooCommerce-specific functions in `functions.php` +- Prevents fatal errors on sites running Elayne without WooCommerce installed (e.g., aseonomics.com) +- Guards added to: `is_shop()`, `is_product_category()`, `is_product_tag()`, `is_product()`, `wc_get_product()`, `WC()` +- Category filter drawer script now safely skips enqueue when WooCommerce functions are unavailable +- Product structured data generation now validates `WC()->structured_data` exists before calling methods + ## [4.6.1] - 2026-06-16 ### Changed diff --git a/functions.php b/functions.php index da99c34..71a2d66 100644 --- a/functions.php +++ b/functions.php @@ -107,7 +107,11 @@ function elayne_enqueue_category_filter_drawer() { return; } // Load on shop page, product category archives, product tag archives, and any product taxonomy. - if ( is_shop() || is_product_category() || is_product_tag() || is_tax( 'product_cat' ) || is_tax( 'product_tag' ) ) { + if ( ( function_exists( 'is_shop' ) && is_shop() ) || + ( function_exists( 'is_product_category' ) && is_product_category() ) || + ( function_exists( 'is_product_tag' ) && is_product_tag() ) || + is_tax( 'product_cat' ) || + is_tax( 'product_tag' ) ) { wp_enqueue_script( 'elayne-category-filter-drawer', get_template_directory_uri() . '/assets/js/category-filter-drawer.js', @@ -137,13 +141,17 @@ function () { * output_structured_data() still runs on wp_footer. */ function elayne_add_product_structured_data() { - if ( ! is_product() ) { + if ( ! function_exists( 'is_product' ) || ! is_product() ) { + return; + } + + if ( ! function_exists( 'wc_get_product' ) ) { return; } $product = wc_get_product( get_the_ID() ); - if ( $product instanceof \WC_Product ) { + if ( $product instanceof \WC_Product && function_exists( 'WC' ) && isset( WC()->structured_data ) ) { WC()->structured_data->generate_product_data( $product ); } } diff --git a/readme.txt b/readme.txt index 7cacf53..ce30c92 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Tags: block-patterns, block-styles, blog, custom-colors, custom-logo, custom-men Requires at least: 6.6 Tested up to: 7.0 Requires PHP: 8.0 -Stable tag: 4.6.1 +Stable tag: 4.6.2 License: GNU General Public License v3.0 (or later) License URI: https://www.gnu.org/licenses/gpl-3.0.html @@ -174,6 +174,11 @@ Elayne includes custom image sizes optimized for different layouts: == Changelog == += 4.6.2 - 06/20/26 = +* FIXED: Added function_exists() guards around all WooCommerce functions to prevent fatal errors on non-WooCommerce sites. +* FIXED: Category filter drawer safely skips enqueue when WooCommerce is not active. +* FIXED: Product structured data generation validates WC() and structured_data availability before use. + = 4.6.1 - 06/16/26 = * CHANGED: Theme description rewritten for WordPress.org discoverability — leads with theme name, action-oriented copy, reordered selling points, added Global Styles callout and demo link. * FIXED: Pattern count in style.css description corrected from 110+ to 125+. diff --git a/style.css b/style.css index 60c6689..2b98bb5 100644 --- a/style.css +++ b/style.css @@ -7,7 +7,7 @@ Description: Elayne is a premium full-site-editing block theme for professional Requires at least: 6.6 Tested up to: 7.0 Requires PHP: 8.0 -Version: 4.6.1 +Version: 4.6.2 License: GNU General Public License v3 or later License URI: https://www.gnu.org/licenses/gpl-3.0.html Text Domain: elayne