From c340d7b650c371d0c29da68392ee1f487d40aaa6 Mon Sep 17 00:00:00 2001 From: vendidero Date: Thu, 26 Sep 2024 11:44:10 +0200 Subject: [PATCH] Fix product factory usage to prevent error. Bump to 3.18.1. --- assets/js/static/add-to-cart-variation.js | 2 +- includes/wc-gzd-product-functions.php | 2 +- includes/wc-gzd-template-functions.php | 13 +++++++++++++ includes/wc-gzd-template-hooks.php | 1 + package.json | 2 +- readme.txt | 5 ++++- woocommerce-germanized.php | 21 +++++---------------- 7 files changed, 26 insertions(+), 20 deletions(-) diff --git a/assets/js/static/add-to-cart-variation.js b/assets/js/static/add-to-cart-variation.js index 47d9a866..af061e2d 100644 --- a/assets/js/static/add-to-cart-variation.js +++ b/assets/js/static/add-to-cart-variation.js @@ -50,7 +50,7 @@ }; GermanizedVariationForm.prototype.showOrHideTabs = function( self, has_product_safety_information = undefined ) { - has_product_safety_information = undefined === has_product_safety_information ? self.params.has_product_safety_information : has_product_safety_information; + has_product_safety_information = undefined === has_product_safety_information ? self.$product.hasClass( 'has-product-safety-information' ) : has_product_safety_information; if ( has_product_safety_information ) { self.$product.find( '.product_safety_tab' ).show().css( 'display', 'inline-block' ); diff --git a/includes/wc-gzd-product-functions.php b/includes/wc-gzd-product-functions.php index 516802e9..43b22dc2 100644 --- a/includes/wc-gzd-product-functions.php +++ b/includes/wc-gzd-product-functions.php @@ -67,7 +67,7 @@ function wc_gzd_get_gzd_product( $product ) { return $product; } - if ( ! $product ) { + if ( ! is_a( $product, 'WC_Product' ) ) { return false; } diff --git a/includes/wc-gzd-template-functions.php b/includes/wc-gzd-template-functions.php index 3cf3a486..0db93974 100644 --- a/includes/wc-gzd-template-functions.php +++ b/includes/wc-gzd-template-functions.php @@ -55,6 +55,19 @@ function woocommerce_gzd_template_product_review_authenticity_status( $comment ) } } +if ( ! function_exists( 'woocommerce_gzd_template_product_classes' ) ) { + + function woocommerce_gzd_template_product_classes( $classes, $product ) { + if ( $gzd_product = wc_gzd_get_gzd_product( $product ) ) { + if ( $gzd_product->has_product_safety_information() ) { + $classes[] = 'has-product-safety-information'; + } + } + + return $classes; + } +} + if ( ! function_exists( 'woocommerce_gzd_template_register_product_tabs' ) ) { function woocommerce_gzd_template_register_product_tabs( $tabs ) { diff --git a/includes/wc-gzd-template-hooks.php b/includes/wc-gzd-template-hooks.php index 175a966e..b2f5be22 100644 --- a/includes/wc-gzd-template-hooks.php +++ b/includes/wc-gzd-template-hooks.php @@ -151,6 +151,7 @@ function woocommerce_gzd_register_checkout_total_taxes() { * Product safety tab */ add_filter( 'woocommerce_product_tabs', 'woocommerce_gzd_template_register_product_tabs', 20 ); +add_filter( 'woocommerce_post_class', 'woocommerce_gzd_template_product_classes', 10, 2 ); // Small enterprises if ( wc_gzd_is_small_business() ) { diff --git a/package.json b/package.json index 693faf22..4e59df47 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "woocommerce-germanized", "title": "Germanized for WooCommerce", - "version": "3.18.0", + "version": "3.18.1", "homepage": "https://vendidero.de/woocommerce-germanized", "repository": { "type": "git", diff --git a/readme.txt b/readme.txt index d56d8874..528debc6 100644 --- a/readme.txt +++ b/readme.txt @@ -5,7 +5,7 @@ Requires at least: 5.4 Tested up to: 6.6 WC requires at least: 3.9 WC tested up to: 9.2 -Stable tag: 3.18.0 +Stable tag: 3.18.1 Requires PHP: 5.6 License: GPLv3 License URI: http://www.gnu.org/licenses/gpl-3.0.html @@ -205,6 +205,9 @@ Bug reports may be filed via our [GitHub repository](https://github.com/vendider 6. Edit pdf documents (Pro) == Changelog == += 3.18.1 = +* Fix: Product map caching issue + = 3.18.0 = * New: Compliance with new GPSR regulation * Improvement: Refactored shipments integration settings UI diff --git a/woocommerce-germanized.php b/woocommerce-germanized.php index f8b06c58..168a37b7 100644 --- a/woocommerce-germanized.php +++ b/woocommerce-germanized.php @@ -3,7 +3,7 @@ * Plugin Name: Germanized for WooCommerce * Plugin URI: https://www.vendidero.de/woocommerce-germanized * Description: Germanized for WooCommerce extends WooCommerce to become a legally compliant store in the german market. - * Version: 3.18.0 + * Version: 3.18.1 * Author: vendidero * Author URI: https://vendidero.de * Requires at least: 5.4 @@ -69,7 +69,7 @@ final class WooCommerce_Germanized { * * @var string */ - public $version = '3.18.0'; + public $version = '3.18.1'; /** * @var WooCommerce_Germanized $instance of the plugin @@ -1208,23 +1208,12 @@ public function get_variation_script_params() { } } - $has_product_safety_information = false; - - if ( is_singular( 'product' ) ) { - global $product; - - if ( $product && ( $gzd_product = wc_gzd_get_gzd_product( $product ) ) ) { - $has_product_safety_information = $gzd_product->has_product_safety_information(); - } - } - return apply_filters( 'woocommerce_gzd_add_to_cart_variation_params', array( - 'wrapper' => '.product', - 'has_safety_information' => $has_product_safety_information, - 'price_selector' => $price_selector, - 'replace_price' => true, + 'wrapper' => '.product', + 'price_selector' => $price_selector, + 'replace_price' => true, ) ); }