From 4979aa4d6322c183c6c479fa4a8eae7997d81655 Mon Sep 17 00:00:00 2001
From: vendidero
+ { _x( 'Sample safety instructions for a certain product.', 'preview', 'woocommerce-germanized' ) }
+
+ + +
+@@ -585,6 +590,7 @@ public static function save( $variation_id, $i ) { '_gtin' => '', '_mpn' => '', '_safety_attachment_ids' => '', + '_safety_instructions' => '', '_warranty_attachment_id' => '', '_nutrient_ids' => '', '_nutrient_reference_value' => '', diff --git a/includes/admin/meta-boxes/class-wc-germanized-meta-box-product-data.php b/includes/admin/meta-boxes/class-wc-germanized-meta-box-product-data.php index 92e2e8008..810c7c0fe 100644 --- a/includes/admin/meta-boxes/class-wc-germanized-meta-box-product-data.php +++ b/includes/admin/meta-boxes/class-wc-germanized-meta-box-product-data.php @@ -681,6 +681,24 @@ public static function output() { $manufacturer ) ); ?>
+@@ -982,6 +1000,7 @@ public static function get_fields() { '_defect_description' => '', '_warranty_attachment_id' => '', '_safety_attachment_ids' => '', + '_safety_instructions' => '', '_gtin' => '', '_mpn' => '', 'delivery_time' => '', @@ -1020,6 +1039,7 @@ protected static function get_field_sanitization_type( $field ) { '_food_place_of_origin', '_ingredients', '_defect_description', + '_safety_instructions', '_mini_desc', ); @@ -1361,6 +1381,10 @@ public static function save_product_data( &$product, $data, $is_variation = fals $gzd_product->set_defect_description( '' === $data['_defect_description'] ? '' : wc_gzd_sanitize_html_text_field( $data['_defect_description'] ) ); } + if ( isset( $data['_safety_instructions'] ) ) { + $gzd_product->set_safety_instructions( '' === $data['_safety_instructions'] ? '' : wc_gzd_sanitize_html_text_field( $data['_safety_instructions'] ) ); + } + if ( isset( $data['_nutrient_ids'] ) ) { $gzd_product->set_nutrient_ids( (array) wc_clean( $data['_nutrient_ids'] ) ); } diff --git a/includes/class-wc-gzd-product-variation.php b/includes/class-wc-gzd-product-variation.php index 348dc9933..574304b93 100644 --- a/includes/class-wc-gzd-product-variation.php +++ b/includes/class-wc-gzd-product-variation.php @@ -44,6 +44,7 @@ class WC_GZD_Product_Variation extends WC_GZD_Product { 'warranty_attachment_id', 'manufacturer_slug', 'safety_attachment_ids', + 'safety_instructions', 'gtin', 'mpn', 'deposit_type', diff --git a/includes/class-wc-gzd-shortcodes.php b/includes/class-wc-gzd-shortcodes.php index 5a7036210..890a99503 100644 --- a/includes/class-wc-gzd-shortcodes.php +++ b/includes/class-wc-gzd-shortcodes.php @@ -38,6 +38,7 @@ public static function init() { 'gzd_product_safety_information' => __CLASS__ . '::gzd_product_safety_information', 'gzd_product_manufacturer' => __CLASS__ . '::gzd_product_manufacturer', 'gzd_product_safety_attachments' => __CLASS__ . '::gzd_product_safety_attachments', + 'gzd_product_safety_instructions' => __CLASS__ . '::gzd_product_safety_instructions', 'gzd_product_deposit' => __CLASS__ . '::gzd_product_deposit', 'gzd_product_deposit_packaging_type' => __CLASS__ . '::gzd_product_deposit_packaging_type', 'gzd_email_legal_page_attachments' => __CLASS__ . '::gzd_email_legal_page_attachments', @@ -181,6 +182,18 @@ public static function gzd_product_safety_attachments( $atts ) { return apply_filters( 'woocommerce_gzd_shortcode_product_safety_attachments_html', self::get_gzd_product_shortcode( $atts, 'woocommerce_gzd_template_single_product_safety_attachments' ), $atts ); } + public static function gzd_product_safety_instructions( $atts ) { + /** + * Filter shortcode product safety instructions output. + * + * @param string $html The output. + * @param array $atts The shortcode arguments. + * + * @since 3.18.0 + */ + return apply_filters( 'woocommerce_gzd_shortcode_product_safety_instructions_html', self::get_gzd_product_shortcode( $atts, 'woocommerce_gzd_template_single_safety_instructions' ), $atts ); + } + public static function gzd_product_manufacturer( $atts ) { /** * Filter shortcode product manufacturer output. diff --git a/includes/export/class-wc-gzd-product-export.php b/includes/export/class-wc-gzd-product-export.php index a7700146c..cd5c25237 100644 --- a/includes/export/class-wc-gzd-product-export.php +++ b/includes/export/class-wc-gzd-product-export.php @@ -91,6 +91,7 @@ public function get_columns() { 'unit' => _x( 'Unit', 'exporter', 'woocommerce-germanized' ), 'manufacturer' => _x( 'Manufacturer', 'exporter', 'woocommerce-germanized' ), 'safety_attachment_ids' => _x( 'Safety attachments ids', 'exporter', 'woocommerce-germanized' ), + 'safety_instructions' => _x( 'Safety instructions', 'exporter', 'woocommerce-germanized' ), 'unit_base' => _x( 'Unit base', 'exporter', 'woocommerce-germanized' ), 'unit_product' => _x( 'Unit product', 'exporter', 'woocommerce-germanized' ), 'mini_desc' => _x( 'Cart description', 'exporter', 'woocommerce-germanized' ), @@ -242,7 +243,7 @@ public function export_column( $value, $product ) { $filter = current_filter(); $column_name = str_replace( 'woocommerce_product_export_product_column_', '', $filter ); $gzd_product = wc_gzd_get_product( $product ); - $is_html_field = in_array( $column_name, array( 'ingredients', 'food_description', 'food_place_of_origin', 'food_distributor', 'defect_description', 'mini_desc' ), true ); + $is_html_field = in_array( $column_name, array( 'ingredients', 'food_description', 'food_place_of_origin', 'food_distributor', 'defect_description', 'mini_desc', 'safety_instructions' ), true ); /** * Delivery time needs special handling diff --git a/includes/import/class-wc-gzd-product-import.php b/includes/import/class-wc-gzd-product-import.php index f049cb960..a1a1044ad 100644 --- a/includes/import/class-wc-gzd-product-import.php +++ b/includes/import/class-wc-gzd-product-import.php @@ -71,6 +71,7 @@ public function get_formatting_callbacks() { array( 'mini_desc' => array( $this, 'parse_html_field' ), 'defect_description' => array( $this, 'parse_html_field' ), + 'safety_instructions' => array( $this, 'parse_html_field' ), 'unit_price_regular' => 'wc_format_decimal', 'unit_price_sale' => 'wc_format_decimal', 'unit_base' => 'wc_format_decimal', diff --git a/includes/wc-gzd-template-functions.php b/includes/wc-gzd-template-functions.php index 560f71216..e4ec435b4 100644 --- a/includes/wc-gzd-template-functions.php +++ b/includes/wc-gzd-template-functions.php @@ -129,6 +129,20 @@ function woocommerce_gzd_template_single_manufacturer( $args = array() ) { } } +if ( ! function_exists( 'woocommerce_gzd_template_single_safety_instructions' ) ) { + + function woocommerce_gzd_template_single_safety_instructions( $args = array() ) { + $args = wp_parse_args( + $args, + array( + 'print_title' => true, + ) + ); + + wc_get_template( 'single-product/safety-instructions.php', $args ); + } +} + if ( ! function_exists( 'woocommerce_gzd_template_product_rating_authenticity_status_loop' ) ) { function woocommerce_gzd_template_product_rating_authenticity_status_loop() { global $product; @@ -815,6 +829,7 @@ function woocommerce_gzd_add_variation_options( $options, $product, $variation ) 'product_safety_attachments' => $gzd_product->get_product_safety_attachments_html(), 'has_product_safety_information' => $gzd_product->has_product_safety_information(), 'manufacturer' => $gzd_product->get_manufacturer_html(), + 'safety_instructions' => $gzd_product->get_formatted_safety_instructions(), 'is_food' => $gzd_product->is_food() ? 'yes' : 'no', 'food_description' => $gzd_product->is_food() ? $gzd_product->get_formatted_food_description() : '', 'food_place_of_origin' => $gzd_product->is_food() ? $gzd_product->get_formatted_food_place_of_origin() : '', @@ -849,6 +864,10 @@ function woocommerce_gzd_add_variation_options( $options, $product, $variation ) if ( ! empty( $options['product_safety_attachments'] ) ) { $options['product_safety_attachments_heading'] = esc_html( apply_filters( 'woocommerce_gzd_product_safety_attachments_heading', __( 'Product safety documents', 'woocommerce-germanized' ) ) ); } + + if ( $gzd_product->get_safety_instructions() ) { + $options['safety_instructions_heading'] = esc_html( apply_filters( 'woocommerce_gzd_product_safety_instructions_heading', __( 'Safety instructions', 'woocommerce-germanized' ) ) ); + } } return $options; diff --git a/src/Blocks/BlockTypes/ProductSafetyInstructions.php b/src/Blocks/BlockTypes/ProductSafetyInstructions.php new file mode 100644 index 000000000..11ba6449f --- /dev/null +++ b/src/Blocks/BlockTypes/ProductSafetyInstructions.php @@ -0,0 +1,29 @@ +get_formatted_safety_instructions(); + } +} diff --git a/src/Blocks/BlockTypesController.php b/src/Blocks/BlockTypesController.php index 36b84b2a6..3feb57f0f 100644 --- a/src/Blocks/BlockTypesController.php +++ b/src/Blocks/BlockTypesController.php @@ -53,6 +53,7 @@ protected function get_block_types() { 'ProductDefectDescription', 'ProductManufacturer', 'ProductSafetyAttachments', + 'ProductSafetyInstructions', ); if ( \Vendidero\Germanized\Package::is_pro() ) { diff --git a/src/Blocks/Products.php b/src/Blocks/Products.php index a68b3b74c..f459cba98 100644 --- a/src/Blocks/Products.php +++ b/src/Blocks/Products.php @@ -227,6 +227,7 @@ private function register_endpoint_data() { 'delivery_time_html' => $html_formatter->format( $gzd_product->get_delivery_time_html() ), 'manufacturer_html' => $html_formatter->format( $gzd_product->get_manufacturer_html() ), 'product_safety_attachments_html' => $html_formatter->format( $gzd_product->get_product_safety_attachments_html() ), + 'safety_instructions_html' => $html_formatter->format( $gzd_product->get_formatted_safety_instructions() ), 'tax_info_html' => $html_formatter->format( $gzd_product->get_tax_info() ), 'shipping_costs_info_html' => $html_formatter->format( $gzd_product->get_shipping_costs_html() ), 'defect_description_html' => $html_formatter->format( $gzd_product->get_formatted_defect_description() ), @@ -369,6 +370,12 @@ private function register_endpoint_data() { 'context' => array( 'view', 'edit' ), 'readonly' => true, ), + 'safety_instructions_html' => array( + 'description' => __( 'Safety instructions formatted as HTML.', 'woocommerce-germanized' ), + 'type' => 'string', + 'context' => array( 'view', 'edit' ), + 'readonly' => true, + ), 'nutri_score' => array( 'description' => __( 'Nutri score.', 'woocommerce-germanized' ), 'type' => 'string', diff --git a/src/Shopmarks.php b/src/Shopmarks.php index 50c052a09..c3011c884 100644 --- a/src/Shopmarks.php +++ b/src/Shopmarks.php @@ -59,6 +59,11 @@ protected static function register_single_product() { 'default_priority' => 11, 'callback' => 'woocommerce_gzd_template_single_product_safety_attachments', ), + 'safety_instructions' => array( + 'default_filter' => 'woocommerce_gzd_single_product_safety_information', + 'default_priority' => 12, + 'callback' => 'woocommerce_gzd_template_single_safety_instructions', + ), 'defect_description' => array( 'default_filter' => 'woocommerce_single_product_summary', 'default_priority' => 21, @@ -796,6 +801,7 @@ public static function get_types( $location = 'single_product' ) { 'nutri_score' => _x( 'Nutri-Score', 'shopmark', 'woocommerce-germanized' ), 'manufacturer' => _x( 'Manufacturer', 'shopmark', 'woocommerce-germanized' ), 'product_safety_attachments' => _x( 'Product safety attachments', 'shopmark', 'woocommerce-germanized' ), + 'safety_instructions' => _x( 'Safety instructions', 'shopmark', 'woocommerce-germanized' ), ), 'single_product_grouped' => array( 'unit_price' => _x( 'Unit Price', 'shopmark', 'woocommerce-germanized' ), diff --git a/templates/single-product/product-safety-attachments.php b/templates/single-product/product-safety-attachments.php index 115a093f1..5b9683b81 100644 --- a/templates/single-product/product-safety-attachments.php +++ b/templates/single-product/product-safety-attachments.php @@ -12,25 +12,26 @@ * * @see https://github.com/vendidero/woocommerce-germanized/wiki/Overriding-Germanized-Templates * @package Germanized/Templates - * @version 3.17.5 + * @version 3.18.5 */ if ( ! defined( 'ABSPATH' ) ) { exit; } // Exit if accessed directly global $product; +$heading = apply_filters( 'woocommerce_gzd_product_product_safety_attachments_heading', __( 'Product safety documents', 'woocommerce-germanized' ) ); ?> get_product_safety_attachments_html() ) : ?> - -
+ + is_type( 'variable' ) ) : ?> - + diff --git a/templates/single-product/product-safety.php b/templates/single-product/product-safety.php index d11c30f54..f94dc7f31 100644 --- a/templates/single-product/product-safety.php +++ b/templates/single-product/product-safety.php @@ -12,24 +12,25 @@ * * @see https://github.com/vendidero/woocommerce-germanized/wiki/Overriding-Germanized-Templates * @package Germanized/Templates - * @version 3.18.0 + * @version 3.18.5 */ if ( ! defined( 'ABSPATH' ) ) { exit; } // Exit if accessed directly global $product; +$heading = apply_filters( 'woocommerce_gzd_product_safety_heading', __( 'Product safety', 'woocommerce-germanized' ) ); ?> has_product_safety_information() ) : ?> - - + + is_type( 'variable' ) ) : ?> - - + + diff --git a/templates/single-product/safety-instructions.php b/templates/single-product/safety-instructions.php new file mode 100644 index 000000000..be94f5286 --- /dev/null +++ b/templates/single-product/safety-instructions.php @@ -0,0 +1,39 @@ + + +get_formatted_safety_instructions() ) : ?> + + + + +