__( 'Shop Sidebar', 'flatsome' ), 'id' => 'shop-sidebar', 'before_widget' => '', 'before_title' => '', 'after_title' => '
', ) ); register_sidebar( array( 'name' => __( 'Product Sidebar', 'flatsome' ), 'id' => 'product-sidebar', 'before_widget' => '', 'before_title' => '', 'after_title' => '
', ) ); } add_action( 'widgets_init', 'flatsome_shop_widgets_init' ); /* Modify define(name, value)ault Shop Breadcrumbs */ function flatsome_woocommerce_breadcrumbs() { $home = (get_theme_mod('breadcrumb_home',1)) ? _x( 'Home', 'breadcrumb', 'woocommerce' ) : false; return array( 'delimiter' => '/', 'wrap_before' => '', 'before' => '', 'after' => '', 'home' => $home ); } add_filter( 'woocommerce_breadcrumb_defaults', 'flatsome_woocommerce_breadcrumbs' ); /** * Add default breadcrumbs. * * @see woocommerce_breadcrumb() */ add_action( 'flatsome_breadcrumb' , 'woocommerce_breadcrumb', 20 ); /* Update cart price */ function flatsome_header_add_to_cart_fragment( $fragments ) { ob_start(); ?> cart->get_cart_subtotal(); ?> cart->cart_contents_count; ?> <?php _e( 'Cart', 'woocommerce' ); ?> array( 'post'), 's' => get_search_query() ) ); $posts = array(); while ( have_posts() ) : the_post(); array_push($posts, $post->ID); endwhile; wp_reset_query(); // Get pages query_posts( array( 'post_type' => array( 'page'), 's' => get_search_query() ) ); $pages = array(); while ( have_posts() ) : the_post(); $wc_page = false; if($post->post_type == 'page'){ foreach (array('shop', 'cart', 'checkout', 'view_order', 'terms') as $wc_page_type) { if( $post->ID == wc_get_page_id($wc_page_type) ) $wc_page = true; } } if( !$wc_page ) array_push($pages, $post->ID); endwhile; wp_reset_query(); if ( ! empty( $posts ) ) { echo '

' . esc_html__( 'Posts found', 'flatsome' ) . '

'; echo flatsome_apply_shortcode( 'blog_posts', array( 'columns' => '3', 'columns__md' => '3', 'columns__sm' => '2', 'type' => get_theme_mod( 'search_result_style', 'slider' ), 'image_height' => '56.25%', 'show_date' => get_theme_mod( 'blog_badge', 1 ) ? 'true' : 'false', 'ids' => implode( ',', $posts ), ) ); } if ( ! empty( $pages ) ) { echo '

' . esc_html__( 'Pages found', 'flatsome' ) . '

