This commit is contained in:
nguyen dung
2022-02-18 16:43:41 +07:00
commit 39b8cb3612
4470 changed files with 1378320 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
<?php
// Move Cross sell product to under cart
remove_action( 'woocommerce_cart_collaterals', 'woocommerce_cross_sell_display' );
add_action( 'woocommerce_after_cart_table', 'woocommerce_cross_sell_display' );
// Add Content after Cart
if(!function_exists('flatsome_html_cart_footer')) {
function flatsome_html_cart_footer(){
$content = get_theme_mod('html_cart_footer');
echo '<div class="cart-footer-content after-cart-content relative">'.do_shortcode($content).'</div>';
}
add_action( 'woocommerce_after_cart', 'flatsome_html_cart_footer', 99);
}
// Add Content in cart sidebar
if(!function_exists('flatsome_html_cart_sidebar')) {
function flatsome_html_cart_sidebar(){
$content = get_theme_mod('html_cart_sidebar');
$icons = get_theme_mod('payment_icons_placement');
echo '<div class="cart-sidebar-content relative">'.do_shortcode($content).'</div>';
if(is_array($icons) && in_array('cart', $icons)) echo do_shortcode('[ux_payment_icons]');
}
add_action( 'flatsome_cart_sidebar', 'flatsome_html_cart_sidebar', 10);
}
// Continue Shopping button
if(!function_exists('flatsome_continue_shopping')) {
function flatsome_continue_shopping(){
wc_get_template_part('cart/continue-shopping');
}
}
add_action('woocommerce_cart_actions', 'flatsome_continue_shopping', 10);
// Move Privacy policy to bottom
function flatsome_fix_policy_text(){
if(function_exists('wc_checkout_privacy_policy_text')) {
remove_action( 'woocommerce_checkout_terms_and_conditions', 'wc_checkout_privacy_policy_text', 20 );
add_action( 'woocommerce_checkout_after_order_review', 'wc_checkout_privacy_policy_text', 1 );
}
}
add_action( 'init', 'flatsome_fix_policy_text', 10);

View File

@@ -0,0 +1,56 @@
<?php
function flatsome_body_classes_catalog_mode( $classes ) {
// Catalog mode
if(get_theme_mod('catalog_mode')) $classes[] = 'catalog-mode';
if(get_theme_mod('catalog_mode_prices')) $classes[] = 'no-prices';
return $classes;
}
add_filter( 'body_class', 'flatsome_body_classes_catalog_mode' );
function flatsome_catalog_mode_product(){
if(flatsome_option('catalog_mode_product')){
echo '<div class="catalog-product-text pb relative">';
echo do_shortcode(flatsome_option('catalog_mode_product'));
echo '</div>';
}
echo '<style>.woocommerce-variation-availability{display:none!important}</style>';
}
add_action('woocommerce_single_product_summary', 'flatsome_catalog_mode_product',30);
function flatsome_catalog_mode_lightbox(){
if(flatsome_option('catalog_mode_lightbox')) {
echo '<div class="catalog-product-text pb relative">';
echo do_shortcode(flatsome_option('catalog_mode_lightbox'));
echo '</div>';
}
echo '<style>.woocommerce-variation-availability{display:none!important}</style>';
}
add_action( 'woocommerce_single_product_lightbox_summary', 'flatsome_catalog_mode_lightbox', 30 );
/* Disable purchasing of products */
add_filter('woocommerce_is_purchasable', 'flatsome_woocommerce_is_purchasable', 10, 2);
function flatsome_woocommerce_is_purchasable($is_purchasable, $product) {
return false;
}
/* Remove variations add to cart */
remove_action( 'woocommerce_single_variation', 'woocommerce_single_variation_add_to_cart_button', 20);
/* Remove add to cart quick button */
remove_action( 'flatsome_product_box_actions', 'flatsome_product_box_actions_add_to_cart', 1 );
/* Remove prices from loop */
if(flatsome_option('catalog_mode_prices')) remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
/* Renove prices from product page */
if(flatsome_option('catalog_mode_prices')) remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
/* Remove prices from lightbox */
if(flatsome_option('catalog_mode_prices')) remove_action( 'woocommerce_single_product_lightbox_summary', 'woocommerce_template_single_price', 10 );
/* Remove sale badges */
if( get_theme_mod( 'catalog_mode_sale_badge', 0 )) add_filter( 'woocommerce_sale_flash', '__return_false' );

View File

@@ -0,0 +1,117 @@
<?php
/* Remove default Hooks */
remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20 );
/* Add Ordering to Flatsome tools */
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 );
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 );
/** $GLOBALS['woocommerce_loop'] will not be set in time otherwise. */
remove_action( 'woocommerce_before_shop_loop', 'wc_setup_loop' );
add_action( 'flatsome_category_title_alt', 'wc_setup_loop' );
add_action( 'flatsome_category_title_alt', 'woocommerce_result_count', 20 );
add_action( 'flatsome_category_title_alt', 'woocommerce_catalog_ordering', 30 );
if ( ! function_exists( 'flatsome_category_header' ) ) {
/**
* Main category header function
*/
function flatsome_category_header() {
global $wp_query;
// Set Custom Shop Header.
if ( get_theme_mod( 'html_shop_page' ) && is_shop() && ! $wp_query->is_search() && $wp_query->query_vars['paged'] < 1 ) {
echo do_shortcode( '<div class="custom-page-title">' . get_theme_mod( 'html_shop_page' ) . '</div>' );
wc_get_template_part( 'layouts/headers/category-title' );
} // Set Category headers.
elseif ( is_product_category() || is_shop() || is_product_tag() || is_product_taxonomy() ) {
// Get Custom Header Content.
$cat_header_style = get_theme_mod( 'category_title_style' );
// Fix Transparent header.
if ( get_theme_mod( 'category_header_transparent', 0 ) && ! $cat_header_style ) {
$cat_header_style = 'featured';
}
$queried_object = get_queried_object();
if ( ! is_shop() && get_term_meta( $queried_object->term_id, 'cat_meta' ) ) {
$content = get_term_meta( $queried_object->term_id, 'cat_meta' );
if ( ! empty( $content[0]['cat_header'] ) ) {
if ( ! $cat_header_style ) {
echo do_shortcode( $content[0]['cat_header'] );
wc_get_template_part( 'layouts/headers/category-title' );
} else {
wc_get_template_part( 'layouts/headers/category-title', $cat_header_style );
echo '<div class="custom-category-header">' . do_shortcode( $content[0]['cat_header'] ) . '</div>';
}
} else {
// Get default header title.
wc_get_template_part( 'layouts/headers/category-title', $cat_header_style );
}
} else {
// Get default header title.
wc_get_template_part( 'layouts/headers/category-title', $cat_header_style );
}
}
}
}
add_action( 'flatsome_after_header', 'flatsome_category_header' );
if ( ! function_exists( 'flatsome_category_header_classes' ) ) {
/**
* Add Transparent Header To Category if Set
*
* @param $classes
*
* @return array
*/
function flatsome_category_header_classes( $classes ) {
$transparent = get_theme_mod( 'category_header_transparent', 0 );
if ( $transparent && is_shop() || $transparent && is_product_category() || $transparent && is_product_tag() ) {
$classes[] = 'transparent has-transparent nav-dark toggle-nav-dark';
}
return $classes;
}
}
add_filter( 'flatsome_header_class', 'flatsome_category_header_classes', 10 );
if ( ! function_exists( 'flatsome_add_category_filter_button' ) ) {
/**
* Add Category Filter button for Mobile and Off Canvas
*/
function flatsome_add_category_filter_button() {
wc_get_template_part( 'loop/filter-button' );
}
}
add_action( 'flatsome_category_title', 'flatsome_add_category_filter_button', 20 );
if ( ! function_exists( 'flatsome_category_title' ) ) {
/**
* Add Category Title if set
*/
function flatsome_category_title() {
if ( ! get_theme_mod( 'category_show_title', 0 ) ) {
return;
} ?>
<h1 class="shop-page-title is-xlarge"><?php woocommerce_page_title(); ?></h1>
<?php
}
}
add_action( 'flatsome_category_title', 'flatsome_category_title', 1 );
if ( ! function_exists( 'flatsome_shop_loop_tools_breadcrumbs' ) ) {
/**
* Add Breadcrumbs
*/
function flatsome_shop_loop_tools_breadcrumbs() {
wc_get_template_part( 'loop/breadcrumbs' );
}
}
add_action( 'flatsome_category_title', 'flatsome_shop_loop_tools_breadcrumbs', 10 );

View File

