diff --git a/src/Config.php b/src/Config.php index 294079d..4d5be1b 100644 --- a/src/Config.php +++ b/src/Config.php @@ -721,4 +721,91 @@ public static function set_international_customer_ledger_code( (string) $value ); } + + /** + * Get wether attribute descriptions from DK are used for variant product + * attributes in WooCommerce + * + * For example, the label tag on the product page can either have the + * attribute label set to the description from DK or its code. The code is + * however generally used internally. + */ + public static function get_use_attribute_description(): bool { + return (bool) ( + get_option( '1984_woo_dk_use_attribute_description', true ) + ); + } + + /** + * Set wether attribute descriptions from DK are used for variant product + * attributes in WooCommerce + * + * @param bool $value True to use attribute descriptions from DK, false to + * use the codes from DK instead. + */ + public static function set_use_attribute_description( bool $value ): bool { + return update_option( + '1984_woo_dk_use_attribute_description', + (bool) $value + ); + } + + /** + * Get wether attribute value descriptions from DK are used as the visible + * title for each attribute value + * + * For example inner contents of the option tags on the product page can + * either be the description or the code, with the value tag always being + * the code. The code is also used internally despite this value. + */ + public static function get_use_attribute_value_description(): bool { + return (bool) ( + get_option( '1984_woo_dk_use_attribute_value_description', true ) + ); + } + + /** + * Get wether attribute value descriptions from DK are used as the visible + * title for each attribute value + * + * @param bool $value True to use the description as the visible attribute + * value or false to use its code. + */ + public static function set_use_attribute_value_description( + bool $value + ): bool { + return update_option( + '1984_woo_dk_use_attribute_value_description', + (bool) $value + ); + } + + /** + * Get ether the product-to-variation conversion feature is enabled + * + * With this enabled, a bulk action to convert products into variations of + * another appears on the product overview page. + */ + public static function get_product_convertion_to_variation_enabled(): bool { + return (bool) ( + get_option( + '1984_woo_dk_product_convertion_to_variation_enabled', + false + ) + ); + } + + /** + * Enable to disable the product-to-variation conversion feature + * + * @param bool $value True to enable, false to disable. + */ + 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 6a20e35..d3a8aa7 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 4115c80..27cabcf 100644 --- a/views/admin.php +++ b/views/admin.php @@ -164,6 +164,88 @@ class="regular-text api-key-input" +

+

+ +

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

+ +

+
+ + + /> + +

+ +

+
+ + + /> + +

+ +

+