ultCurrency( $rate->$rateField, $rateSettings, $costName, $currency ); } } } return $rate->$rateField; } /** * @see \WCML\Multicurrency\Shipping\ShippingMode::isManualPricingEnabled * * @param \WC_Shipping_Rate $instance * * @return mixed */ public function isManualPricingEnabled( $instance ) { return self::isEnabled( $this->getWpOption( $this->getMethodId(), $instance->instance_id ) ); } /** * Returns shipping data from wp_options table. * * @param string $methodId * @param int $instanceId * * @return bool|mixed|void|null */ private function getWpOption( $methodId, $instanceId ) { return get_option( \WCML_Multi_Currency_Shipping::getShippingOptionName( $methodId, $instanceId ) ); } /** * Extracts numeric shipping class ID from shipping class key. * * @param string $key * * @return false|string Class ID or false if not found. */ private function getShippingClassTermId( $key ) { if ( preg_match( '/^class_cost_(\d*)(_[A-Z]*)*$/', $key, $matches ) && isset( $matches[1] ) ) { return $matches[1]; } return false; } /** * @param string $shippingClassKey * * @return string */ private function replaceShippingClassId( $shippingClassKey ) { $termId = $this->getShippingClassTermId( $shippingClassKey ); if ( $termId ) { $termTrid = apply_filters( 'wpml_element_trid', null, $termId, 'tax_product_shipping_class' ); $termTranslations = apply_filters( 'wpml_get_element_translations', null, $termTrid, 'tax_product_shipping_class' ); if ( is_array( $termTranslations ) ) { foreach ( $termTranslations as $translation ) { if ( $translation->source_language_code === null ) { $shippingClassKey = str_replace( $termId, $translation->element_id, $shippingClassKey ); break; } } } } return $shippingClassKey; } /** * Wrapper for getShippingClassTermId to avail testing private method. * * @param string $key * * @return bool|false|string */ public function _testGetShippingClassTermId( $key ) { if ( ! isset( $_SERVER['SCRIPT_NAME'] ) || stristr( $_SERVER['SCRIPT_NAME'], 'phpunit' ) === false ) { die( "don't run this method directly outside phpunit env" ); } return $this->getShippingClassTermId( $key ); } }