@@ -0,0 +1,179 @@
<?php
// Remove Default links
remove_action( 'woocommerce_before_shop_loop_item','woocommerce_template_loop_product_link_open', 10);
remove_action( 'woocommerce_after_shop_loop_item','woocommerce_template_loop_product_link_close', 5);
/* Move Sale Flash */
remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_show_product_loop_sale_flash', 10);
add_action( 'woocommerce_before_shop_loop_item', 'woocommerce_show_product_loop_sale_flash', 10);
/**
* Gets products per page count from theme settings.
*/
function flatsome_product_pr_page() {
return get_theme_mod( 'products_pr_page', 12 );
}
add_filter( 'loop_shop_per_page', 'flatsome_product_pr_page', 20 );
/**
* Gets base desktop row count from theme settings.
*/
function flatsome_category_row_count() {
return get_theme_mod( 'category_row_count', 3 );
}
add_filter( 'loop_shop_columns', 'flatsome_category_row_count', 20 );
/* Set WooCommerce product loop classes */
function flatsome_product_row_classes($cols = null){
$classes = array('row','row-small');
$category_grid_style = flatsome_option('category_grid_style');
if($category_grid_style == 'masonry'){
wp_enqueue_script('flatsome-masonry-js');
$classes[] = 'row-masonry has-packery';
}
if(get_theme_mod('category_grid_style') == 'list'){
$classes[] = 'has-box-vertical';
}
$columns = flatsome_option('category_row_count');
if($cols) $columns = $cols;
if ( is_cart() ) $columns = apply_filters( 'woocommerce_cross_sells_columns', 4 );
$classes[] = 'large-columns-'.$columns;
$classes[] = 'medium-columns-'.flatsome_option('category_row_count_tablet');
$classes[] = 'small-columns-'.flatsome_option('category_row_count_mobile');
$shadow = flatsome_option('category_shadow');
$shadow_hover = flatsome_option('category_shadow_hover');
if($shadow || $shadow_hover) $classes[] = 'has-shadow';
if($shadow) $classes[] = 'row-box-shadow-'.$shadow;
if($shadow_hover) $classes[] = 'row-box-shadow-'.$shadow_hover.'-hover';
// Custom heights
if(get_theme_mod('category_force_image_height')) {
$classes[] = 'has-equal-box-heights';
}
if ( get_theme_mod( 'equalize_product_box' ) ) {
$classes[] = 'equalize-box';
}
return implode(' ', $classes);
}
function flatsome_products_footer_content(){
if(is_product_category() || is_product_tag()){
$queried_object = get_queried_object();
$content = get_term_meta($queried_object->term_id, 'cat_meta');
if(!empty($content[0]['cat_footer'])){
echo '<hr/>';
echo do_shortcode($content[0]['cat_footer']);
}
}
}
add_action('flatsome_products_after','flatsome_products_footer_content');
/* Add Custom Meta to Category */
if(is_admin()){
if(function_exists('get_term_meta')){
function top_text_taxonomy_edit_meta_field($term) {
// put the term ID into a variable
$t_id = $term->term_id;
// retrieve the existing value(s) for this meta field. This returns an array
$term_meta = get_term_meta($t_id,'cat_meta');
if(!$term_meta){$term_meta = add_term_meta($t_id, 'cat_meta', '');}
?>
<tr class="form-field">
<th scope="row" valign="top"><label for="term_meta[cat_header]"><?php _e( 'Top Content', 'flatsome' ); ?></label></th>
<td>
<?php
$content = esc_attr( isset($term_meta[0]['cat_header']) ) ? esc_attr( $term_meta[0]['cat_header'] ) : '';
echo '<textarea id="term_meta[cat_header]" name="term_meta[cat_header]">'.$content.'</textarea>'; ?>
<p class="description"><?php _e( 'Enter a value for this field. Shortcodes are allowed. This will be displayed at top of the category.','flatsome' ); ?></p>
</td>
</tr>
<?php
}
add_action( 'product_cat_edit_form_fields', 'top_text_taxonomy_edit_meta_field', 10, 2 );
add_action( 'product_tag_edit_form_fields', 'top_text_taxonomy_edit_meta_field', 10, 2 );
/* ADD CUSTOM META BOX TO CATEGORY PAGES */
function bottom_text_taxonomy_edit_meta_field($term) {
// put the term ID into a variable
$t_id = $term->term_id;
// retrieve the existing value(s) for this meta field. This returns an array
$term_meta = get_term_meta($t_id,'cat_meta');
if(!$term_meta){$term_meta = add_term_meta($t_id, 'cat_meta', '');}
?>
<tr class="form-field">
<th scope="row" valign="top"><label for="term_meta[cat_footer]"><?php _e( 'Bottom Content', 'flatsome' ); ?></label></th>
<td>
<?php
$content = isset($term_meta[0]['cat_footer']) ? esc_attr( $term_meta[0]['cat_footer'] ) : '';
echo '<textarea id="term_meta[cat_footer]" name="term_meta[cat_footer]">'.$content.'</textarea>'; ?>
<p class="description"><?php _e( 'Enter a value for this field. Shortcodes are allowed. This will be displayed at bottom of the category.','flatsome' ); ?></p>
</td>
</tr>
<?php
}
add_action( 'product_cat_edit_form_fields', 'bottom_text_taxonomy_edit_meta_field', 10, 2 );
add_action( 'product_tag_edit_form_fields', 'bottom_text_taxonomy_edit_meta_field', 10, 2 );
function flatsome_custom_product_page_taxonomy_edit_meta_field( $term ) {
$t_id = $term->term_id;
// retrieve the existing value(s) for this meta field. This returns an array
$term_meta = get_term_meta( $t_id, 'cat_meta' );
if ( ! $term_meta ) {
$term_meta = add_term_meta( $t_id, 'cat_meta', '' );
}
?>
<tr class="form-field">
<th scope="row" valign="top"><label for="term_meta[cat_product_block]"><?php _e( 'Custom product layout', 'flatsome' ); ?></label></th>
<td>
<?php
$selected = esc_attr( isset( $term_meta[0]['cat_product_block'] ) ) ? esc_attr( $term_meta[0]['cat_product_block'] ) : 0;
wp_dropdown_pages( array(
'id' => 'term_meta[cat_product_block]',
'name' => 'term_meta[cat_product_block]',
'post_type' => 'blocks',
'show_option_none' => '-- None --',
'selected' => $selected,
) ); ?>
<p class="description"><?php _e( 'Choose a custom product block layout for this category.', 'flatsome' ); ?></p>
</td>
</tr>
<?php
}
add_action( 'product_cat_edit_form_fields', 'flatsome_custom_product_page_taxonomy_edit_meta_field', 10 );
/* SAVE CUSTOM META*/
function fl_save_taxonomy_custom_meta( $term_id ) {
if ( isset( $_POST['term_meta'] ) ) {
$t_id = $term_id;
$cat_keys = array_keys( $_POST['term_meta'] );
foreach ( $cat_keys as $key ) {
if ( isset ( $_POST['term_meta'][$key] ) ) {
$term_meta[$key] = $_POST['term_meta'][$key];
}
}
// Save the option array.
update_term_meta($term_id, 'cat_meta', $term_meta);
}
}
add_action( 'edited_product_cat', 'fl_save_taxonomy_custom_meta', 10, 2 );
add_action( 'edited_product_tag', 'fl_save_taxonomy_custom_meta', 10, 2 );
}
} // is_admin

View File

