set_settings(); add_action('etheme_after_mini_cart_footer', array($this, 'output')); add_action('etheme_elementor_header_off_canvas_footer_after', function ($widget_name) { if ( $widget_name == 'theme-etheme_cart') echo do_shortcode('[etheme_sales_booster_progress_bar force_load_assets="yes"]'); }); add_action('wp_enqueue_scripts', array($this, 'load_assets')); } public function load_assets() { wp_enqueue_script( 'cart_progress_bar'); } /** * @param array $custom_settings * @since 9.2.8 */ public function set_settings($custom_settings = array()) { $settings = (array)get_option('xstore_sales_booster_settings', array()); $default = array( 'message_text' => get_theme_mod( 'booster_progress_content_et-desktop', esc_html__( 'Spend {{et_price}} to get free shipping', 'xstore' ) ), 'process_icon' => get_theme_mod( 'booster_progress_icon_et-desktop', 'et_icon-delivery' ), 'process_icon_position' => get_theme_mod( 'booster_progress_icon_position_et-desktop', 'before' ) != 'after' ? 'before' : 'after', 'price' => get_theme_mod( 'booster_progress_price_et-desktop', 350 ), 'message_success_text' => get_theme_mod( 'booster_progress_content_success_et-desktop', esc_html__( 'Congratulations! You\'ve got free shipping.', 'xstore' ) ), 'success_icon' => get_theme_mod( 'booster_progress_success_icon_et-desktop', 'et_icon-star' ), 'success_icon_position' => get_theme_mod( 'booster_progress_success_icon_position_et-desktop', 'before' ), 'progress_bar_cart_ignore_discount' => 'yes', 'wrapper_classes' => array('woocommerce-mini-cart__footer'), 'force_load_assets' => false ); $local_settings = $default; if (count($settings) && isset($settings[self::$option_name])) { $local_settings = wp_parse_args( $settings[ self::$option_name ], $default ); } $this->settings = wp_parse_args( $custom_settings, $local_settings ); $this->settings = wp_parse_args( $custom_settings, $this->settings ); } /** * Output the content of payments. * @since 8.3.9 */ public function output() { if ( !self::$should_display ) return; if ( !apply_filters('etheme_sales_booster_progress_bar', true) ) return; $settings = apply_filters('et_'.self::$option_name.'_settings', $this->settings); // in case it was on different hook added where not refreshing by woocomerce ajax // wp_enqueue_script( 'cart_progress_bar'); if ( $settings['force_load_assets'] ) etheme_enqueue_style( 'sale-booster-cart-checkout-progress-bar', true ); $amount = ''; if ( ! wc_tax_enabled() ) { $amount = WC()->cart->cart_contents_total; } else { // $amount = WC()->cart->cart_contents_total + WC()->cart->tax_total; $amount = WC()->cart->get_displayed_subtotal(); } if ($settings['progress_bar_cart_ignore_discount'] == 'yes'){ $amount += WC()->cart->get_discount_total(); } $amount = apply_filters('et_progress_bar_amount', $amount); if ( class_exists('WCPay\MultiCurrency\MultiCurrency') ) { // $amount = WCPay\MultiCurrency\MultiCurrency::instance()->get_price($amount, 'exchange_rate'); $settings['price'] = WCPay\MultiCurrency\MultiCurrency::instance()->get_price($settings['price'], 'exchange_rate'); } $settings['price_diff'] = $settings['price'] - $amount; $settings['price_diff'] = $settings['price_diff'] > 0 ? $settings['price_diff'] : 0; $settings['cart_progress_bar_content'] = ''.wc_price($settings['price_diff']).''; $percent_sold = ($amount/$settings['price'])*100; $finished = false; if ( $amount >= $settings['price'] ) $finished = true; ?>