'; echo flatsome_apply_shortcode( 'ux_pages', array( 'columns' => '3', 'columns__md' => '3', 'columns__sm' => '2', 'type' => get_theme_mod( 'search_result_style', 'slider' ), 'image_height' => '56.25%', 'ids' => implode( ',', $pages ), ) ); } ?> get_date_created(); if ( ! $datetime_created ) { return $html; } $timestamp_created = $datetime_created->getTimestamp(); $datetime_now = new WC_DateTime(); $timestamp_now = $datetime_now->getTimestamp(); $time_delta = $timestamp_now - $timestamp_created; $days = (int) get_theme_mod( 'new_bubble_auto' ); $days_in_seconds = 60 * 24 * 60 * $days; if ( $time_delta < $days_in_seconds ) { $html .= apply_filters( 'flatsome_new_flash_html', '
' . esc_html__( 'New', 'flatsome' ) . '
', $post, $product, $badge_style ); } return $html; } add_filter( 'flatsome_product_labels', 'flatsome_new_flash', 20, 4 ); /** * Calculates discount percentage for the product sale bubble for * simple, variable or external product types. Returns base bubble text * with or without formatting otherwise. * * @param WC_Product $product Product object. * @param string $text Default text. * * @return string */ function flatsome_presentage_bubble( $product, $text ) { $post_id = $product->get_id(); if ( $product->is_type( 'simple' ) || $product->is_type( 'external' ) || $product->is_type( 'variation' ) ) { $regular_price = $product->get_regular_price(); $sale_price = $product->get_sale_price(); $bubble_content = round( ( ( floatval( $regular_price ) - floatval( $sale_price ) ) / floatval( $regular_price ) ) * 100 ); } elseif ( $product->is_type( 'variable' ) ) { $bubble_content = flatsome_percentage_get_cache( $post_id ); if ( $bubble_content && apply_filters( 'flatsome_sale_bubble_percentage_cache_enabled', true ) ) { return flatsome_percentage_format( $bubble_content ); } $available_variations = $product->get_available_variations(); $maximumper = 0; for ( $i = 0; $i < count( $available_variations ); ++ $i ) { $variation_id = $available_variations[ $i ]['variation_id']; $variable_product = new WC_Product_Variation( $variation_id ); if ( ! $variable_product->is_on_sale() ) { continue; } $regular_price = $variable_product->get_regular_price(); $sale_price = $variable_product->get_sale_price(); $percentage = round( ( ( floatval( $regular_price ) - floatval( $sale_price ) ) / floatval( $regular_price ) ) * 100 ); if ( $percentage > $maximumper ) { $maximumper = $percentage; } } $bubble_content = sprintf( __( '%s', 'woocommerce' ), $maximumper ); // Cache percentage for variable products to reduce database queries. if ( apply_filters( 'flatsome_sale_bubble_percentage_cache_enabled', true ) ) { flatsome_percentage_set_cache( $post_id, $bubble_content ); } } else { // Return default if the product type doesn't meet specification. return $text; } return flatsome_percentage_format( $bubble_content ); } function flatsome_percentage_get_cache( $post_id ) { return get_post_meta( $post_id, '_flatsome_product_percentage', true ); } function flatsome_percentage_set_cache( $post_id, $bubble_content ) { update_post_meta( $post_id, '_flatsome_product_percentage', $bubble_content ); } // Process custom formatting. Keep mod value double check // to process % for default parameter (See sprintf()). function flatsome_percentage_format( $value ) { $formatting = get_theme_mod( 'sale_bubble_percentage_formatting' ); $formatting = $formatting ? $formatting : '-{value}%'; return str_replace( '{value}', $value, $formatting ); } // Clear cached percentage whenever a product or variation is saved. function flatsome_percentage_clear( $object ) { if ( ! get_theme_mod( 'sale_bubble_percentage' ) ) return; $post_id = 'variation' === $object->get_type() ? $object->get_parent_id() : $object->get_id(); delete_post_meta( $post_id, '_flatsome_product_percentage' ); } add_action( 'woocommerce_before_product_object_save', 'flatsome_percentage_clear' ); // Clear all cached percentages when disabling bubble percentage. function flatsome_percentage_clear_all( $value, $old_value ) { if ( ! $value && $old_value ) { delete_metadata( 'post', null, '_flatsome_product_percentage', '', true ); } return $value; } add_filter( 'pre_set_theme_mod_sale_bubble_percentage', 'flatsome_percentage_clear_all', 10, 2 ); // Account login style function flatsome_account_login_lightbox(){ // Show Login Lightbox if selected if ( !is_user_logged_in() && get_theme_mod('account_login_style','lightbox') == 'lightbox' && !is_checkout() && !is_account_page() ) { $is_facebook_login = is_nextend_facebook_login(); $is_google_login = is_nextend_google_login(); $layout = get_theme_mod( 'account_login_lightbox_layout' ); if ( empty( $layout ) && 'no' === get_option( 'woocommerce_registration_generate_password' ) ) { wp_enqueue_script( 'wc-password-strength-meter' ); } ?> _wp_specialchars( get_post_field( 'post_title', $attachment_id ), ENT_QUOTES, 'UTF-8', true ), 'data-caption' => _wp_specialchars( get_post_field( 'post_excerpt', $attachment_id ), ENT_QUOTES, 'UTF-8', true ), 'data-src' => esc_url( $full_src[0] ), 'data-large_image' => esc_url( $full_src[0] ), 'data-large_image_width' => esc_attr( $full_src[1] ), 'data-large_image_height' => esc_attr( $full_src[2] ), 'class' => esc_attr( $main_image ? 'wp-post-image skip-lazy' : 'skip-lazy' ), // skip-lazy, blacklist for Jetpack's lazy load. ), $attachment_id, $image_size, $main_image ) ); $image_wrapper_class = $main_image ? 'slide first' : 'slide'; return ''; } } /* Move demo store notice to top. */ function flatsome_move_store_notice() { if ( get_theme_mod( 'woocommerce_store_notice_top' ) ) { remove_action( 'wp_footer', 'woocommerce_demo_store' ); add_action ( 'flatsome_after_body_open', 'woocommerce_demo_store', 0 ); } } add_action( 'wp_loaded', 'flatsome_move_store_notice' ); /** * Filter WC Product shortcode attributes, * * @param array $attrs Attributes. * * @return array Attributes. */ function flatsome_filter_shortcode_atts_products( $attrs ) { if ( $attrs['limit'] == '-1' ) { $attrs['limit'] = '12'; } if ( $attrs['columns'] == '' ) { $attrs['columns'] = '4'; } return $attrs; } add_filter( 'shortcode_atts_products', 'flatsome_filter_shortcode_atts_products' ); /** * Flatsome Payment Icons List. * * Returns a list of Flatsome Payment Icons. * * @return array Payment Icons list. */ function flatsome_get_payment_icons_list() { return apply_filters( 'flatsome_payment_icons', array( 'amazon' => __( 'Amazon', 'flatsome-admin' ), 'americanexpress' => __( 'American Express', 'flatsome-admin' ), 'applepay' => __( 'Apple Pay', 'flatsome-admin' ), 'afterpay' => __( 'AfterPay', 'flatsome-admin' ), 'afterpay-2' => __( 'AfterPay 2', 'flatsome-admin' ), 'alipay' => __( 'Alipay', 'flatsome-admin' ), 'atm' => __( 'Atm', 'flatsome-admin' ), 'bancontact' => __( 'Bancontact', 'flatsome-admin' ), 'bankomat' => __( 'Bankomat', 'flatsome-admin' ), 'banktransfer' => __( 'Bank Transfer', 'flatsome-admin' ), 'belfius' => __( 'Belfius', 'flatsome-admin' ), 'bitcoin' => __( 'BitCoin', 'flatsome-admin' ), 'braintree' => __( 'Braintree', 'flatsome-admin' ), 'cartasi' => __( 'CartaSi', 'flatsome-admin' ), 'cashcloud' => __( 'CashCloud', 'flatsome-admin' ), 'cashondelivery' => __( 'Cash On Delivery', 'flatsome-admin' ), 'cashonpickup' => __( 'Cash on Pickup', 'flatsome-admin' ), 'cbc' => __( 'CBC', 'flatsome-admin' ), 'cirrus' => __( 'Cirrus', 'flatsome-admin' ), 'clickandbuy' => __( 'Click and Buy', 'flatsome-admin' ), 'creditcard' => __( 'Credit Card', 'flatsome-admin' ), 'creditcard2' => __( 'Credit Card 2', 'flatsome-admin' ), 'dancard' => __( 'DanKort', 'flatsome-admin' ), 'dinnersclub' => __( 'Dinners Club', 'flatsome-admin' ), 'discover' => __( 'Discover', 'flatsome-admin' ), 'elo' => __( 'Elo', 'flatsome-admin' ), 'eps' => __( 'Eps', 'flatsome-admin' ), 'facture' => __( 'Facture', 'flatsome-admin' ), 'fattura' => __( 'Fattura', 'flatsome-admin' ), 'flattr' => __( 'Flattr', 'flatsome-admin' ), 'giropay' => __( 'GiroPay', 'flatsome-admin' ), 'googlepay' => __( 'Google Pay', 'flatsome-admin' ), 'googlewallet' => __( 'Google Wallet', 'flatsome-admin' ), // Deprecated, changed to Google Pay. 'hiper' => __( 'Hiper', 'flatsome-admin' ), 'ideal' => __( 'IDeal', 'flatsome-admin' ), 'interac' => __( 'Interac', 'flatsome-admin' ), 'invoice' => __( 'Invoice', 'flatsome-admin' ), 'jcb' => __( 'JCB', 'flatsome-admin' ), 'kbc' => __( 'KBC', 'flatsome-admin' ), 'klarna' => __( 'Klarna', 'flatsome-admin' ), 'maestro' => __( 'Maestro', 'flatsome-admin' ), 'mastercard' => __( 'MasterCard', 'flatsome-admin' ), 'mastercard-2' => __( 'MasterCard 2', 'flatsome-admin' ), 'mir' => __( 'Mir', 'flatsome-admin' ), 'moip' => __( 'Moip', 'flatsome-admin' ), 'mollie' => __( 'Mollie', 'flatsome-admin' ), 'ogone' => __( 'Ogone', 'flatsome-admin' ), 'paybox' => __( 'Paybox', 'flatsome-admin' ), 'paylife' => __( 'Paylife', 'flatsome-admin' ), 'paymill' => __( 'PayMill', 'flatsome-admin' ), 'paypal' => __( 'PayPal', 'flatsome-admin' ), 'paypal-2' => __( 'PayPal 2', 'flatsome-admin' ), 'paysafe' => __( 'PaySafe', 'flatsome-admin' ), 'paysera' => __( 'Paysera', 'flatsome-admin' ), 'payshop' => __( 'PayShop', 'flatsome-admin' ), 'paytm' => __( 'Paytm', 'flatsome-admin' ), 'payu' => __( 'PayU', 'flatsome-admin' ), 'postepay' => __( 'Postepay', 'flatsome-admin' ), 'quick' => __( 'Quick', 'flatsome-admin' ), 'rechung' => __( 'Rechung', 'flatsome-admin' ), 'revolut' => __( 'Revolut', 'flatsome-admin' ), 'ripple' => __( 'Ripple', 'flatsome-admin' ), 'rupay' => __( 'RuPay', 'flatsome-admin' ), 'sage' => __( 'Sage', 'flatsome-admin' ), 'sepa' => __( 'Sepa', 'flatsome-admin' ), 'six' => __( 'Six', 'flatsome-admin' ), 'skrill' => __( 'Skrill', 'flatsome-admin' ), 'sofort' => __( 'Sofort', 'flatsome-admin' ), 'square' => __( 'Square', 'flatsome-admin' ), 'stripe' => __( 'Stripe', 'flatsome-admin' ), 'swish' => __( 'Swish (SE)', 'flatsome-admin' ), 'truste' => __( 'Truste', 'flatsome-admin' ), 'twint' => __( 'Twint', 'flatsome-admin' ), 'unionpay' => __( 'UnionPay', 'flatsome-admin' ), 'venmo' => __( 'Venmo', 'flatsome-admin' ), 'verisign' => __( 'VeriSign', 'flatsome-admin' ), 'vipps' => __( 'Vipps', 'flatsome-admin' ), 'visa' => __( 'Visa', 'flatsome-admin' ), 'visa1' => __( 'Visa 2', 'flatsome-admin' ), 'visaelectron' => __( 'Visa Electron', 'flatsome-admin' ), 'westernunion' => __( 'Western Union', 'flatsome-admin' ), 'wirecard' => __( 'Wirecard', 'flatsome-admin' ), ) ); } if ( flatsome_is_mini_cart_reveal() ) { /** * Adds a span tag with the "added-to-cart" class to Add to Cart notice to trigger auto reveal mini cart. * * @param string $message Default WooCommerce added to cart notice. * @param int $product_id Product id. * @return string The modified message. */ add_filter( 'wc_add_to_cart_message_html', function ( $message ) { $message .= ''; return $message; }); }