@@ -0,0 +1,191 @@
<?php
// Fix Cart Totals Title style
if(!function_exists('flatsome_woocommerce_before_cart_totals')) {
function flatsome_woocommerce_before_cart_totals(){ ?>
<table cellspacing="0">
<thead>
<tr>
<th class="product-name" colspan="2" style="border-width:3px;"><?php _e( 'Cart totals', 'woocommerce' ); ?></th>
</tr>
</thead>
</table>
<?php }
}
add_action( 'woocommerce_before_cart_totals', 'flatsome_woocommerce_before_cart_totals' );
// Custom Thank You Html
function flatsome_thank_you_html(){
echo do_shortcode( get_theme_mod( 'html_thank_you' ) );
}
add_action( 'woocommerce_thankyou', 'flatsome_thank_you_html', 100);
// Add HTML Checkout sidebar
if(!function_exists('flatsome_html_checkout_sidebar')) {
function flatsome_html_checkout_sidebar(){
$content = flatsome_option('html_checkout_sidebar');
if($content) {
echo '<div class="html-checkout-sidebar pt-half">'.do_shortcode($content).'</div>';
}
}
}
add_action('woocommerce_checkout_after_order_review', 'flatsome_html_checkout_sidebar');
function flatsome_override_existing_checkout_fields( $fields ) {
// Make sure address 1 and address 2 is on same line.
if ( isset( $fields['address_2'] ) ) {
$fields['address_1']['class'][] = 'form-row-first';
$fields['address_2']['class'][] = 'form-row-last';
$fields['address_2']['label'] = esc_attr__( 'Apartment, suite, unit, etc.', 'woocommerce' );
// Remove "form-row-wide" class from address 1 and address 2.
$fields['address_1']['class'] = array_diff( $fields['address_1']['class'], array( 'form-row-wide' ) );
$fields['address_1']['class'] = array_values( $fields['address_1']['class'] ); // Reindex.
$fields['address_2']['class'] = array_diff( $fields['address_2']['class'], array( 'form-row-wide' ) );
$fields['address_2']['class'] = array_values( $fields['address_2']['class'] ); // Reindex.
// Reveal label.
if ( isset( $fields['address_2']['label_class'] ) && is_array( $fields['address_2']['label_class'] ) ) {
$fields['address_2']['label_class'] = array_diff( $fields['address_2']['label_class'], array( 'screen-reader-text' ) );
$fields['address_2']['label_class'] = array_values( $fields['address_2']['label_class'] ); // Reindex.
}
}
// Fix labels for floating labels option.
if ( get_theme_mod( 'checkout_floating_labels', 0 ) ) {
$fields['address_1']['placeholder'] = __( 'Street address', 'woocommerce' );
// Set Placeholders.
foreach ( $fields as $key => $value ) {
if ( isset( $fields[ $key ]['label'] ) && ! isset( $fields[ $key ]['placeholder'] ) ) {
$fields[ $key ]['placeholder'] = $fields[ $key ]['label'];
}
}
}
return $fields;
}
add_filter( 'woocommerce_default_address_fields', 'flatsome_override_existing_checkout_fields' );
function flatsome_move_checkout_fields( $fields ) {
// Move email to top
if ( get_theme_mod( 'checkout_fields_email_first', 0 ) ) {
$fields['billing']['billing_email']['priority'] = -1;
$billing_email = $fields['billing']['billing_email'];
unset( $fields['billing']['billing_email'] );
$fields['billing'] = array( 'billing_email' => $billing_email ) + $fields['billing'];
}
// Fix auto scrolling
if ( isset( $fields['billing'] ) ) $fields['billing']['billing_first_name']['autofocus'] = false;
if ( isset( $fields['shipping'] ) ) $fields['shipping']['shipping_first_name']['autofocus'] = false;
return $fields;
}
add_filter( 'woocommerce_checkout_fields', 'flatsome_move_checkout_fields' );
/* Floating labels option */
function flatsome_checkout_scripts() {
if(is_checkout() && get_theme_mod('checkout_floating_labels', 0)) {
wp_enqueue_script( 'flatsome-woocommerce-floating-labels', get_template_directory_uri() .'/assets/libs/float-labels.min.js', array( 'flatsome-theme-woocommerce-js' ), '3.5', true );
wp_dequeue_style( 'selectWoo' );
wp_deregister_style( 'selectWoo' );
wp_dequeue_script( 'selectWoo' );
wp_deregister_script( 'selectWoo' );
}
}
add_action( 'wp_enqueue_scripts', 'flatsome_checkout_scripts', 100 );
function flatsome_checkout_body_classes( $classes ) {
if( is_checkout() && get_theme_mod('checkout_floating_labels', 0)) {
$classes[] = 'fl-labels';
}
return $classes;
}
add_filter( 'body_class', 'flatsome_checkout_body_classes' );
/**
* Output terms and conditions checkbox text.
* @see wc_terms_and_conditions_checkbox_text()
*
* @param string $link_style Link opening style: tab, lightbox
*/
function flatsome_terms_and_conditions_checkbox_text( $link_style ) {
$text = wc_get_terms_and_conditions_checkbox_text();
$terms_page_id = wc_terms_and_conditions_page_id();
if ( ! $text || ! $terms_page_id ) {
return;
}
$terms_link = $terms_page_id ? '<a href="' . esc_url( get_permalink( $terms_page_id ) ) . '" target="_blank" rel="noopener noreferrer">' . esc_html__( 'terms and conditions', 'woocommerce' ) . '</a>' : esc_html__( 'terms and conditions', 'woocommerce' );
if ( $link_style === 'lightbox' ) {
$terms_link = $terms_page_id ? '<a href="#terms-and-conditions-lightbox">' . esc_html__( 'terms and conditions', 'woocommerce' ) . '</a>' : esc_html__( 'terms and conditions', 'woocommerce' );
}
$text = str_replace( '[terms]', $terms_link, $text );
$page = get_post( $terms_page_id );
if ( $page && 'publish' === $page->post_status && $page->post_content && ! has_shortcode( $page->post_content, 'woocommerce_checkout' ) ) {
echo $text;
}
}
/**
* Output lightbox shortcode with term and conditions selected page as content.
*/
function flatsome_terms_and_conditions_lightbox() {
if ( get_theme_mod( 'checkout_terms_and_conditions' ) !== 'lightbox' ) {
return;
}
$terms_page_id = wc_terms_and_conditions_page_id();
if ( ! $terms_page_id ) {
return;
}
$page = get_post( $terms_page_id );
$shortcode = '[lightbox id="terms-and-conditions-lightbox" width="800px" padding="20px"]';
$shortcode .= $page->post_content;
if ( get_theme_mod( 'terms_and_conditions_lightbox_buttons', 1 ) ) {
$text = __( 'I have read and agree', 'flatsome' );
$shortcode .= '<div class="terms-and-conditions-lightbox__buttons text-center">';
$shortcode .= sprintf( '<button id="terms-and-conditions-accept" class="button primary is-underline" aria-label="%s" onClick="document.getElementById(\'terms\').checked = true; jQuery.magnificPopup.close();">%s</button>',
esc_attr( $text ),
esc_html( $text )
);
$shortcode .= '</div>';
}
$shortcode .= '[/lightbox]';
echo do_shortcode( $shortcode );
}
add_action( 'woocommerce_checkout_terms_and_conditions', 'flatsome_terms_and_conditions_lightbox', 30 );
/**
* Disable default wc_terms_and_conditions_page_content output.
*/
function flatsome_terms_and_conditions() {
if ( get_theme_mod( 'checkout_terms_and_conditions' ) ) {
remove_action( 'woocommerce_checkout_terms_and_conditions', 'wc_terms_and_conditions_page_content', 30 );
}
}
add_action( 'woocommerce_checkout_terms_and_conditions', 'flatsome_terms_and_conditions' );

View File

@@ -0,0 +1,20 @@
<?php
/**
* Validates whether the WC Cart instance is available in the request.
*
* @return bool
*/
function flatsome_is_wc_cart_available() {
if ( ! function_exists( 'WC' ) ) return false;
return WC() instanceof \WooCommerce && WC()->cart instanceof \WC_Cart;
}
/**
* Verifies whether the mini cart can be revealed or not.
*
* @return bool
*/
function flatsome_is_mini_cart_reveal() {
return ( 'yes' !== get_option( 'woocommerce_cart_redirect_after_add' ) && 'link' !== get_theme_mod( 'header_cart_style', 'dropdown' ) && get_theme_mod( 'cart_dropdown_show', 1 ) );
}

View File

