From ce0033f8df8a89f69dfdb7dafb4e910d686589fd Mon Sep 17 00:00:00 2001 From: Fabiano Mallmann <25328512+fabiano-mallmann@users.noreply.github.com> Date: Tue, 12 Nov 2024 15:00:52 -0300 Subject: [PATCH] fix: validate if checkoutblocks active --- src/Action/CustomerFieldsActions.php | 5 +++-- src/Helper/Utils.php | 11 +++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Action/CustomerFieldsActions.php b/src/Action/CustomerFieldsActions.php index 20be485f..e9ea00ae 100644 --- a/src/Action/CustomerFieldsActions.php +++ b/src/Action/CustomerFieldsActions.php @@ -91,8 +91,9 @@ public function addDocumentField(array $fields): array public function addDocumentFieldOnCheckoutBlocks() { if ( - $this->customerFields->hasCheckoutBlocksDocumentField() - || !function_exists('woocommerce_register_additional_checkout_field') + Utils::isCheckoutBlocksActive() && + ($this->customerFields->hasCheckoutBlocksDocumentField() + || !function_exists('woocommerce_register_additional_checkout_field')) ) { return; } diff --git a/src/Helper/Utils.php b/src/Helper/Utils.php index 776103c0..c37c5c51 100644 --- a/src/Helper/Utils.php +++ b/src/Helper/Utils.php @@ -677,4 +677,15 @@ public static function getRegisterScriptParameters(string $path, string $fileNam 'ver' => self::getScriptVersion($path, $fileName) ]; } + + /** + * @return bool + */ + public static function isCheckoutBlocksActive() + { + if (!class_exists('\Automattic\WooCommerce\Blocks\Utils\CartCheckoutUtils')) { + return false; + } + return \Automattic\WooCommerce\Blocks\Utils\CartCheckoutUtils::is_checkout_block_default(); + } }