Skip to content

Commit

Permalink
WPML compatibility patches.
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisnissle committed Nov 21, 2024
1 parent 2750a05 commit 6439511
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
34 changes: 20 additions & 14 deletions src/WPMLHelper.php → src/Compatibility/WPML.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
<?php

namespace Vendidero\Germanized\Shipments;
namespace Vendidero\Germanized\Shipments\Compatibility;

use Vendidero\Germanized\Shipments\Interfaces\Compatibility;
use Vendidero\Germanized\Shipments\ShippingProvider\Helper;
use Vendidero\Germanized\Shipments\ShippingProvider\Simple;
use WC_GZD_Compatibility_WPML;

defined( 'ABSPATH' ) || exit;

class WPMLHelper {
class WPML implements Compatibility {

private static $compatibility = false;

/**
* @param bool|WC_GZD_Compatibility_WPML $compatibility
*/
public static function init( $compatibility = false ) {
self::$compatibility = $compatibility;
public static function is_active() {
return defined( 'ICL_SITEPRESS_VERSION' );
}

public static function init() {
add_filter( 'woocommerce_gzd_wpml_email_ids', array( __CLASS__, 'register_emails' ), 10 );

/**
Expand All @@ -36,10 +33,20 @@ public static function init( $compatibility = false ) {
add_action( 'woocommerce_gzd_load_shipping_providers', array( __CLASS__, 'register_provider_filters' ) );
}

/**
* Translate shipment item name
*/
add_filter( 'woocommerce_gzd_email_shipment_items_args', array( __CLASS__, 'translate_email_shipment_items' ), 10 );
add_filter(
'woocommerce_gzd_shipments_shipping_method_shipping_classes',
function ( $shipping_classes ) {
$shipping_classes = array_map(
function ( $class_id ) {
return apply_filters( 'wpml_object_id', $class_id, 'category' );
},
$shipping_classes
);

return $shipping_classes;
}
);
}

public static function translate_email_shipment_items( $args ) {
Expand Down Expand Up @@ -99,7 +106,6 @@ public static function filter_shipping_provider_placeholder( $placeholder, $prov
* @param Simple $provider
*/
public static function register_shipping_provider_strings( $provider_id, $provider ) {

foreach ( self::get_shipping_provider_strings() as $string_name => $title ) {
$title = sprintf( $title, $provider->get_title() );
$getter = "get_{$string_name}";
Expand Down
6 changes: 1 addition & 5 deletions src/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ protected static function init_hooks() {
add_action( 'init', array( __CLASS__, 'check_version' ), 10 );
add_action( 'init', array( __CLASS__, 'load_fallback_compatibility' ) );

add_action( 'woocommerce_gzd_wpml_compatibility_loaded', array( __CLASS__, 'load_wpml_compatibility' ), 10 );
add_filter( 'woocommerce_shipping_method_add_rate_args', array( __CLASS__, 'manipulate_shipping_rates' ), 1000, 2 );
}

Expand Down Expand Up @@ -129,6 +128,7 @@ public static function load_compatibilities() {
array(
'bundles' => '\Vendidero\Germanized\Shipments\Compatibility\Bundles',
'shipment-tracking' => '\Vendidero\Germanized\Shipments\Compatibility\ShipmentTracking',
'wpml' => '\Vendidero\Germanized\Shipments\Compatibility\WPML',
)
);

Expand Down Expand Up @@ -205,10 +205,6 @@ public static function return_request_form( $args = array() ) {
return $html;
}

public static function load_wpml_compatibility( $compatibility ) {
WPMLHelper::init( $compatibility );
}

public static function get_method_settings( $force_load_all = false ) {
wc_deprecated_function( __FUNCTION__, '3.0.0', 'MethodHelper::get_method_settings()' );

Expand Down
2 changes: 1 addition & 1 deletion src/ShippingMethod/ShippingMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,7 @@ protected function rule_applies( $rule, $package_data, $global_only = false ) {
}
}
} elseif ( 'shipping_classes' === $condition_type_name || 'package_shipping_classes' === $condition_type_name ) {
$classes = isset( $condition['classes'] ) && ! empty( $condition['classes'] ) ? array_map( 'absint', (array) $condition['classes'] ) : array();
$classes = isset( $condition['classes'] ) && ! empty( $condition['classes'] ) ? apply_filters( 'woocommerce_gzd_shipments_shipping_method_shipping_classes', array_map( 'absint', (array) $condition['classes'] ) ) : array();

if ( 'exactly' === $operator_name ) {
$has_missing_shipping_classes = 'package_shipping_classes' === $condition_type_name ? $package_data['package_has_missing_shipping_classes'] : $package_data['has_missing_shipping_classes'];
Expand Down

0 comments on commit 6439511

Please sign in to comment.