@@ -0,0 +1,637 @@
<?php
function flatsome_woocommerce_setup() {
// Theme support for default WC gallery.
if ( get_theme_mod( 'product_gallery_woocommerce') ) {
add_theme_support( 'wc-product-gallery-slider' );
// Force default lightbox when default gallery is chosen.
if ( get_theme_mod( 'product_lightbox','default' ) !== 'default' ) {
set_theme_mod( 'product_lightbox', 'default' );
}
}
// Theme support for default WC gallery lightbox.
if ( get_theme_mod( 'product_lightbox','default' ) === 'default' ) {
add_theme_support( 'wc-product-gallery-lightbox' );
}
// Remove default row and column options.
remove_theme_support( 'product_grid' );
}
add_action( 'after_setup_theme', 'flatsome_woocommerce_setup', 90 );
if ( ! function_exists( 'flatsome_woocommerce_add_notice' ) ) {
/**
* Add wc notices except for the cart page
*/
function flatsome_woocommerce_add_notice() {
if ( is_woocommerce_activated() && ! is_cart() ) {
if ( function_exists( 'wc_print_notices' ) ) wc_print_notices();
}
}
}
add_action( 'flatsome_after_header', 'flatsome_woocommerce_add_notice', 100 );
function flatsome_my_account_menu_classes($classes){
// Add Active Class
if(in_array('is-active', $classes)){
array_push($classes, 'active');
}
return $classes;
}
add_filter('woocommerce_account_menu_item_classes', 'flatsome_my_account_menu_classes');
/* My Account Dashboard overview */
function flatsome_my_account_dashboard(){
wc_get_template( 'myaccount/dashboard-links.php' );
}
add_action('woocommerce_account_dashboard','flatsome_my_account_dashboard');
// Remove logout from my account menu
function flatsome_remove_logout_account_item( $items ) {
unset( $items['customer-logout'] );
return $items;
}
add_filter( 'woocommerce_account_menu_items', 'flatsome_remove_logout_account_item' );
/**
* Conditionally remove WooCommerce styles and/or scripts.
*/
function flatsome_woocommerce_scripts_styles() {
// Remove default WooCommerce Lightbox.
if ( get_theme_mod( 'product_lightbox', 'default' ) !== 'woocommerce' || ! is_product() ) {
wp_dequeue_style( 'woocommerce_prettyPhoto_css' );
wp_deregister_style( 'woocommerce_prettyPhoto_css' );
wp_dequeue_script( 'prettyPhoto' );
wp_dequeue_script( 'prettyPhoto-init' );
}
if ( ! is_admin() ) {
wp_dequeue_style( 'woocommerce-layout' );
wp_deregister_style( 'woocommerce-layout' );
wp_dequeue_style( 'woocommerce-smallscreen' );
wp_deregister_style( 'woocommerce-smallscreen' );
wp_dequeue_style( 'woocommerce-general' );
wp_deregister_style( 'woocommerce-general' );
}
}
add_action( 'wp_enqueue_scripts', 'flatsome_woocommerce_scripts_styles', 98 );
// Add Shop Widgets
function flatsome_shop_widgets_init() {
register_sidebar( array(
'name' => __( 'Shop Sidebar', 'flatsome' ),
'id' => 'shop-sidebar',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<span class="widget-title shop-sidebar">',
'after_title' => '</span><div class="is-divider small"></div>',
) );
register_sidebar( array(
'name' => __( 'Product Sidebar', 'flatsome' ),
'id' => 'product-sidebar',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<span class="widget-title shop-sidebar">',
'after_title' => '</span><div class="is-divider small"></div>',
) );
}
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' => '&#47;',
'wrap_before' => '<nav class="woocommerce-breadcrumb breadcrumbs '.get_theme_mod('breadcrumb_case', 'uppercase').'">',
'wrap_after' => '</nav>',
'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();
?> <span class="cart-price"><?php echo WC()->cart->get_cart_subtotal(); ?></span><?php
$fragments['.cart-price'] = ob_get_clean();
return $fragments;
}
add_filter('woocommerce_add_to_cart_fragments', 'flatsome_header_add_to_cart_fragment');
if ( ! function_exists( 'flatsome_header_add_to_cart_fragment_count' ) ) {
/**
* Update cart number when default cart icon is selected
*
* @param $fragments
*
* @return mixed
*/
function flatsome_header_add_to_cart_fragment_count( $fragments ) {
ob_start();
?>
<span class="cart-icon image-icon">
<strong><?php echo WC()->cart->cart_contents_count; ?></strong>
</span>
<?php
$fragments['.header .cart-icon'] = ob_get_clean();
return $fragments;
}
}
add_filter( 'woocommerce_add_to_cart_fragments', 'flatsome_header_add_to_cart_fragment_count' );
if ( ! function_exists( 'flatsome_header_add_to_cart_fragment_count_label' ) ) {
/**
* Update cart label when a build-in cart icon is selected
*
* @param $fragments
*
* @return mixed
*/
function flatsome_header_add_to_cart_fragment_count_label( $fragments ) {
if ( ! get_theme_mod( 'cart_icon_style' ) ) {
return $fragments;
}
$icon = get_theme_mod( 'cart_icon', 'basket' );
ob_start();
?>
<i class="icon-shopping-<?php echo $icon; ?>" data-icon-label="<?php echo WC()->cart->cart_contents_count; ?>">
<?php
$fragments[ 'i.icon-shopping-' . $icon ] = ob_get_clean();
return $fragments;
}
}
add_filter( 'woocommerce_add_to_cart_fragments', 'flatsome_header_add_to_cart_fragment_count_label' );
if ( ! function_exists( 'flatsome_header_add_to_cart_custom_icon_fragment_count_label' ) ) {
/**
* Update cart label when custom cart icon is selected
*
* @param $fragments
*
* @return mixed
*/
function flatsome_header_add_to_cart_custom_icon_fragment_count_label( $fragments ) {
$custom_cart_icon = get_theme_mod( 'custom_cart_icon' );
if ( ! $custom_cart_icon ) {
return $fragments;
}
ob_start();
?>
<span class="image-icon header-cart-icon" data-icon-label="<?php echo WC()->cart->cart_contents_count; ?>">
<img class="cart-img-icon" alt="<?php _e( 'Cart', 'woocommerce' ); ?>" src="<?php echo do_shortcode( $custom_cart_icon ); ?>"/>
</span>
<?php
$fragments['.image-icon.header-cart-icon'] = ob_get_clean();
return $fragments;
}
}
add_filter( 'woocommerce_add_to_cart_fragments', 'flatsome_header_add_to_cart_custom_icon_fragment_count_label' );
// Add Pages and blog posts to top of search results if set.
function flatsome_pages_in_search_results(){
if(!is_search() || !get_theme_mod('search_result', 1)) return;
global $post;
?>
<?php if( get_search_query() ) : ?>
<?php
/**
* Include pages and posts in search
*/
query_posts( array( 'post_type' => 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 '<hr/><h4 class="uppercase">' . esc_html__( 'Posts found', 'flatsome' ) . '</h4>';
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 '<hr/><h4 class="uppercase">' . esc_html__( 'Pages found', 'flatsome' ) . '</h4>';
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 ),
) );
}
?>
<?php endif; ?>
<?php
}
add_action('woocommerce_after_main_content','flatsome_pages_in_search_results', 10);
function flatsome_new_flash( $html, $post, $product, $badge_style ) {
if ( ! get_theme_mod( 'new_bubble_auto' ) ) {
return $html;
}
$datetime_created = $product->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', '<div class="badge callout badge-' . $badge_style . '"><div class="badge-inner is-small new-bubble-auto">' . esc_html__( 'New', 'flatsome' ) . '</div></div>', $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' );
}
?>
<div id="login-form-popup" class="lightbox-content mfp-hide">
<?php if(get_theme_mod('social_login_pos','top') == 'top' && ($is_facebook_login || $is_google_login)) wc_get_template('myaccount/header.php'); ?>
<?php wc_get_template_part('myaccount/form-login', $layout ); ?>
<?php if(get_theme_mod('social_login_pos','top') == 'bottom' && ($is_facebook_login || $is_google_login)) wc_get_template('myaccount/header.php'); ?>
</div>
<?php }
}
add_action('wp_footer', 'flatsome_account_login_lightbox', 10);
// Payment icons to footer
function flatsome_footer_payment_icons(){
$icons = get_theme_mod('payment_icons_placement');
if(is_array($icons) && !in_array('footer', $icons)) return;
echo do_shortcode('[ux_payment_icons]');
}
add_action('flatsome_absolute_footer_secondary','flatsome_footer_payment_icons', 10);
/* Disable reviews globally */
if(get_theme_mod('disable_reviews')){
remove_filter( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 5 );
remove_filter( 'woocommerce_single_product_summary','woocommerce_template_single_rating', 10);
add_filter( 'woocommerce_product_tabs', 'wcs_woo_remove_reviews_tab', 98 );
function wcs_woo_remove_reviews_tab($tabs) {
unset($tabs['reviews']);
return $tabs;
}
}
if ( ! function_exists( 'flatsome_wc_get_gallery_image_html' ) ) {
/**
* Get HTML for a gallery image. Copied and modified from woocommerce plugin and wc_get_gallery_image_html helper function.
*
* @param int $attachment_id Attachment ID.
* @param bool $main_image Is this the main image or a thumbnail?.
* @param string $size Image size.
*
* @return string
*/
function flatsome_wc_get_gallery_image_html( $attachment_id, $main_image = false, $size = 'woocommerce_single' ) {
$gallery_thumbnail = wc_get_image_size( 'gallery_thumbnail' );
$thumbnail_size = apply_filters( 'woocommerce_gallery_thumbnail_size', array( $gallery_thumbnail['width'], $gallery_thumbnail['height'] ) );
$image_size = apply_filters( 'woocommerce_gallery_image_size', $size );
$full_size = apply_filters( 'woocommerce_gallery_full_size', apply_filters( 'woocommerce_product_thumbnails_large_size', 'full' ) );
$thumbnail_src = wp_get_attachment_image_src( $attachment_id, $thumbnail_size );
$full_src = wp_get_attachment_image_src( $attachment_id, $full_size );
$alt_text = trim( wp_strip_all_tags( get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ) ) );
if ( empty( $full_src ) ) {
return '';
}
$image = wp_get_attachment_image(
$attachment_id,
$image_size,
false,
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 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 '<div data-thumb="' . esc_url( $thumbnail_src[0] ) . '" data-thumb-alt="' . esc_attr( $alt_text ) . '" class="woocommerce-product-gallery__image ' . $image_wrapper_class . '"><a href="' . esc_url( $full_src[0] ) . '">' . $image . '</a></div>';
}
}
/* 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 .= '<span class="added-to-cart" data-timer=""></span>';
return $message;
});
}

View File

@@ -0,0 +1,196 @@
<?php
// Get Product Lists
function ux_list_products( $args ) {
if ( isset( $args ) ) {
$options = $args;
$number = 8;
if ( isset( $options['products'] ) ) {
$number = $options['products'];
}
$show = ''; // featured, onsale.
if ( isset( $options['show'] ) ) {
$show = $options['show'];
}
$orderby = 'date';
$order = 'desc';
if ( isset( $options['orderby'] ) ) {
$orderby = $options['orderby'];
}
if ( isset( $options['order'] ) ) {
$order = $options['order'];
}
if ( $orderby == 'menu_order' ) {
$order = 'asc';
}
$tags = '';
if ( isset( $options['tags'] ) ) {
if ( is_numeric( $options['tags'] ) ) {
$term = get_term( $options['tags'] );
if ( $term instanceof WP_Term ) {
$options['tags'] = $term->slug;
}
}
$tags = $options['tags'];
}
$offset = '';
if ( isset( $options['offset'] ) ) {
$offset = $options['offset'];
}
} else {
return false;
}
$query_args = array(
'posts_per_page' => $number,
'post_status' => 'publish',
'post_type' => 'product',
'no_found_rows' => 1,
'ignore_sticky_posts' => 1,
'order' => $order,
'product_tag' => $tags,
'offset' => $offset,
'meta_query' => WC()->query->get_meta_query(), // @codingStandardsIgnoreLine
'tax_query' => WC()->query->get_tax_query(), // @codingStandardsIgnoreLine
);
switch ( $show ) {
case 'featured':
$query_args['tax_query'][] = array(
'taxonomy' => 'product_visibility',
'field' => 'name',
'terms' => 'featured',
'operator' => 'IN',
);
break;
case 'onsale':
$query_args['post__in'] = array_merge( array( 0 ), wc_get_product_ids_on_sale() );
break;
}
switch ( $orderby ) {
case 'menu_order':
$query_args['orderby'] = 'menu_order';
break;
case 'title':
$query_args['orderby'] = 'name';
break;
case 'date':
$query_args['orderby'] = 'date';
break;
case 'price':
$query_args['meta_key'] = '_price'; // @codingStandardsIgnoreLine
$query_args['orderby'] = 'meta_value_num';
break;
case 'rand':
$query_args['orderby'] = 'rand'; // @codingStandardsIgnoreLine
break;
case 'sales':
$query_args['meta_key'] = 'total_sales'; // @codingStandardsIgnoreLine
$query_args['orderby'] = 'meta_value_num';
break;
default:
$query_args['orderby'] = 'date';
}
$query_args = ux_maybe_add_category_args( $query_args, $options['cat'], 'IN' );
if ( isset( $options['out_of_stock'] ) && $options['out_of_stock'] === 'exclude' ) {
$product_visibility_term_ids = wc_get_product_visibility_term_ids();
$query_args['tax_query'][] = array(
'taxonomy' => 'product_visibility',
'field' => 'term_taxonomy_id',
'terms' => $product_visibility_term_ids['outofstock'],
'operator' => 'NOT IN',
);
}
$results = new WP_Query( $query_args );
return $results;
} // List products
/**
* Set categories query args if not empty.
*
* @param array $query_args Query args.
* @param string $category Shortcode category attribute value.
* @param string $operator Query Operator.
*
* @return array $query_args
*/
function ux_maybe_add_category_args( $query_args, $category, $operator ) {
if ( ! empty( $category ) ) {
if ( empty( $query_args['tax_query'] ) ) {
$query_args['tax_query'] = array(); // @codingStandardsIgnoreLine
}
$categories = array_map( 'sanitize_title', explode( ',', $category ) );
$field = 'slug';
if ( is_numeric( $categories[0] ) ) {
$field = 'term_id';
$categories = array_map( 'absint', $categories );
// Check numeric slugs.
foreach ( $categories as $cat ) {
$the_cat = get_term_by( 'slug', $cat, 'product_cat' );
if ( false !== $the_cat ) {
$categories[] = $the_cat->term_id;
}
}
}
$query_args['tax_query'][] = array(
'taxonomy' => 'product_cat',
'terms' => $categories,
'field' => $field,
'operator' => $operator,
);
}
return $query_args;
}
global $pagenow;
if ( ! get_theme_mod( 'activated_before' ) && is_admin() && isset( $_GET['activated'] ) && $pagenow == 'themes.php' ) {
/**
* Set Default WooCommerce Image sizes upon theme activation.
*/
function flatsome_woocommerce_image_dimensions() {
$single = array(
'width' => '510',
'height' => '600',
'crop' => 1,
);
$catalog = array(
'width' => '247',
'height' => '300',
'crop' => 1,
);
update_option( 'woocommerce_single_image_width', $single['width'] );
update_option( 'woocommerce_thumbnail_image_width', $catalog['width'] );
update_option( 'woocommerce_thumbnail_cropping', 'custom' );
update_option( 'woocommerce_thumbnail_cropping_custom_width', 5 );
update_option( 'woocommerce_thumbnail_cropping_custom_height', 6 );
}
add_action( 'init', 'flatsome_woocommerce_image_dimensions', 1 );
/**
* Set a theme mod to retrieve first activation state from.
*/
function flatsome_first_activation_state() {
if ( ! get_theme_mod( 'activated_before' ) ) {
set_theme_mod( 'activated_before', true );
}
}
add_action( 'shutdown', 'flatsome_first_activation_state' );
}

