From ef654320093ddafc38f50bae6ec8aad4029e1847 Mon Sep 17 00:00:00 2001 From: vendidero Date: Wed, 13 Nov 2024 16:04:13 +0100 Subject: [PATCH] Register structured product data (GTIN, MPN). Patch Elementor Pro compatibility as the elementor-pro stylesheet doesn't exist in newest elementor version. --- .../class-wc-gzd-compatibility-elementor-pro.php | 2 +- woocommerce-germanized.php | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/includes/compatibility/class-wc-gzd-compatibility-elementor-pro.php b/includes/compatibility/class-wc-gzd-compatibility-elementor-pro.php index 1464d0ec..e26e7998 100644 --- a/includes/compatibility/class-wc-gzd-compatibility-elementor-pro.php +++ b/includes/compatibility/class-wc-gzd-compatibility-elementor-pro.php @@ -205,7 +205,7 @@ function ( $element ) { 'elementor/frontend/after_enqueue_styles', function () { wp_add_inline_style( - 'elementor-pro', + 'elementor-frontend', ' .elementor-widget-woocommerce-checkout-page .woocommerce table.woocommerce-checkout-review-order-table { margin: var(--sections-margin, 24px 0 24px 0); diff --git a/woocommerce-germanized.php b/woocommerce-germanized.php index 386e1ffb..9edf7d13 100644 --- a/woocommerce-germanized.php +++ b/woocommerce-germanized.php @@ -318,6 +318,7 @@ public function init() { add_action( 'wp_print_footer_scripts', array( $this, 'localize_scripts' ), 5 ); add_filter( 'woocommerce_locate_core_template', array( $this, 'email_templates' ), 0, 3 ); + add_filter( 'woocommerce_structured_data_product', array( $this, 'add_structured_product_data' ), 10, 2 ); // Payment gateways add_filter( 'woocommerce_payment_gateways', array( $this, 'register_gateways' ) ); @@ -1520,7 +1521,6 @@ public function add_emails( $mails ) { * @return string */ public function email_templates( $core_file, $template, $template_base ) { - if ( ! file_exists( $template_base . $template ) && file_exists( $this->plugin_path() . '/templates/' . $template ) ) { $core_file = $this->plugin_path() . '/templates/' . $template; } @@ -1539,7 +1539,6 @@ public function email_templates( $core_file, $template, $template_base ) { } public function register_gateways( $gateways ) { - // Do only load gateway for PHP >= 5.3 because of Namespaces if ( version_compare( phpversion(), '5.3', '>=' ) ) { $gateways[] = 'WC_GZD_Gateway_Direct_Debit'; @@ -1549,6 +1548,19 @@ public function register_gateways( $gateways ) { return $gateways; } + + public function add_structured_product_data( $markup, $product ) { + if ( $gzd_product = wc_gzd_get_gzd_product( $product ) ) { + if ( $gtin = $gzd_product->get_gtin() ) { + $markup['gtin'] = $gtin; + } + if ( $mpn = $gzd_product->get_mpn() ) { + $markup['mpn'] = $mpn; + } + } + + return $markup; + } } endif;