Settings
1 week ago
BlockHooks.php
1 week ago
BlockHooksFactory.php
1 week ago
Factory.php
1 year ago
Hooks.php
1 week ago
Strings.php
1 week ago
BlockHooks.php
41 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WCML\PaymentGateways; |
| 4 | |
| 5 | use Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry; |
| 6 | use WPML\LIB\WP\Hooks; |
| 7 | |
| 8 | use function WPML\FP\spreadArgs; |
| 9 | |
| 10 | class BlockHooks implements \IWPML_Action { |
| 11 | |
| 12 | private $woocommerce_wpml; |
| 13 | |
| 14 | public function __construct( \woocommerce_wpml $woocommerce_wpml ) { |
| 15 | $this->woocommerce_wpml = $woocommerce_wpml; |
| 16 | } |
| 17 | |
| 18 | public function add_hooks() { |
| 19 | Hooks::onAction( 'woocommerce_blocks_payment_method_type_registration', PHP_INT_MAX ) |
| 20 | ->then( spreadArgs( [ $this, 'translateSettings' ] ) ); |
| 21 | } |
| 22 | |
| 23 | public function translateSettings( $registry ) { |
| 24 | if ( $this->woocommerce_wpml->gateways instanceof \WCML_WC_Gateways ) { |
| 25 | foreach ( $registry->get_all_registered() as $gatewayId => $gateway ) { |
| 26 | Hooks::onFilter( 'option_woocommerce_' . $gatewayId . '_settings' ) |
| 27 | ->then( spreadArgs( function( $settings ) use ( $gatewayId ) { |
| 28 | foreach ( [ 'title', 'description' ] as $name ) { |
| 29 | if ( isset( $settings[ $name ] ) ) { |
| 30 | $settings[ $name ] = $this->woocommerce_wpml->gateways->get_translated_gateway_string( $settings[ $name ], $gatewayId, $name ); |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | return $settings; |
| 35 | } ) ); |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | } |
| 41 |