diff --git a/includes/compatibility/class-wc-gzd-compatibility-google-for-woocommerce.php b/includes/compatibility/class-wc-gzd-compatibility-google-for-woocommerce.php new file mode 100644 index 00000000..a19166eb --- /dev/null +++ b/includes/compatibility/class-wc-gzd-compatibility-google-for-woocommerce.php @@ -0,0 +1,155 @@ +has_unit() && apply_filters( 'woocommerce_gzd_google_for_woocommerce_inject_unit_price', true, $product ) ) { + $base_measure = new ProductUnitPricingBaseMeasure(); + $base_measure->setUnit( $gzd_product->get_unit() ); + $base_measure->setValue( $gzd_product->get_unit_base() ); + + $measure = new ProductUnitPricingMeasure(); + $measure->setUnit( $gzd_product->get_unit() ); + $measure->setValue( $gzd_product->get_unit_product() ); + + $attributes['unitPricingMeasure'] = $measure; + $attributes['unitPricingBaseMeasure'] = $base_measure; + } + } + + return $attributes; + } + + public function register_mapping_source( $sources, $attribute_id ) { + if ( GTIN::get_id() === $attribute_id ) { + return array_merge( $this->get_mapping_gtin_sources(), $sources ); + } + + if ( MPN::get_id() === $attribute_id ) { + return array_merge( $this->get_mapping_mpn_sources(), $sources ); + } + + return $sources; + } + + /** + * @param $value + * @param WC_Product $product + * + * @return mixed|null + */ + public function get_mpn( $value, $product ) { + if ( strpos( $value, self::VALUE_KEY ) === 0 ) { + if ( $gzd_product = wc_gzd_get_gzd_product( $product ) ) { + if ( $mpn = $gzd_product->get_mpn() ) { + $value = $mpn; + } else { + $value = null; + } + } + } + + return ! empty( $value ) ? $value : null; + } + + /** + * @param $value + * @param WC_Product $product + * + * @return mixed|null + */ + public function get_gtin( $value, $product ) { + if ( strpos( $value, self::VALUE_KEY ) === 0 ) { + if ( $gzd_product = wc_gzd_get_gzd_product( $product ) ) { + if ( $gtin = $gzd_product->get_gtin() ) { + $value = $gtin; + } else { + $value = null; + } + } + } + + return ! empty( $value ) ? $value : null; + } + + public function register_option_group( $options ) { + $options[ self::VALUE_KEY ] = __( 'Germanized for WooCommerce', 'woocommerce-germanized' ); + + return $options; + } + + /** + * Load the GTIN Fields for Attribute mapping YOAST SEO + * + * @return array The GTIN sources + */ + protected function get_mapping_gtin_sources() { + return array_merge( self::get_mapping_group_source(), array( self::VALUE_KEY . ':gtin' => __( 'GTIN', 'woocommerce-germanized' ) ) ); + } + + /** + * Load the MPN Fields for Attribute mapping YOAST SEO + * + * @return array The MPN sources + */ + protected function get_mapping_mpn_sources() { + return array_merge( self::get_mapping_group_source(), array( self::VALUE_KEY . ':mpn' => __( 'MPN', 'woocommerce-germanized' ) ) ); + } + + /** + * Load the group disabled option for Attribute mapping YOAST SEO + * + * @return array The disabled group option + */ + protected function get_mapping_group_source() { + return array( 'disabled:' . self::VALUE_KEY => __( 'Germanized for WooCommerce', 'woocommerce-germanized' ) ); + } +} diff --git a/woocommerce-germanized.php b/woocommerce-germanized.php index 9edf7d13..d4ec2d2b 100644 --- a/woocommerce-germanized.php +++ b/woocommerce-germanized.php @@ -698,6 +698,7 @@ public function setup_compatibility() { 'erecht24' => 'WC_GZD_Compatibility_ERecht24', 'wc-dynamic-pricing-and-discounts' => 'WC_GZD_Compatibility_WC_Dynamic_Pricing_And_Discounts', 'cartflows' => 'WC_GZD_Compatibility_Cartflows', + 'google-for-woocommerce' => 'WC_GZD_Compatibility_Google_For_WooCommerce', ) );