HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux wordpress-ubuntu-s-2vcpu-4gb-fra1-01 5.4.0-169-generic #187-Ubuntu SMP Thu Nov 23 14:52:28 UTC 2023 x86_64
User: root (0)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/dinamo-shop/wp-content/plugins/woocommerce-multilingual/classes/Tax/Strings/Hooks.php
<?php

namespace WCML\Tax\Strings;

use IWPML_Backend_Action;
use IWPML_Frontend_Action;

class Hooks implements IWPML_Backend_Action, IWPML_Frontend_Action {

	const STRINGS_CONTEXT = 'admin_texts_woocommerce_tax';

	public function add_hooks() {
		add_action( 'woocommerce_tax_rate_added', [ $this, 'registerLabelString' ], 10, 2 );
		add_action( 'woocommerce_tax_rate_updated', [ $this, 'registerLabelString' ], 10, 2 );
		add_filter( 'woocommerce_rate_label', [ $this, 'translateLabelString' ], 10, 2 );
	}

	/**
	 * @param string $label
	 * @param int $taxId
	 *
	 * @return string
	 */
	public function translateLabelString( $label, $taxId ) {

		$stringId = icl_get_string_id( $label, self::STRINGS_CONTEXT, $this->getStringName( $taxId ) );

		if ( ! $stringId ) {
			$this->migrateStringToTaxIdName( $taxId, $label );
		}

		return icl_translate( self::STRINGS_CONTEXT, $this->getStringName( $taxId ), $label );
	}

	/**
	 * @param int $taxId
	 * @param array $taxRate
	 */
	public function registerLabelString( $taxId, $taxRate ) {
		if ( ! empty( $taxRate['tax_rate_name'] ) ) {
			$this->registerString( $taxId, $taxRate['tax_rate_name'] );
		}
	}

	/**
	 * @param int $taxId
	 * @param string $label
	 *
	 * @return int
	 */
	private function registerString( $taxId, $label ) {
		return icl_register_string( self::STRINGS_CONTEXT, $this->getStringName( $taxId ), $label );
	}

	/**
	 * migration from WCML < 4.9.0
	 *
	 * @param int $taxId
	 * @param string $label
	 */
	private function migrateStringToTaxIdName( $taxId, $label ) {
		$newStringId = $this->registerString( $taxId, $label );

		$oldStringId = icl_get_string_id( $label, 'woocommerce taxes', $label );

		$oldStringTranslations = icl_get_string_translations_by_id( $oldStringId );

		foreach ( $oldStringTranslations as $languageCode => $translation ) {
			icl_add_string_translation(
				$newStringId,
				$languageCode,
				$translation['value'],
				ICL_STRING_TRANSLATION_COMPLETE
			);
		}
	}

	/**
	 * @param int $taxId
	 *
	 * @return string
	 */
	private function getStringName( $taxId ) {
		return 'tax_label_' . $taxId;
	}

}