View File

@@ -0,0 +1,327 @@
<?php
/**
* Handles the woocommerce product box structure
*
* @author UX Themes
* @package Flatsome/WooCommerce
*/
if ( ! function_exists( 'flatsome_sale_flash' ) ) {
/**
* Add Extra Sale Flash Bubbles
*
* @param $text
* @param $post
* @param $_product
* @param $badge_style
*
* @return string
*/
function flatsome_sale_flash( $text, $post, $_product, $badge_style ) {
global $wc_cpdf;
if ( ! is_a( $wc_cpdf, 'WC_Product_Data_Fields' ) ) {
return $text;
}
if ( $wc_cpdf->get_value( get_the_ID(), '_bubble_new' ) ) {
$bubble_text = $wc_cpdf->get_value( get_the_ID(), '_bubble_text' ) ? $wc_cpdf->get_value( get_the_ID(), '_bubble_text' ) : __( 'New', 'flatsome' );
// Extra Product bubbles.
$text .= '<div class="badge callout badge-' . $badge_style . '"><div class="badge-inner callout-new-bg is-small new-bubble">' . $bubble_text . '</div></div>';
}
return $text;
}
}
add_filter( 'flatsome_product_labels', 'flatsome_sale_flash', 10, 4 );
if ( ! function_exists( 'flatsome_woocommerce_get_alt_product_thumbnail' ) ) {
/**
* Get Hover image for WooCommerce Grid
*/
function flatsome_woocommerce_get_alt_product_thumbnail() {
$hover_style = get_theme_mod( 'product_hover', 'fade_in_back' );
if ( $hover_style !== 'fade_in_back' && $hover_style !== 'zoom_in' ) {
return;
}
global $product;
$attachment_ids = $product->get_gallery_image_ids();
$class = 'show-on-hover absolute fill hide-for-small back-image';
if ( $hover_style == 'zoom_in' ) {
$class .= $class . ' hover-zoom';
}
if ( $attachment_ids ) {
$loop = 0;
foreach ( $attachment_ids as $attachment_id ) {
$image_link = wp_get_attachment_url( $attachment_id );
if ( ! $image_link ) {
continue;
}
$loop ++;
echo apply_filters( 'flatsome_woocommerce_get_alt_product_thumbnail',
wp_get_attachment_image( $attachment_id, 'woocommerce_thumbnail', false, array( 'class' => $class ) ) );
if ( $loop == 1 ) {
break;
}
}
}
}
}
add_action( 'flatsome_woocommerce_shop_loop_images', 'flatsome_woocommerce_get_alt_product_thumbnail', 11 );
if ( ! function_exists( 'woocommerce_template_loop_product_title' ) ) {
/**
* Fix WooCommerce Loop Title
*/
function woocommerce_template_loop_product_title() {
echo '<p class="name product-title ' . esc_attr( apply_filters( 'woocommerce_product_loop_title_classes', 'woocommerce-loop-product__title' ) ) . '">';
woocommerce_template_loop_product_link_open();
echo get_the_title(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
woocommerce_template_loop_product_link_close();
echo '</p>';
}
}
if ( ! function_exists( 'flatsome_woocommerce_shop_loop_category' ) ) {
/**
* Add and/or Remove Categories
*/
function flatsome_woocommerce_shop_loop_category() {
if ( ! flatsome_option( 'product_box_category' ) ) {
return;
} ?>
<p class="category uppercase is-smaller no-text-overflow product-cat op-7">
<?php
global $product;
$product_cats = function_exists( 'wc_get_product_category_list' ) ? wc_get_product_category_list( get_the_ID(), '\n', '', '' ) : $product->get_categories( '\n', '', '' );
$product_cats = strip_tags( $product_cats );
if ( $product_cats ) {
list( $first_part ) = explode( '\n', $product_cats );
echo esc_html( apply_filters( 'flatsome_woocommerce_shop_loop_category', $first_part, $product ) );
}
?>
</p>
<?php
}
}
add_action( 'woocommerce_shop_loop_item_title', 'flatsome_woocommerce_shop_loop_category', 0 );
if ( ! function_exists( 'flatsome_woocommerce_shop_loop_ratings' ) ) {
/**
* Add and/or Remove Ratings
*/
function flatsome_woocommerce_shop_loop_ratings() {
// Switch ratings position when grid 3 is chosen.
if ( 'grid3' === flatsome_option( 'grid_style' ) && ! get_theme_mod( 'disable_reviews' ) ) {
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 5 );
add_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_rating' );
}
// Remove ratings.
if ( flatsome_option( 'product_box_rating' ) ) {
return;
}
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 5 );
remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_rating' );
}
}
add_action( 'woocommerce_shop_loop_item_title', 'flatsome_woocommerce_shop_loop_ratings', 0 );
/* Remove and add Product image */
remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 );
add_action( 'flatsome_woocommerce_shop_loop_images', 'woocommerce_template_loop_product_thumbnail', 10 );
/* Remove Default Add To cart button from Grid */
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
if ( ! function_exists( 'flatsome_product_box_actions_add_to_cart' ) ) {
/**
* Add 'Add to cart' icon
*/
function flatsome_product_box_actions_add_to_cart() {
// Check if active.
if ( get_theme_mod( 'add_to_cart_icon' ) !== 'show' ) {
return;
}
woocommerce_template_loop_add_to_cart();
}
}
add_action( 'flatsome_product_box_actions', 'flatsome_product_box_actions_add_to_cart', 1 );
if ( ! function_exists( 'flatsome_woocommerce_shop_loop_button' ) ) {
/**
* Add 'Add to Cart' After
*/
function flatsome_woocommerce_shop_loop_button() {
if ( get_theme_mod( 'add_to_cart_icon' ) !== 'button' ) {
return;
}
woocommerce_template_loop_add_to_cart();
}
}
add_action( 'flatsome_product_box_after', 'flatsome_woocommerce_shop_loop_button', 100 );
/**
* Add and remove classes depending on add_to_cart_icon type.
*
* @param array $args Default args, see woocommerce_template_loop_add_to_cart().
* @param WC_Product $product Product object.
*
* @return array
*/
function flatsome_woocommerce_loop_add_to_cart_args( $args, $product ) {
if ( ! doing_action( 'flatsome_product_box_actions' ) && ! doing_action( 'flatsome_product_box_after' ) ) {
return $args;
}
if ( get_theme_mod( 'add_to_cart_icon' ) === 'show' ) {
$classes = array( 'add-to-cart-grid', 'no-padding', 'is-transparent' );
$class = isset( $args['class'] ) ? $args['class'] : '';
$classes = array_merge( $classes, explode( ' ', $class ) );
$classes = array_diff( $classes, array( 'button' ) );
$args['class'] = implode( ' ', array_filter( $classes ) );
}
if ( get_theme_mod( 'add_to_cart_icon' ) === 'button' ) {
$classes = array( 'primary', 'is-small', 'mb-0' );
$class = isset( $args['class'] ) ? $args['class'] : '';
$classes = array_merge( $classes, explode( ' ', $class ) );
$classes[] = 'is-' . get_theme_mod( 'add_to_cart_style', 'outline' );
$args['class'] = implode( ' ', array_filter( $classes ) );
}
return $args;
}
add_filter( 'woocommerce_loop_add_to_cart_args', 'flatsome_woocommerce_loop_add_to_cart_args', 5, 2 );
/**
* Change button sprintf format depending on add_to_cart_icon type.
*
* @param string $link Add to cart link html.
* @param WC_Product $product Product object.
* @param array $args Filtered args, see woocommerce_template_loop_add_to_cart().
*
* @return string
*/
function flatsome_woocommerce_loop_add_to_cart_link( $link, $product, $args ) {
if ( ! doing_action( 'flatsome_product_box_actions' ) && ! doing_action( 'flatsome_product_box_after' ) ) {
return $link;
}
switch ( get_theme_mod( 'add_to_cart_icon', 'disabled' ) ) {
case 'show':
$insert = '<div class="cart-icon tooltip is-small" title="' . esc_html( $product->add_to_cart_text() ) . '"><strong>+</strong></div>';
$link = preg_replace( '/(<a.*?>).*?(<\/a>)/', '$1' . $insert . '$2', $link );
break;
case 'button':
$link = '<div class="add-to-cart-button">' . $link . '</div>';
break;
default:
return $link;
}
return $link;
}
add_filter( 'woocommerce_loop_add_to_cart_link', 'flatsome_woocommerce_loop_add_to_cart_link', 5, 3 );
if ( ! function_exists( 'flatsome_woocommerce_shop_loop_excerpt' ) ) {
/**
* Add Product Short description
*/
function flatsome_woocommerce_shop_loop_excerpt() {
if ( ! flatsome_option( 'short_description_in_grid' ) ) {
return;
}
?>
<p class="box-excerpt is-small">
<?php echo get_the_excerpt(); ?>
</p>
<?php
}
}
add_action( 'flatsome_product_box_after', 'flatsome_woocommerce_shop_loop_excerpt', 20 );
if ( ! function_exists( 'flatsome_product_box_class' ) ) {
/**
* Add Classes to product box
*
* @return null/string
*/
function flatsome_product_box_class() {
$classes = array();
$category_grid_style = get_theme_mod( 'category_grid_style', 'grid');
if ( $category_grid_style == 'list' ) {
$classes[] = 'box-vertical';
}
if ( ! empty( $classes ) ) {
return implode( ' ', $classes );
}
return null;
}
}
if ( ! function_exists( 'flatsome_product_box_image_class' ) ) {
/**
* Add Classes to product image box
*
* @return null/string
*/
function flatsome_product_box_image_class() {
$hover_style = flatsome_option( 'product_hover' );
if ( $hover_style == 'fade_in_back' && $hover_style == 'zoom_in' ) {
return null;
}
$classes = array();
$classes[] = 'image-' . $hover_style;
if ( ! empty( $classes ) ) {
return implode( ' ', $classes );
}
return null;
}
}
if ( ! function_exists( 'flatsome_product_box_actions_class' ) ) {
/**
* Add Classes to product actions
*
* @return string
*/
function flatsome_product_box_actions_class() {
return 'grid-tools text-center hide-for-small bottom hover-slide-in show-on-hover';
}
}
if ( ! function_exists( 'flatsome_product_box_text_class' ) ) {
/**
* Add classes to product text box
*
* @return string
*/
function flatsome_product_box_text_class() {
$classes = array( 'box-text-products' );
$grid_style = flatsome_option( 'grid_style' );
if ( $grid_style == 'grid2' ) {
$classes[] = 'text-center grid-style-2';
}
if ( $grid_style == 'grid3' ) {
$classes[] = 'flex-row align-top grid-style-3 flex-wrap';
}
return implode( ' ', $classes );
}
}

