From c2d093c2e538d4e0b4d05c0d3044e5f18253ed5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alda=20Vigd=C3=ADs=20Skarph=C3=A9=C3=B0insd=C3=B3ttir?= Date: Mon, 15 Jul 2024 18:59:46 +0200 Subject: [PATCH] Adding configuration options for variant support --- src/Config.php | 46 ++++++++++++++++ src/Hooks/Admin.php | 24 +++++---- src/Hooks/WooProductVariations.php | 43 ++++++++------- src/Rest/Settings.php | 18 +++++++ views/admin.php | 84 +++++++++++++++++++++++++++++- 5 files changed, 184 insertions(+), 31 deletions(-) diff --git a/src/Config.php b/src/Config.php index 4c696ab..51ae435 100644 --- a/src/Config.php +++ b/src/Config.php @@ -721,4 +721,50 @@ public static function set_international_customer_ledger_code( (string) $value ); } + + public static function get_use_attribute_description(): bool { + return (bool) ( + get_option( '1984_woo_dk_use_attribute_description', true ) + ); + } + + public static function set_use_attribute_description( bool $value ): bool { + return update_option( + '1984_woo_dk_use_attribute_description', + (bool) $value + ); + } + + public static function get_use_attribute_value_description(): bool { + return (bool) ( + get_option( '1984_woo_dk_use_attribute_value_description', true ) + ); + } + + public static function set_use_attribute_value_description( + bool $value + ): bool { + return update_option( + '1984_woo_dk_use_attribute_value_description', + (bool) $value + ); + } + + public static function get_product_convertion_to_variation_enabled(): bool { + return (bool) ( + get_option( + '1984_woo_dk_product_convertion_to_variation_enabled', + false + ) + ); + } + + public static function set_product_convertion_to_variation_enabled( + bool $value + ): bool { + return update_option( + '1984_woo_dk_product_convertion_to_variation_enabled', + (bool) $value + ); + } } diff --git a/src/Hooks/Admin.php b/src/Hooks/Admin.php index c9fa1f9..0333c99 100644 --- a/src/Hooks/Admin.php +++ b/src/Hooks/Admin.php @@ -49,18 +49,20 @@ public function __construct() { 10 ); - add_filter( - 'bulk_actions-edit-product', - array( __CLASS__, 'register_product_to_variant_bulk_action' ), - 10 - ); + if ( Config::get_product_convertion_to_variation_enabled() ) { + add_filter( + 'bulk_actions-edit-product', + array( __CLASS__, 'register_product_to_variant_bulk_action' ), + 10 + ); - add_filter( - 'handle_bulk_actions-edit-product', - array( __CLASS__, 'handle_product_to_variant_bulk_action' ), - 10, - 3 - ); + add_filter( + 'handle_bulk_actions-edit-product', + array( __CLASS__, 'handle_product_to_variant_bulk_action' ), + 10, + 3 + ); + } } /** diff --git a/src/Hooks/WooProductVariations.php b/src/Hooks/WooProductVariations.php index 77c47cd..df412d6 100644 --- a/src/Hooks/WooProductVariations.php +++ b/src/Hooks/WooProductVariations.php @@ -4,6 +4,7 @@ namespace NineteenEightyFour\NineteenEightyWoo\Hooks; +use NineteenEightyFour\NineteenEightyWoo\Config; use NineteenEightyFour\NineteenEightyWoo\Import\ProductVariations; use WC_Product_Variation; @@ -38,26 +39,30 @@ public function __construct() { 2 ); - add_filter( - 'woocommerce_variation_option_name', - array( __CLASS__, 'filter_variation_option_name' ), - 10, - 1 - ); - - add_filter( - 'woocommerce_attribute_label', - array( __CLASS__, 'filter_variation_label' ), - 10, - 3 - ); + if ( Config::get_use_attribute_value_description() ) { + add_filter( + 'woocommerce_variation_option_name', + array( __CLASS__, 'filter_variation_option_name' ), + 10, + 1 + ); + + add_filter( + 'woocommerce_order_item_display_meta_value', + array( __CLASS__, 'filter_woocommerce_order_meta_value' ), + 10, + 1 + ); + } - add_filter( - 'woocommerce_order_item_display_meta_value', - array( __CLASS__, 'filter_woocommerce_order_meta_value' ), - 10, - 1 - ); + if ( Config::get_use_attribute_description() ) { + add_filter( + 'woocommerce_attribute_label', + array( __CLASS__, 'filter_variation_label' ), + 10, + 3 + ); + } } /** diff --git a/src/Rest/Settings.php b/src/Rest/Settings.php index 209b9ac..ca6df31 100644 --- a/src/Rest/Settings.php +++ b/src/Rest/Settings.php @@ -266,6 +266,24 @@ public static function rest_api_callback( ); } + if ( property_exists( $rest_json, 'use_attribute_description' ) ) { + Config::set_use_attribute_description( + $rest_json->use_attribute_description + ); + } + + if ( property_exists( $rest_json, 'use_attribute_value_description' ) ) { + Config::set_use_attribute_value_description( + $rest_json->use_attribute_value_description + ); + } + + if ( property_exists( $rest_json, 'product_convertion_to_variation_enabled' ) ) { + Config::set_product_convertion_to_variation_enabled( + $rest_json->product_convertion_to_variation_enabled + ); + } + if ( property_exists( $rest_json, 'fetch_products' ) && $rest_json->fetch_products diff --git a/views/admin.php b/views/admin.php index 8e589d9..a08459a 100644 --- a/views/admin.php +++ b/views/admin.php @@ -164,6 +164,88 @@ class="regular-text api-key-input" +

+

+ +

+ + + + + + + + + + + + + + + +
+ + + /> + +

+ +

+
+ + + /> + +

+ +

+
+ + + /> + +

+ +

+