__( 'Shop Sidebar', 'flatsome' ),
'id' => 'shop-sidebar',
'before_widget' => '',
'before_title' => '
',
) );
register_sidebar( array(
'name' => __( 'Product Sidebar', 'flatsome' ),
'id' => 'product-sidebar',
'before_widget' => '',
'before_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->get_cart_contents_count(); ?>
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' );
}
?>
get_title(), $main_image, $image_index ) : $alt_text;
}
if ( empty( $full_src ) ) {
return '';
}
/**
* Filters the attributes for the image markup.
*
* @since 3.3.2
*
* @param array $image_attributes Attributes for the image markup.
*/
$image_params = apply_filters(
'woocommerce_gallery_image_html_attachment_image_params',
array(
'title' => _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' : '' ),
'alt' => esc_attr( $alt_text ),
),
$attachment_id,
$image_size,
$main_image
);
if ( isset( $image_params['title'] ) ) {
unset( $image_params['title'] );
}
$image = wp_get_attachment_image(
$attachment_id,
$image_size,
false,
$image_params
);
$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 ( ! isset( $attrs['limit'] ) || $attrs['limit'] == '-1' ) {
$attrs['limit'] = '12';
}
if ( ! isset( $attrs['columns'] ) || $attrs['columns'] == '' ) {
$attrs['columns'] = '4';
}
return $attrs;
}
add_filter( 'shortcode_atts_products', 'flatsome_filter_shortcode_atts_products' );
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;
});
}
/**
* Get HTML for ratings.
*
* @see wc_get_rating_html()
*/
function flatsome_get_rating_html( $rating, $count = 0, $single_product = false ) {
global $product;
$review_count = $product->get_review_count();
$label = sprintf( __( 'Rated %s out of 5', 'woocommerce' ), $rating ); // phpcs:ignore WordPress.WP.I18n.MissingTranslatorsComment
$html = '';
if ( $rating > 0 ) {
if ( $single_product ) {
$style = get_theme_mod( 'product_info_review_count_style', 'inline' );
// Default to 'simple' when review count visibility is disabled.
$style = get_theme_mod( 'product_info_review_count' ) ? $style : 'simple';
switch ( $style ) {
case 'tooltip':
$title = sprintf( _n( '%s customer review', '%s customer reviews', $review_count, 'woocommerce' ), $review_count ); // phpcs:ignore WordPress.WP.I18n.MissingTranslatorsComment
$html = '';
$html .= '';
$html .= wc_get_star_rating_html( $rating, $count );
$html .= '
';
$html .= '';
break;
case 'inline':
$html = '';
$html .= wc_get_star_rating_html( $rating, $count );
$html .= '
';
break;
case 'stacked':
$html = '';
$html .= wc_get_star_rating_html( $rating, $count );
$html .= '
';
break;
case 'simple':
$html = '';
$html .= '';
$html .= wc_get_star_rating_html( $rating, $count );
$html .= '
';
$html .= '';
break;
}
} else {
$html = '';
$html .= wc_get_star_rating_html( $rating, $count );
$html .= '
';
}
}
return apply_filters( 'woocommerce_product_get_rating_html', $html, $rating, $count );
}