View File

@@ -0,0 +1,121 @@
<?php
add_action( 'wc_cpdf_init', 'wc_custom_product_data_fields', 10, 0 );
if ( ! function_exists( 'wc_custom_product_data_fields' ) ) {
/**
* Custom WooCommerce product fields
*
* @return array
*/
function wc_custom_product_data_fields() {
$custom_product_data_fields = array();
$custom_product_data_fields['ux_product_layout_tab'] = array(
array(
'tab_name' => __( 'Product layout', 'flatsome' ),
),
array(
'id' => '_product_block',
'type' => 'select',
'label' => __( 'Custom product layout', 'flatsome' ),
'style' => 'width:100%;height:140px;',
'description' => __( 'Choose a custom product block layout for this product.', 'flatsome' ),
'desc_tip' => true,
'options' => flatsome_get_block_list_by_id( array( 'option_none' => '-- None --' ) ),
),
array(
'id' => '_top_content',
'type' => 'textarea',
'label' => __( 'Top Content', 'flatsome' ),
'style' => 'width:100%;height:140px;',
'description' => __( 'Enter content that will show after the header and before the product. Shortcodes are allowed', 'flatsome' ),
),
array(
'id' => '_bottom_content',
'type' => 'textarea',
'label' => __( 'Bottom Content', 'flatsome' ),
'style' => 'width:100%;height:140px;',
'description' => __( 'Enter content that will show after the product info. Shortcodes are allowed', 'flatsome' ),
),
);
$custom_product_data_fields['ux_extra_tab'] = array(
array(
'tab_name' => __( 'Extra', 'flatsome' ),
),
array(
'id' => '_bubble_new',
'type' => 'select',
'label' => __( 'Custom Bubble', 'flatsome-admin' ),
'description' => __( 'Enable a custom bubble on this product.', 'flatsome' ),
'desc_tip' => true,
'options' => array(
'' => 'Disabled',
'"yes"' => 'Enabled',
),
),
array(
'id' => '_bubble_text',
'type' => 'text',
'label' => __( 'Custom Bubble Title', 'flatsome-admin' ),
'placeholder' => __( 'NEW', 'flatsome-admin' ),
'class' => 'large',
'description' => __( 'Field description.', 'flatsome-admin' ),
'desc_tip' => true,
),
array(
'type' => 'divider',
),
array(
'id' => '_custom_tab_title',
'type' => 'text',
'label' => __( 'Custom Tab Title', 'flatsome-admin' ),
'class' => 'large',
'description' => __( 'Field description.', 'flatsome-admin' ),
'desc_tip' => true,
),
array(
'id' => '_custom_tab',
'type' => 'textarea',
'label' => __( 'Custom Tab Content', 'flatsome' ),
'style' => 'width:100%;height:140px;',
'description' => __( 'Enter content for custom product tab here. Shortcodes are allowed', 'flatsome' ),
),
array(
'type' => 'divider',
),
array(
'id' => '_product_video',
'type' => 'text',
'placeholder' => 'https://www.youtube.com/watch?v=Ra_iiSIn4OI',
'label' => __( 'Product Video', 'flatsome' ),
'style' => 'width:100%;',
'description' => __( 'Enter a Youtube or Vimeo Url of the product video here. We recommend uploading your video to Youtube.', 'flatsome' ),
),
array(
'id' => '_product_video_size',
'type' => 'text',
'label' => __( 'Product Video Size', 'flatsome-admin' ),
'placeholder' => __( '900x900', 'flatsome-admin' ),
'class' => 'large',
'description' => __( 'Set Product Video Size.. Default is 900x900. (Width X Height)', 'flatsome-admin' ),
'desc_tip' => true,
),
array(
'id' => '_product_video_placement',
'type' => 'select',
'label' => __( 'Product Video Placement', 'flatsome-admin' ),
'description' => __( 'Select where you want to display product video.', 'flatsome' ),
'desc_tip' => true,
'options' => array(
'' => 'Lightbox (Default)',
'tab' => 'New Tab',
),
),
);
return $custom_product_data_fields;
}
}

