default_currencies = $this->get_available_currencies(); parent::__construct(); } public function register_element( $elements = array() ) { $elements[ $this->element_id ] = array( 'id' => $this->element_id, 'title' => __( 'Currency', 'brandy' ), // 'settings' => $this->map_settings( $this->components ), 'builders' => $this->builders, 'icon' => ' ', ); return $elements; } protected function register_components() { $typo = TypographyService::get_default_typography_value(); return array( 'list_currencies' => array( 'value_path' => array( 'currencies' ), 'default_value' => $this->default_currencies, 'type' => 'ListCurrencies', ), 'currency_icon_enabled' => array( 'value_path' => array( 'currency_flag_enabled' ), 'title' => array( 'text' => __( 'Show currency flag', 'brandy' ), 'type' => 'bold', ), 'default_value' => true, 'type' => 'Switcher', 'render_options' => array( 'type' => 'variable', 'data' => array( array( 'type' => 'custom_variables', 'selector' => '.brandy-currency-flag', 'value_path' => array( 'currency_icon_enabled' ), 'mapping_variables' => array( array( 'condition' => array( 'value' => true, 'operator' => 'equal', ), 'path' => array(), 'mapping' => array( 'desktop' => array( 'display' => 'block', ), ), ), array( 'condition' => array( 'value' => false, 'operator' => 'equal', ), 'path' => array(), 'mapping' => array( 'desktop' => array( 'display' => 'none', ), ), ), ), ), ), ), ), 'currency_icon_position' => array( 'title' => array( 'text' => __( 'Icon Position', 'brandy' ), 'type' => 'normal', ), 'value_path' => array( 'currency_icon_position' ), 'type' => 'Position', 'default_value' => 'left', 'available_positions' => array( 'left', 'right' ), 'render_options' => array( 'type' => 'data_attribute', 'data' => array( array( 'selector' => '.brandy-currency-box', 'value_path' => array( 'currency_icon_position' ), 'name' => 'flag-position', ), ), ), ), 'arrow_icon_enabled' => array( 'value_path' => array( 'show_arrow_icon' ), 'title' => array( 'text' => __( 'Show arrow icon', 'brandy' ), 'type' => 'bold', ), 'default_value' => true, 'type' => 'Switcher', 'render_options' => array( 'type' => 'variable', 'data' => array( array( 'type' => 'custom_variables', 'selector' => '.brandy-currency-arrow', 'value_path' => array( 'show_arrow_icon' ), 'mapping_variables' => array( array( 'condition' => array( 'value' => true, 'operator' => 'equal', ), 'path' => array(), 'mapping' => array( 'desktop' => array( 'display' => 'block', ), ), ), array( 'condition' => array( 'value' => false, 'operator' => 'equal', ), 'path' => array(), 'mapping' => array( 'desktop' => array( 'display' => 'none', ), ), ), ), ), ), ), ), //design 'design_symbol_reset' => array( 'title' => array( 'text' => __( 'Currency flag', 'brandy' ), 'type' => 'bold', 'show_devices' => true, ), 'type' => 'Reset', 'reset_paths' => array( array( 'design_symbol' ), ), ), 'design_symbol_stroke_color' => array( 'title' => array( 'text' => __( 'Stroke color', 'brandy' ), 'type' => 'normal', ), 'value_path' => array( 'design_symbol', 'stroke', 'color' ), 'default_value' => array( 'normal' => array( 'desktop' => 'var(--wp--preset--color--brandy-secondary-text)', 'tablet' => null, 'mobile' => null, ), 'hover' => array( 'desktop' => 'var(--wp--preset--color--brandy-secondary-text)', 'tablet' => null, 'mobile' => null, ), ), 'type' => 'ColorGroup', 'render_options' => array( 'type' => 'variable', 'data' => array( array( 'type' => 'color', 'name' => '--b-symbol-stroke-color', 'value_path' => array( 'design_symbol', 'stroke', 'color' ), ), ), ), ), 'design_symbol_stroke_width' => array( 'title' => array( 'text' => __( 'Stroke width', 'brandy' ), 'type' => 'normal', ), 'value_path' => array( 'design_symbol', 'stroke', 'width' ), 'units' => array( 'px' ), 'default_value' => array( 'desktop' => array( 'unit' => 'px', 'min' => 0, 'max' => 20, 'value' => 0, ), 'tablet' => null, 'mobile' => null, ), 'type' => 'Dimension', 'render_options' => array( 'type' => 'variable', 'data' => array( array( 'type' => 'dimension', 'name' => '--b-symbol-stroke-width', 'value_path' => array( 'design_symbol', 'stroke', 'width' ), ), ), ), ), 'design_symbol_size' => array( 'title' => array( 'text' => __( 'Flag size', 'brandy' ), 'type' => 'normal', ), 'value_path' => array( 'design_symbol', 'size' ), 'default_value' => array( 'desktop' => ElementsLoader::get_default_icon_size(), 'tablet' => null, 'mobile' => null, ), 'type' => 'Dimension', 'render_options' => array( 'type' => 'variable', 'data' => array( array( 'type' => 'dimension', 'name' => '--b-symbol-size', 'value_path' => array( 'design_symbol', 'size' ), ), ), ), ), 'design_code_reset' => array( 'title' => array( 'text' => __( 'Currency code', 'brandy' ), 'type' => 'bold', 'show_devices' => true, ), 'type' => 'Reset', 'reset_paths' => array( array( 'design_code' ), ), ), 'design_code_typography' => array( 'value_path' => array( 'design_code', 'typography' ), 'title' => array( 'text' => 'Typography', 'type' => 'normal', ), 'default_value' => null, 'type' => 'Typography', 'is_responsive' => true, 'render_options' => array( 'type' => 'variable', 'data' => array( array( 'type' => 'typography', 'selector' => '.brandy-currency-name', 'value_path' => array( 'design_code', 'typography' ), ), ), ), ), 'design_code_text_color' => array( 'title' => array( 'text' => __( 'Text color', 'brandy' ), 'type' => 'normal', ), 'value_path' => array( 'design_code', 'text_color' ), 'default_value' => array( 'normal' => array( 'desktop' => 'var(--wp--preset--color--brandy-primary-text)', 'tablet' => null, 'mobile' => null, ), 'hover' => array( 'desktop' => 'var(--wp--preset--color--brandy-primary-text)', 'tablet' => null, 'mobile' => null, ), ), 'type' => 'ColorGroup', 'render_options' => array( 'type' => 'variable', 'data' => array( array( 'type' => 'color', 'name' => '--b-code-text-color', 'value_path' => array( 'design_code', 'text_color' ), ), ), ), ), 'design_arrow_icon_reset' => array( 'title' => array( 'text' => __( 'Icon arrow', 'brandy' ), 'type' => 'bold', 'show_devices' => true, ), 'type' => 'Reset', 'reset_paths' => array( array( 'design_arrow_icon' ), ), ), 'design_arrow_icon_color' => array( 'title' => array( 'text' => __( 'Icon color', 'brandy' ), 'type' => 'normal', ), 'value_path' => array( 'design_arrow_icon', 'color' ), 'default_value' => array( 'normal' => array( 'desktop' => 'var(--wp--preset--color--brandy-secondary-text)', 'tablet' => null, 'mobile' => null, ), 'hover' => array( 'desktop' => 'var(--wp--preset--color--brandy-secondary-text)', 'tablet' => null, 'mobile' => null, ), ), 'type' => 'ColorGroup', 'render_options' => array( 'type' => 'variable', 'data' => array( array( 'type' => 'color', 'name' => '--b-arrow-icon-color', 'value_path' => array( 'design_arrow_icon', 'color' ), ), ), ), ), 'design_arrow_icon_size' => array( 'title' => array( 'text' => __( 'Icon size', 'brandy' ), 'type' => 'normal', ), 'value_path' => array( 'design_arrow_icon', 'size' ), 'units' => array( 'px' ), 'default_value' => array( 'desktop' => ElementsLoader::get_default_icon_size( array( 'min' => 20 ) ), 'tablet' => null, 'mobile' => null, ), 'type' => 'Dimension', 'render_options' => array( 'type' => 'variable', 'data' => array( array( 'type' => 'dimension', 'name' => '--b-arrow-icon-size', 'value_path' => array( 'design_arrow_icon', 'size' ), ), ), ), ), 'design_item_spacing' => array( 'value_path' => array( 'design_item_spacing' ), 'title' => array( 'text' => 'Item Spacing', 'type' => 'bold', ), 'default_value' => array( 'desktop' => array( 'unit' => 'px', 'value' => 1, 'min' => 0, 'max' => 30, ), 'tablet' => null, 'mobile' => null, ), 'type' => 'Dimension', 'render_options' => array( 'type' => 'variable', 'data' => array( array( 'type' => 'dimension', 'selector' => '.brandy-currency-switcher__placeholder+.brandy-currency-options', 'name' => 'gap', 'value_path' => array( 'design_item_spacing' ), ), ), ), ), 'design_margin' => array( 'value_path' => array( 'design_margin' ), 'title' => array( 'text' => 'Margin', 'type' => 'bold', ), 'default_value' => array( 'unit' => 'px', 'top' => 0, 'right' => 0, 'bottom' => 0, 'left' => 0, 'is_constraints' => false, ), 'type' => 'Spacing', 'render_options' => array( 'type' => 'variable', 'data' => array( array( 'type' => 'spacing', 'selector' => '.brandy-currency-element', 'name' => 'margin', 'value_path' => array( 'design_margin' ), ), ), ), ), ); } public function add_layout( $layouts = array() ) { $layout = array( 'general' => array( 'sections' => array( array( 'components' => array( 'list_currencies', ), ), array( 'components' => array( 'currency_icon_enabled', 'currency_icon_position', ), ), array( 'components' => array( 'arrow_icon_enabled', ), ), ), ), 'designs' => array( 'sections' => array( array( 'components' => array( 'design_symbol_reset', // 'design_symbol_color', // 'design_symbol_bgcolor', 'design_symbol_stroke_color', 'design_symbol_stroke_width', 'design_symbol_size', ), ), array( 'components' => array( 'design_code_reset', 'design_code_typography', 'design_code_text_color', ), ), array( 'components' => array( 'design_arrow_icon_reset', 'design_arrow_icon_color', 'design_arrow_icon_size', ), ), array( 'components' => array( 'design_item_spacing', ), ), array( 'components' => array( 'design_margin', ), ), ), ), ); $mapped_layout = $this->map_layout( $layout ); $layouts[ $this->element_id ] = $mapped_layout; return $layouts; } public function add_localize_data( $localize_data ) { $localize_data['currency'] = array( 'list' => $this->get_available_currencies(), ); return $localize_data; } public function get_available_currencies() { if ( function_exists( 'get_woocommerce_currencies' ) && function_exists( 'get_woocommerce_currency_symbol' ) ) { $currency_code_options = get_woocommerce_currencies(); if ( class_exists( 'Yay_Currency\Helpers\Helper' ) ) { $yay_currencies = apply_filters( 'yay_currency_get_currencies_posts', \Yay_Currency\Helpers\Helper::get_currencies_post_type() ); } else { $yay_currencies = array(); } $res = array(); foreach ( $currency_code_options as $code => $name ) { foreach ( $yay_currencies as $yay_c ) { if ( $code == $yay_c->post_title ) { $res[] = array( 'id' => $code, 'name' => $name, 'flag' => self::get_currency_flag( $code ), 'symbol' => get_woocommerce_currency_symbol( $code ), 'yay_id' => $yay_c->ID, ); break; } } } return $res; } return array(); } public static function get_currency_flag( $code ) { $countries_code = array(); $flag = ''; if ( class_exists( '\Yay_Currency\Helpers\Helper' ) ) { if ( is_callable( array( '\Yay_Currency\Helpers\Helper', 'currency_code_by_country_code' ) ) ) { $countries_code = \Yay_Currency\Helpers\Helper::currency_code_by_country_code(); } $selected_country_code = $countries_code[ $code ]; if ( ! empty( $selected_country_code ) && is_callable( array( '\Yay_Currency\Helpers\Helper', 'get_flag_by_country_code' ) ) ) { $flag = \Yay_Currency\Helpers\Helper::get_flag_by_country_code( $selected_country_code ); } } return $flag; } }