View File

@@ -0,0 +1,142 @@
<?php
/* HEADER TEMPLATES */
// Product Headers
function flatsome_product_header(){
if(is_product() && get_theme_mod('product_header') && get_theme_mod('product_layout') !== 'custom'){
wc_get_template_part('single-product/headers/header-product', get_theme_mod('product_header'));
}
}
add_action('flatsome_after_header','flatsome_product_header', 10);
// Add Transparent Header To Cateogry if Set
function flatsome_product_header_classes($classes){
// Add transparent header to product page if set.
if(is_product() && flatsome_option('product_header_transparent')){
$classes[] = 'transparent has-transparent nav-dark toggle-nav-dark';
}
return $classes;
}
add_filter('flatsome_header_class','flatsome_product_header_classes', 10);
/* BREADCRUMBS */
// Add Breadcrunmbs To Description if no custom page header is set
function flatsome_woocommerce_product_breadcrumb() {
if(!get_theme_mod('product_header')){
flatsome_breadcrumb();
}
}
add_action( 'woocommerce_single_product_summary', 'flatsome_woocommerce_product_breadcrumb', 0 );
// Add Breadcrumbs to Featured Headers if set
function flatsome_product_page_breadcrumbs(){
wc_get_template_part('loop/breadcrumbs');
}
add_action('flatsome_product_title','flatsome_product_page_breadcrumbs',20);
// Move Page title up if featured header is set
function flatsome_product_page_title(){
if(get_theme_mod('product_header') !== 'featured-center') return;
echo '<h1 class="product-title product_title entry-title">'.get_the_title().'</h1>';
remove_action('woocommerce_single_product_summary','woocommerce_template_single_title', 5);
}
add_action('flatsome_product_title','flatsome_product_page_title', 10);
/* Add Next/Prev Nav to Product Image */
if(!function_exists('flatsome_product_title_next_prev')) {
function flatsome_product_title_next_prev(){
if(get_theme_mod('product_next_prev_nav',1)){
flatsome_product_next_prev_nav();
}
}
}
add_action('flatsome_product_title_tools','flatsome_product_title_next_prev', 20);
if(!function_exists('flatsome_product_mobile_next_prev_nav')) {
function flatsome_product_mobile_next_prev_nav(){
if(!get_theme_mod('product_header') && get_theme_mod('product_next_prev_nav',1)){
flatsome_product_next_prev_nav('show-for-medium');
}
}
}
add_action('woocommerce_single_product_summary','flatsome_product_mobile_next_prev_nav', 7);
/* Add Next/Prev Nav to Product Sidebar */
if(!function_exists('flatsome_product_nav_sidebar')) {
function flatsome_product_nav_sidebar(){
if(get_theme_mod('product_next_prev_nav',1) && !get_theme_mod('product_header') && get_theme_mod('product_layout') !== 'left-sidebar-full' && get_theme_mod('product_layout') !== 'left-sidebar'){
echo '<div class="hide-for-off-canvas" style="width:100%">';
flatsome_product_next_prev_nav('nav-right text-right');
echo '</div>';
}
}
}
add_action('flatsome_before_product_sidebar','flatsome_product_nav_sidebar', 0);
if(!function_exists('flatsome_product_next_prev_nav')) {
function flatsome_product_next_prev_nav($class = ''){
echo '<ul class="next-prev-thumbs is-small '.$class.'">';
flatsome_next_post_link_product();
flatsome_previous_post_link_product();
echo '</ul>';
}
}
if(!function_exists('flatsome_next_post_link_product')) {
function flatsome_next_post_link_product() {
global $post;
$next_post = get_next_post(true,'','product_cat');
if ( is_a( $next_post , 'WP_Post' ) ) { ?>
<li class="prod-dropdown has-dropdown">
<a href="<?php echo get_the_permalink( $next_post->ID ); ?>" rel="next" class="button icon is-outline circle">
<?php echo get_flatsome_icon('icon-angle-left'); ?>
</a>
<div class="nav-dropdown">
<a title="<?php echo get_the_title( $next_post->ID ); ?>" href="<?php echo get_the_permalink( $next_post->ID ); ?>">
<?php echo get_the_post_thumbnail($next_post->ID, apply_filters( 'woocommerce_gallery_thumbnail_size', 'woocommerce_gallery_thumbnail' )) ?></a>
</div>
</li>
<?php }
}
}
if(!function_exists('flatsome_previous_post_link_product')) {
function flatsome_previous_post_link_product() {
global $post;
$prev_post = get_previous_post(true,'','product_cat');
if ( is_a( $prev_post , 'WP_Post' ) ) { ?>
<li class="prod-dropdown has-dropdown">
<a href="<?php echo get_the_permalink( $prev_post->ID ); ?>" rel="next" class="button icon is-outline circle">
<?php echo get_flatsome_icon('icon-angle-right'); ?>
</a>
<div class="nav-dropdown">
<a title="<?php echo get_the_title( $prev_post->ID ); ?>" href="<?php echo get_the_permalink( $prev_post->ID ); ?>">
<?php echo get_the_post_thumbnail($prev_post->ID, apply_filters( 'woocommerce_gallery_thumbnail_size', 'woocommerce_gallery_thumbnail' )) ?></a>
</div>
</li>
<?php }
}
}
if(!function_exists('flatsome_open_product_sidebar_lightbox')) {
function flatsome_open_product_sidebar_lightbox() {
if(!get_theme_mod('product_offcanvas_sidebar', 0)) return;
wc_get_template_part('single-product/filter-button');
}
}
add_action('woocommerce_before_single_product', 'flatsome_open_product_sidebar_lightbox', 15);

View File

@@ -0,0 +1,283 @@
<?php
function flatsome_product_summary_fix(){
if(is_product()){
if(!get_theme_mod('product_info_meta', 1)){
remove_action('woocommerce_single_product_summary','woocommerce_template_single_meta',40);
}
if(!get_theme_mod('product_info_share', 1)){
remove_action('woocommerce_single_product_summary','woocommerce_template_single_sharing',50);
}
}
}
add_action('wp_head','flatsome_product_summary_fix', 9999);
// Product summary classes
function flatsome_product_summary_classes( $main = true, $align = true, $form = true ) {
$classes = $main ? array( 'product-summary' ) : array();
if ( $align && get_theme_mod( 'product_info_align' ) ) {
$classes[] = 'text-' . get_theme_mod( 'product_info_align', 'left' );
}
if ( $form && get_theme_mod( 'product_info_form' ) ) {
$classes[] = 'form-' . get_theme_mod( 'product_info_form', '' );
}
echo implode( ' ', $classes );
}
function flatsome_product_upsell_sidebar(){
// Product Upsell
if(get_theme_mod('product_upsell','sidebar') == 'sidebar') {
remove_action( 'woocommerce_after_single_product_summary' , 'woocommerce_upsell_display', 15);
add_action('flatsome_before_product_sidebar','woocommerce_upsell_display', 2);
}
else if(get_theme_mod('product_upsell', 'sidebar') == 'disabled') {
remove_action( 'woocommerce_after_single_product_summary' , 'woocommerce_upsell_display', 15);
}
}
add_action('flatsome_before_product_sidebar','flatsome_product_upsell_sidebar', 1);
/* Add Share to product description */
if(!function_exists('flatsome_product_share')) {
function flatsome_product_share() {
echo do_shortcode('[share]');
}
}
add_action( 'woocommerce_share', 'flatsome_product_share', 10 );
/* Remove Product Description Heading */
function flatsome_remove_product_description_heading($heading){
return $heading = '';
}
add_filter('woocommerce_product_description_heading','flatsome_remove_product_description_heading');
/* Remove Additional Product Information Heading */
function flatsome_remove_product_information_heading($heading){
return $heading = '';
}
add_filter('woocommerce_product_additional_information_heading','flatsome_remove_product_information_heading');
// Move Sale Flash to another hook
remove_action('woocommerce_before_single_product_summary', 'woocommerce_show_product_sale_flash',10);
add_action('flatsome_sale_flash','woocommerce_show_product_sale_flash',10);
// Add Product Video Button
if(!function_exists('flatsome_product_video_button')){
function flatsome_product_video_button(){
global $wc_cpdf;
// Add Product Video
if($wc_cpdf->get_value(get_the_ID(), '_product_video')){ ?>
<a class="button is-outline circle icon button product-video-popup tip-top" href="<?php echo trim( $wc_cpdf->get_value( get_the_ID(), '_product_video' ) ); ?>" title="<?php echo __( 'Video', 'flatsome' ); ?>">
<?php echo get_flatsome_icon('icon-play'); ?>
</a>
<style>
<?php
// Set product video height
$height = '900px';
$width = '900px';
$iframe_scale = '100%';
$custom_size = $wc_cpdf->get_value(get_the_ID(), '_product_video_size');
if($custom_size){
$split = explode("x", $custom_size);
$height = $split[0];
$width = $split[1];
$iframe_scale = ($width/$height*100).'%';
}
echo '.has-product-video .mfp-iframe-holder .mfp-content{max-width: '.$width.';}';
echo '.has-product-video .mfp-iframe-scaler{padding-top: '.$iframe_scale.'}';
?>
</style>
<?php }
}
}
add_action('flatsome_product_image_tools_bottom','flatsome_product_video_button', 1);
// Product Image Lightbox
function flatsome_product_lightbox_button(){
if(get_theme_mod('product_lightbox', 'default') !== 'disabled') { ?>
<a href="#product-zoom" class="zoom-button button is-outline circle icon tooltip hide-for-small" title="<?php echo __( 'Zoom', 'flatsome' ); ?>">
<?php echo get_flatsome_icon('icon-expand'); ?>
</a>
<?php }
}
add_action('flatsome_product_image_tools_bottom','flatsome_product_lightbox_button', 2);
// Add Product Body Classes
function flatsome_product_body_classes( $classes ) {
// Add Frame Class for Posts
if(is_product() && get_theme_mod('product_lightbox', 'default') == 'flatsome'){
$classes[] = 'has-lightbox';
}
return $classes;
}
add_filter( 'body_class', 'flatsome_product_body_classes' );
function flatsome_product_video_tab() {
global $wc_cpdf;
echo flatsome_apply_shortcode( 'ux_video', array(
'url' => trim( $wc_cpdf->get_value( get_the_ID(), '_product_video' ) ),
) );
}
// Custom Product Tabs
function flatsome_custom_product_tabs( $tabs ) {
global $wc_cpdf;
// Product video Tab
if($wc_cpdf->get_value(get_the_ID(), '_product_video_placement') == 'tab'){
$tabs['ux_video_tab'] = array(
'title' => __('Video','flatsome'),
'priority' => 10,
'callback' => 'flatsome_product_video_tab'
);
}
// Adds the new tab
if($wc_cpdf->get_value(get_the_ID(), '_custom_tab_title')){
$tabs['ux_custom_tab'] = array(
'title' => $wc_cpdf->get_value(get_the_ID(), '_custom_tab_title'),
'priority' => 40,
'callback' => 'flatsome_custom_tab_content'
);
}
// Custom Global Section
if(get_theme_mod('tab_title')){
$tabs['ux_global_tab'] = array(
'title' => get_theme_mod('tab_title'),
'priority' => 50,
'callback' => 'flatsome_global_tab_content'
);
}
// Move review tab to the last position
//$tabs['reviews']['priority'] = 100;
return $tabs;
}
add_filter( 'woocommerce_product_tabs', 'flatsome_custom_product_tabs' );
function flatsome_custom_tab_content() {
// The new tab content
global $wc_cpdf;
echo do_shortcode($wc_cpdf->get_value(get_the_ID(), '_custom_tab'));
}
function flatsome_global_tab_content() {
// The new tab content
echo do_shortcode(get_theme_mod('tab_content'));
}
function flatsome_product_tabs_classes(){
$classes = array('nav','nav-uppercase');
$tab_style = get_theme_mod('product_display','tabs');
if($tab_style == 'tabs' || !$tab_style){
$classes[] = 'nav-line';
} else{
$tab_style = str_replace("tabs_","",$tab_style);
if($tab_style == 'vertical') $classes[] = 'nav-line';
if($tab_style == 'normal') $classes[] = 'nav-tabs';
$classes[] = 'nav-'.$tab_style;
}
$align = get_theme_mod('product_tabs_align','left');
if($align){
$classes[] = 'nav-'.$align;
}
echo implode(' ', $classes);
}
// Add Custom HTML Blocks
function flatsome_before_add_to_cart_html(){
echo do_shortcode(get_theme_mod('html_before_add_to_cart'));
}
add_action( 'woocommerce_single_product_summary', 'flatsome_before_add_to_cart_html', 20);
// Add HTML after Add to Cart button
function flatsome_after_add_to_cart_html(){
echo do_shortcode(get_theme_mod('html_after_add_to_cart'));
}
add_action( 'woocommerce_single_product_summary', 'flatsome_after_add_to_cart_html', 30);
// Add Custom HTML to top of product page
function flatsome_product_top_content(){
global $wc_cpdf;
if($wc_cpdf->get_value(get_the_ID(), '_top_content')){
echo do_shortcode($wc_cpdf->get_value(get_the_ID(), '_top_content'));
}
}
add_action('flatsome_before_product_page','flatsome_product_top_content', 10);
// Add Custom HTML to bottom of product page
function flatsome_product_bottom_content(){
global $wc_cpdf;
if($wc_cpdf->get_value(get_the_ID(), '_bottom_content')){
echo do_shortcode($wc_cpdf->get_value(get_the_ID(), '_bottom_content'));
}
}
add_action('flatsome_after_product_page','flatsome_product_bottom_content', 10);
function flatsome_related_products_args( $args ) {
$args['posts_per_page'] = get_theme_mod('max_related_products', 8);
return $args;
}
add_filter( 'woocommerce_output_related_products_args', 'flatsome_related_products_args' );
function flatsome_sticky_add_to_cart_before() {
global $product;
if ( ! is_product() || ! get_theme_mod( 'product_sticky_cart', 0 ) || ! apply_filters( 'flatsome_sticky_add_to_cart_enabled', true, $product ) ) {
return;
}
echo '<div class="sticky-add-to-cart-wrapper">';
echo '<div class="sticky-add-to-cart">';
echo '<div class="sticky-add-to-cart__product">';
$image_id = $product->get_image_id();
$image = wp_get_attachment_image_src( $image_id, 'woocommerce_gallery_thumbnail' );
if ( $image ) {
$image_alt = get_post_meta( $image_id, '_wp_attachment_image_alt', true );
$image = '<img src="' . $image[0] . '" alt="' . $image_alt . '" class="sticky-add-to-cart-img" />';
echo $image;
}
echo '<div class="product-title-small hide-for-small"><strong>' . get_the_title() . '</strong></div>';
if ( ! $product->is_type( 'variable' ) ) {
woocommerce_template_single_price();
}
echo '</div>';
}
add_action( 'woocommerce_before_add_to_cart_button', 'flatsome_sticky_add_to_cart_before', -100 );
function flatsome_sticky_add_to_cart_after() {
global $product;
if ( ! is_product() || ! get_theme_mod( 'product_sticky_cart', 0 ) || ! apply_filters( 'flatsome_sticky_add_to_cart_enabled', true, $product ) ) {
return;
}
echo '</div>';
echo '</div>';
}
add_action( 'woocommerce_after_add_to_cart_button', 'flatsome_sticky_add_to_cart_after', 100 );

View File

@@ -0,0 +1,21 @@
<?php
/**
* Generate product structured data at later point.
* (hook woocommerce_single_product_summary is not always available)
*/
function flatsome_single_product_custom_structured_data() {
if ( ! class_exists( 'WC_Structured_Data' ) ) {
return;
}
$structured_data = WC()->structured_data;
if ( ! is_object( $structured_data ) || ! is_a( $structured_data, 'WC_Structured_Data' ) ) {
return;
}
remove_action( 'woocommerce_single_product_summary', [ $structured_data, 'generate_product_data' ], 60 );
add_action( 'woocommerce_after_single_product', [ $structured_data, 'generate_product_data' ], 60 );
}
add_action( 'flatsome_before_single_product_custom', 'flatsome_single_product_custom_structured_data' );

View File

@@ -0,0 +1,50 @@
<?php
/**
* Get HTML for ratings.
*
* @see wc_get_rating_html()
*/
function flatsome_get_rating_html( $rating, $count = 0 ) {
global $product;
$review_count = $product->get_review_count();
$label = sprintf( __( 'Rated %s out of 5', 'woocommerce' ), $rating ); // phpcs:ignore WordPress.WP.I18n.MissingTranslatorsComment
$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';
if ( $rating > 0 ) {
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 = '<a href="#reviews" class="woocommerce-review-link" rel="nofollow">';
$html .= '<div class="star-rating tooltip" role="img" aria-label="' . esc_attr( $label ) . '" title="' . esc_attr( $title ) . '">';
$html .= wc_get_star_rating_html( $rating, $count );
$html .= '</div>';
$html .= '</a>';
break;
case 'inline':
$html = '<div class="star-rating star-rating--inline" role="img" aria-label="' . esc_attr( $label ) . '">';
$html .= wc_get_star_rating_html( $rating, $count );
$html .= '</div>';
break;
case 'stacked':
$html = '<div class="star-rating" role="img" aria-label="' . esc_attr( $label ) . '">';
$html .= wc_get_star_rating_html( $rating, $count );
$html .= '</div>';
break;
case 'simple':
$html = '<a href="#reviews" class="woocommerce-review-link" rel="nofollow">';
$html .= '<div class="star-rating" role="img" aria-label="' . esc_attr( $label ) . '">';
$html .= wc_get_star_rating_html( $rating, $count );
$html .= '</div>';
$html .= '</a>';
break;
}
} else {
$html = '';
}
return apply_filters( 'woocommerce_product_get_rating_html', $html, $rating, $count );
}