";
}
}
//remove_action( 'woocommerce_product_thumbnails', 'woocommerce_show_product_thumbnails', 20 );
if(avia_woocommerce_version_check('3.0.0')) // in woocommerce 3.0.0
{
add_action('woocommerce_product_thumbnails', 'avia_product_gallery_thumbnail_opener', 19);
add_action('woocommerce_product_thumbnails', 'avia_close_div', 21);
}
if(!function_exists('avia_product_gallery_thumbnail_opener'))
{
function avia_product_gallery_thumbnail_opener()
{
echo "
";
}
}
if( ! function_exists( 'avia_woocommerce_frontend_search_params' ) )
{
add_action( 'woocommerce_before_shop_loop', 'avia_woocommerce_frontend_search_params', 20 );
/**
* Displays a front end interface for modifying the shoplist query parameters like sorting order, product count etc
*
* @since < 4.0
*/
function avia_woocommerce_frontend_search_params()
{
global $avia_config;
if( ! empty( $avia_config['woocommerce']['disable_sorting_options'] ) )
{
return;
}
$product_order['default'] = __( 'Default', 'avia_framework' );
$product_order['menu_order'] = __( 'Custom', 'avia_framework' );
$product_order['title'] = __( 'Name', 'avia_framework' );
$product_order['price'] = __( 'Price', 'avia_framework' );
$product_order['date'] = __( 'Date', 'avia_framework' );
$product_order['popularity'] = __( 'Popularity (sales)', 'avia_framework' );
$product_order['rating'] = __( 'Average rating', 'avia_framework' );
$product_order['relevance'] = __( 'Relevance', 'avia_framework' );
$product_order['rand'] = __( 'Random', 'avia_framework' );
$product_order['id'] = __( 'Product ID', 'avia_framework' );
/**
*
* @since 4.5.6.2
* @return array
*/
$product_order = apply_filters( 'avf_wc_product_order_dropdown_frontend', $product_order );
$product_sort['asc'] = __( 'Click to order products ascending', 'avia_framework' );
$product_sort['desc'] = __( 'Click to order products descending', 'avia_framework' );
$per_page_string = __( 'Products per page', 'avia_framework' );
$per_page = get_option( 'avia_woocommerce_product_count' );
if( ! $per_page )
{
$per_page = get_option( 'posts_per_page' );
}
/**
* ALB elements can return all elements = -1
*/
if( ! empty( $avia_config['woocommerce']['default_posts_per_page'] ) && is_numeric( $avia_config['woocommerce']['default_posts_per_page'] ) )
{
if( $avia_config['woocommerce']['default_posts_per_page'] > 0 )
{
$per_page = $avia_config['woocommerce']['default_posts_per_page'];
}
}
parse_str( $_SERVER['QUERY_STRING'], $params );
if( ! isset( $params['product_order'] ) )
{
$po_key = 'default';
}
else
{
$po_key = $params['product_order'];
}
if( ! isset( $params['product_sort'] ) )
{
$ps_key = ! empty( $avia_config['woocommerce']['product_sort'] ) ? $avia_config['woocommerce']['product_sort'] : 'asc';
}
else
{
$ps_key = $params['product_sort'];
}
if( 'default' == $po_key )
{
unset( $params['product_sort'] );
}
$params['avia_extended_shop_select'] = 'yes';
// $po_key = ! empty( $avia_config['woocommerce']['product_order'] ) ? $avia_config['woocommerce']['product_order'] : $params['product_order'];
// $ps_key = ! empty( $avia_config['woocommerce']['product_sort'] ) ? $avia_config['woocommerce']['product_sort'] : $params['product_sort'];
$pc_key = ! empty( $avia_config['woocommerce']['product_count'] ) ? $avia_config['woocommerce']['product_count'] : $per_page;
$ps_key = strtolower( $ps_key );
$show_sort = ! in_array( $po_key, array( 'rand', 'popularity', 'rating', 'default' ) );
$nofollow = 'rel="nofollow"';
//generate markup
$output = '';
$output .= "
";
$output .= "
";
$output .= "- " . __( 'Sort by', 'avia_framework' ) . " {$product_order[$po_key]}";
$output .= "
";
foreach ( $product_order as $order_key => $order_text )
{
$query_string = 'default' == $order_key ? avia_woo_build_query_string( $params, 'product_order', $order_key, 'product_sort' ) : avia_woo_build_query_string( $params, 'product_order', $order_key );
$output .= '- ';
$output .= "";
$output .= "{$order_text}";
$output .= '';
$output .= '
';
}
$output .= '
';
$output .= ' ';
$output .= '
';
if( $show_sort )
{
$output .= "
';
}
if( ! isset( $avia_config['woocommerce']['default_posts_per_page'] ) || ( $avia_config['woocommerce']['default_posts_per_page'] > 0 ) )
{
$output .= "
";
$output .= "- ".__("Display",'avia_framework')." ".$pc_key." ".$per_page_string."";
$output .= '';
$output .= '
';
$output .= '
';
}
$output .= '
';
echo $output;
}
}
if( ! function_exists( 'avia_woocommerce_ajax_search_params' ) )
{
/**
* Add support for WC product display settings
*
* @since 4.7.3.1
* @param array|string $params
* @return array
*/
function avia_woocommerce_ajax_search_params( $params = array() )
{
if( ! avia_woocommerce_enabled() )
{
return $params;
}
if( ! avia_woocommerce_version_check( '3.0.0') )
{
return $params;
}
/**
*
* @since 4.7.3.1
* @param string $visibility 'show'|'hide'|'' for WC default
* @param string $context
* @return string 'show'|'hide'|'' for WC default
*/
$products_visibility = apply_filters( 'avf_ajax_search_woocommerce_params', '', 'out_of_stock' );
/**
*
* @since 4.7.3.1
* @param string $visibility 'show'|'hide'|'' for WC default
* @param string $context
* @return string 'show'|'hide'|'' for all
*/
$prod_hidden = apply_filters( 'avf_ajax_search_woocommerce_params', '', 'hidden_products' );
/**
*
* @since 4.7.3.1
* @param string $visibility 'show'|'hide'|'' for WC default
* @param string $context
* @return string 'show'|'hide'|'' for all
*/
$prod_featured = apply_filters( 'avf_ajax_search_woocommerce_params', '', 'featured_products' );
// Meta query - replaced by Tax query in WC 3.0.0
$meta_query = array();
$tax_query = array();
avia_wc_set_out_of_stock_query_params( $meta_query, $tax_query, $products_visibility );
avia_wc_set_hidden_prod_query_params( $meta_query, $tax_query, $prod_hidden );
avia_wc_set_featured_prod_query_params( $meta_query, $tax_query, $prod_featured );
if( empty( $tax_query ) || ! is_array( $tax_query ) )
{
return $params;
}
// Plugins might render a query string -> transform to array
$params = wp_parse_args( $params );
if( ! isset( $params['tax_query'] ) || ! is_array( $params['tax_query'] ) )
{
$params['tax_query'] = array();
}
foreach( $tax_query as $value )
{
$params['tax_query'][] = $value;
}
return $params;
}
add_filter( 'avf_ajax_search_query', 'avia_woocommerce_ajax_search_params', 20, 1 );
}
if( ! function_exists( 'avia_woo_active_class' ) )
{
/**
* Helper function to create the active list class
*
* @param string $key1
* @param string $key2
* @return string
*/
function avia_woo_active_class( $key1, $key2 )
{
return ( $key1 == $key2 ) ? " class='current-param'" : '';
}
}
if( ! function_exists( 'avia_woo_build_query_string' ) )
{
/**
* helper function to build the query strings for the catalog ordering menu
*
* @since < 4.0
* @param array $params
* @param string $overwrite_key
* @param string $overwrite_value
* @param string $remove_key
* @return string
*/
function avia_woo_build_query_string( $params = array(), $overwrite_key = '', $overwrite_value = '', $remove_key = '' )
{
if( ! empty( $overwrite_key ) )
{
$params[ $overwrite_key ] = $overwrite_value;
}
if( ! empty( $remove_key ) )
{
unset( $params[ $remove_key ] );
}
$paged = ( array_key_exists( 'product_count', $params ) ) ? 'paged=1&' : '';
return "?" . $paged . http_build_query( $params );
}
}
if( ! function_exists( 'avia_woocommerce_overwrite_catalog_ordering' ) )
{
add_action( 'woocommerce_get_catalog_ordering_args', 'avia_woocommerce_overwrite_catalog_ordering', 20, 1 );
/**
* Overwrite the query parameters from WooCommerce
*
* @since < 4.0
* @param array $args
* @return string
*/
function avia_woocommerce_overwrite_catalog_ordering( $args )
{
global $avia_config;
if( empty( $avia_config['woocommerce'] ) )
{
$avia_config['woocommerce'] = array();
}
if( ! empty( $avia_config['woocommerce']['disable_sorting_options'] ) )
{
return $args;
}
/**
* WC added shortcodes that use this filter (e.g. products).
* We only need to alter the query when we have our select boxes.
*
* LINITATION: It is not possible to mix shop overview (= shop) and other shortcodes because we cannot distinguish when this filter is called !!!
*/
if( ! isset( $_REQUEST['avia_extended_shop_select'] ) || ( 'yes' != $_REQUEST['avia_extended_shop_select'] ) )
{
$avia_config['woocommerce']['product_sort'] = strtolower( $args['order'] );
$avia_config['woocommerce']['product_order'] = strtolower( $args['orderby'] );
return $args;
}
//check the folllowing get parameters and session vars. if they are set overwrite the defaults
$check = array( 'product_order', 'product_count', 'product_sort' );
foreach( $check as $key )
{
if( isset( $_GET[ $key ] ) )
{
$_SESSION['avia_woocommerce'][ $key ] = esc_attr( $_GET[ $key ] );
}
if( isset( $_SESSION['avia_woocommerce'][ $key ] ) )
{
$avia_config['woocommerce'][ $key ] = $_SESSION['avia_woocommerce'][ $key ];
}
}
// if user wants to use new product order remove the old sorting parameter
if( isset( $_GET['product_order'] ) && ! isset( $_GET['product_sort'] ) && isset( $_SESSION['avia_woocommerce']['product_sort'] ) )
{
unset( $_SESSION['avia_woocommerce']['product_sort'], $avia_config['woocommerce']['product_sort'] );
}
$orderby = '';
$order = '';
/**
* Set the product sorting
*/
$product_sort = '';
if( isset( $avia_config['woocommerce']['product_sort'] ) )
{
$product_sort = strtoupper( $avia_config['woocommerce']['product_sort'] );
switch ( $product_sort )
{
case 'DESC':
case 'ASC':
break;
default:
$product_sort = 'ASC';
break;
}
}
/**
* Set the product order with default sortings
*/
$product_order = isset( $avia_config['woocommerce']['product_order'] ) ? $avia_config['woocommerce']['product_order'] :'';
switch ( $product_order )
{
case 'id':
case 'relevance':
case 'date':
$orderby = $product_order;
$order = ! empty( $product_sort ) ? $product_sort : 'DESC';
break;
case 'menu_order':
case 'title' :
case 'price' :
$orderby = $product_order;
$order = ! empty( $product_sort ) ? $product_sort : 'ASC';
break;
case 'rand':
case 'popularity':
case 'rating':
$orderby = $product_order;
break;
case 'default':
default:
$orderby = '';
break;
}
WC()->query->remove_ordering_args();
$old_disable_sorting_options = isset( $avia_config['woocommerce']['disable_sorting_options'] ) ? $avia_config['woocommerce']['disable_sorting_options'] : null;
$avia_config['woocommerce']['disable_sorting_options'] = true;
$new_args = WC()->query->get_catalog_ordering_args( $orderby, $order );
if( ! is_null( $old_disable_sorting_options) )
{
$avia_config['woocommerce']['disable_sorting_options'] = $old_disable_sorting_options;
}
else
{
unset( $avia_config['woocommerce']['disable_sorting_options'] );
}
/**
* set the product count
*/
if( isset( $avia_config['woocommerce']['product_count'] ) && is_numeric( $avia_config['woocommerce']['product_count'] ) )
{
$avia_config['shop_overview_products_overwritten'] = true;
$avia_config['shop_overview_products'] = (int) $avia_config['woocommerce']['product_count'];
}
$avia_config['woocommerce']['product_order'] = strtolower( $new_args['orderby'] );
$avia_config['woocommerce']['product_sort'] = strtolower( $new_args['order'] );
return $new_args;
}
}
//remove produt information on password protected products
if(!function_exists('avia_woocommerce_remove_hooks'))
{
add_action('woocommerce_before_single_product', 'avia_woocommerce_remove_hooks');
function avia_woocommerce_remove_hooks()
{
/*remove content from password protected products*/
if(post_password_required())
{
add_action( 'woocommerce_after_single_product_summary', 'avia_woocommerce_echo_password', 1 );
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 1 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_sharing', 50 );
remove_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_images', 20 );
remove_action( 'woocommerce_product_thumbnails', 'woocommerce_show_product_thumbnails', 20 );
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 10 );
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_upsell_display', 15 );
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );
remove_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_sale_flash', 10 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
remove_action( 'woocommerce_simple_add_to_cart', 'woocommerce_simple_add_to_cart', 30 );
remove_action( 'woocommerce_grouped_add_to_cart', 'woocommerce_grouped_add_to_cart', 30 );
remove_action( 'woocommerce_variable_add_to_cart', 'woocommerce_variable_add_to_cart', 30 );
remove_action( 'woocommerce_external_add_to_cart', 'woocommerce_external_add_to_cart', 30 );
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 );
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 5 );
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_show_product_loop_sale_flash', 10 );
}
}
}
if(!function_exists('avia_woocommerce_echo_password'))
{
add_action('ava_woocomemrce_password_protection_remove_hooks', 'avia_woocommerce_remove_hooks');
function avia_woocommerce_echo_password()
{
/*remove content from password protected products*/
if(post_password_required())
{
echo get_the_password_form();
}
}
}
if( ! function_exists( 'avia_woocommerce_product_gallery_support' ) )
{
if ( did_action( 'woocommerce_init' ) )
{
avia_woocommerce_product_gallery_support();
}
else
{
add_action( 'woocommerce_init', 'avia_woocommerce_product_gallery_support', 50 );
}
function avia_woocommerce_product_gallery_support()
{
if( avia_woocommerce_version_check( '3.0.0' ) && current_theme_supports( 'avia-wc-30-product-gallery-feature' ) )
{
remove_action( 'woocommerce_product_thumbnails', 'avia_product_gallery_thumbnail_opener', 19 );
remove_action( 'woocommerce_product_thumbnails', 'avia_close_div', 21 );
}
else
{
add_filter( 'woocommerce_single_product_image_thumbnail_html','avia_woocommerce_gallery_thumbnail_description', 10, 4 );
}
}
}
/*
single page big image and thumbnails are using the same filter now. therefore we need to make sure that the images get the correct size by storing once the
woocommerce_product_thumbnails action has been called
*/
add_action('woocommerce_product_thumbnails', 'avia_woocommerce_set_single_page_image_size');
if(!function_exists('avia_woocommerce_set_single_page_image_size'))
{
function avia_woocommerce_set_single_page_image_size()
{
global $avia_config;
if(!isset($avia_config['avwc-single-page-size']))
{
$avia_config['avwc-single-page-size'] = "shop_thumbnail";
}
}
}
if(!function_exists('avia_woocommerce_gallery_thumbnail_description'))
{
function avia_woocommerce_gallery_thumbnail_description($img, $attachment_id, $post_id = "", $image_class = "" )
{
global $avia_config;
$image_size = isset($avia_config['avwc-single-page-size']) ? $avia_config['avwc-single-page-size'] : 'shop_single';
$image_link = wp_get_attachment_url( $attachment_id );
if(!$image_link) return $img;
$image = wp_get_attachment_image( $attachment_id, apply_filters( 'single_product_small_thumbnail_size', $image_size ) );
$image_title = esc_attr(get_post_field('post_content', $attachment_id));
$img = sprintf( '
%s', $image_link, $image_class, $image_title, $image );
return $img;
}
}
if( ! function_exists( 'avia_title_args_woopage' ) )
{
add_filter( 'avf_title_args', 'avia_title_args_woopage', 10, 2 );
/**
*
* @param array $args
* @param int $id
* @return array
*/
function avia_title_args_woopage( $args, $id )
{
if( is_single() && is_product() )
{
$args['heading'] = "strong";
}
return $args;
}
}
/*
Function that is able to overwrite the default "shop" page used by woocommerce so the template builder can be used
Will only be executed if the user has switched the "shop" page to advanced layout builder. Default products are no longer displayed
and the user needs to add a product grid element
Can be activated by adding
add_theme_support( 'avia_custom_shop_page' );
to your functions.php file
*/
if(!function_exists('avia_woocommerce_default_page'))
{
add_filter( 'pre_get_posts', 'avia_woocommerce_default_page' );
function avia_woocommerce_default_page($query)
{
if(current_theme_supports('avia_custom_shop_page'))
{
if( isset( $_REQUEST['s'] ) )
{
return $query;
}
if(!$query->is_admin && $query->is_main_query() && !$query->is_tax && $query->is_archive && $query->is_post_type_archive)
{
$vars = $query->query_vars;
if(isset($vars['post_type']) && 'product' == $vars['post_type'] )
{
$shop_page_id = wc_get_page_id( 'shop' );
$builder_active = Avia_Builder()->get_alb_builder_status($shop_page_id);
if($builder_active == "active")
{
$query->set( 'post_type', 'page' );
$query->set( 'p', $shop_page_id );
$query->set( 'meta_query', array() );
$query->is_singular = true;
$query->is_page = true;
$query->is_archive = false;
$query->is_post_type_archive = false;
$query->query = array('p'=>$shop_page_id, 'post_type' => 'page');
}
}
}
}
return $query;
}
}
if(!function_exists('avia_woocommerce_disable_editor'))
{
add_filter( 'avf_builder_button_params', 'avia_woocommerce_disable_editor' );
function avia_woocommerce_disable_editor($params)
{
if(!current_theme_supports('avia_custom_shop_page'))
{
global $post_ID;
$shop_page_id = wc_get_page_id( 'shop' );
if($post_ID == $shop_page_id)
{
$disabled = __('(disabled)', 'avia_framework');
$params['visual_label'] = $params['visual_label'] . " ".$disabled;
$params['default_label'] = $params['default_label'] . " ".$disabled;
$params['button_class'] = "av-builer-button-disabled";
$params['disabled'] = true;
$params['note'] = __('This page is set as the default WooCommerce Shop Overview and therefore does not support the Enfold advanced layout editor', 'avia_framework')."
(".__('Learn more').")";
}
}
if(avia_backend_get_post_type() == "product")
{
$params['noteclass'] = "av-notice av-only-active";
$params['note'] = __('Please note that the Advanced Layout Builder for products will not work with all WooCommerce Extensions', 'avia_framework');
}
return $params;
}
}
if(!function_exists('avia_woocommerce_disable_editor_option'))
{
add_filter( 'avf_builder_active', 'avia_woocommerce_disable_editor_option' , 10 , 2);
function avia_woocommerce_disable_editor_option($params, $post_id)
{
if(!current_theme_supports('avia_custom_shop_page'))
{
if($post_id == wc_get_page_id( 'shop' ))
{
$params = false;
}
}
return $params;
}
}
if( ! function_exists( 'avia_woocommerce_cart_placement' ) )
{
/**
* Place the cart button according to the header layout (top/sidebar)
*/
function avia_woocommerce_cart_placement()
{
$cart_pos = avia_get_option( 'cart_icon', '' );
if( 'no_cart' == $cart_pos )
{
return;
}
$position = avia_get_option( 'header_position', 'header_top' ) == 'header_top' ? 'ava_main_header' : 'ava_inside_main_menu';
if( $cart_pos == 'always_display_menu' )
{
$position = 'ava_inside_main_menu';
if( strpos( avia_get_option( 'header_layout' ), 'bottom_nav_header' ) !== false && avia_get_option( 'header_position' ) == 'header_top' )
{
$position = 'ava_before_bottom_main_menu';
}
}
add_action( $position, 'avia_woocommerce_cart_dropdown', 10 );
}
add_action( 'init', 'avia_woocommerce_cart_placement', 10 );
}
if( ! function_exists( 'avia_woocommerce_cart_pos' ) )
{
/**
* Permanent display of cart button
*
* @param array $class
* @param array $necessary
* @param string $prefix
* @return array
*/
function avia_woocommerce_cart_pos( $class, $necessary, $prefix )
{
$cart_pos = avia_get_option( 'cart_icon', '' );
if( 'no_cart' == $cart_pos )
{
return $class;
}
if( $prefix == 'html_' ) // only for the html tag
{
$cart = WC()->cart->get_cart();
if( $cart_pos == 'always_display' || ( ! empty( $cart ) ) )
{
$class[] = 'visible_cart';
}
if( $cart_pos == 'always_display_menu' )
{
$class[] = 'cart_at_menu';
}
}
return $class;
}
add_filter( 'avf_header_classes', 'avia_woocommerce_cart_pos', 10, 3 );
}
if( ! function_exists( 'avia_woocommerce_cart_dropdown' ) )
{
function avia_woocommerce_cart_dropdown()
{
$cart_items = WC()->cart->get_cart_contents_count();
$cart_subtotal = WC()->cart->get_cart_subtotal();
$link = function_exists( 'wc_get_cart_url' ) ? wc_get_cart_url() : WC()->cart->get_cart_url();
$id = '';
$added = wc_get_notices( 'success' );
$trigger = ! empty( $added ) ? 'av-display-cart-on-load' : '';
$active = $cart_items > 0 ? 'av-active-counter' : '';
if( avia_get_option( 'cart_icon' ) == 'always_display_menu' )
{
$id = 'id="menu-item-shop"';
}
$output = '';
$output .= "';
echo $output;
}
}
if( ! function_exists( 'avia_woocommerce_add_to_cart_fragments' ) )
{
/**
* @since 4.7.6.3
* @param array $fragments
* @return array
*/
function avia_woocommerce_add_to_cart_fragments( $fragments )
{
$cart_items = WC()->cart->get_cart_contents_count();
$active = $cart_items > 0 ? 'av-active-counter' : '';
$fragments['span.av-cart-counter'] = "
{$cart_items}";
return $fragments;
}
add_filter( 'woocommerce_add_to_cart_fragments', 'avia_woocommerce_add_to_cart_fragments');
}
/*
after importing demo pages make sure that if we got multiple shop/my account/etc pages (happens if the user used default woocommerce setup)
to remove the duplicates and set the theme options properly
*/
add_action('avia_after_import_hook', 'avia_woocommerce_set_pages');
// add_action('ava_after_main_container', 'avia_woocommerce_set_pages');
function avia_woocommerce_set_pages()
{
global $wpdb;
$pages = array(
'shop' => array(
'title' => 'Shop',
'slug' => 'shop',
),
'cart' => array(
'title' => 'Cart',
'slug' => 'cart',
),
'checkout' => array(
'title' => 'Checkout',
'slug' => 'checkout',
),
'myaccount' => array(
'title' => 'My Account',
'slug' => 'my-account',
)
);
/*query string to get multiple posts with the same name*/
$pagequery = "SELECT ID FROM $wpdb->posts WHERE post_title = %s AND post_type='page'";
foreach ($pages as $page)
{
$entries = $wpdb->get_results( $wpdb->prepare( $pagequery , $page['title'] ));
if(!empty($entries))
{
$keep = 0;
$delete = array();
//we got one post of that name. the user did not yet activate woocommerce setup or no page with that name was imported
if(count($entries) === 1)
{
$keep = $entries[0]->ID;
}
else //we got 2 or more entries. keep the one with the highest id as woocommerce setting and delete the other ones
{
foreach($entries as $entry)
{
if($entry->ID > $keep)
{
if($keep) $delete[] = $keep;
$keep = $entry->ID;
}
else
{
$delete[] = $entry->ID;
}
}
}
//delete the not required posts
foreach($delete as $delete_id)
{
wp_delete_post( $delete_id, true );
}
if($keep > 0)
{
//store the value of the $keep as the default woo setting
$setting = str_replace("-", "", $page['slug']);
update_option('woocommerce_' . $setting . '_page_id' , $keep);
//modify the page slug and remove any numbers if necessary
$update_post = array(
'ID' => $keep,
'post_name' => $page['slug']
);
wp_update_post( $update_post );
}
}
}
}
/**
* Helper functions for template builder elements - Product grids, slideshows, ......
* ==================================================================================
*
*/
if( ! function_exists( 'avia_wc_set_out_of_stock_query_params' ) )
{
/**
* Returns the query parameters for the "product out of stock" feature for selecting the products
*
* @param array $meta_query
* @param array $tax_query
* @param string $products_visibility 'show'|'hide'|'' for WC default
*/
function avia_wc_set_out_of_stock_query_params( array &$meta_query, array &$tax_query, $products_visibility = '' )
{
/**
* Backwards compatibility WC < 3.0.0
*/
if( ! avia_woocommerce_version_check( '3.0.0') )
{
$meta_query[] = WC()->query->visibility_meta_query();
$meta_query[] = WC()->query->stock_status_meta_query();
$meta_query = array_filter( $meta_query );
}
else
{
switch( $products_visibility )
{
case 'show':
$hide = 'no';
break;
case 'hide':
$hide = 'yes';
break;
default:
$hide = get_option( 'woocommerce_hide_out_of_stock_items', 'no' );
}
if( 'yes' == $hide )
{
$outofstock_term = get_term_by( 'name', 'outofstock', 'product_visibility' );
if( $outofstock_term instanceof WP_Term )
{
$tax_query[] = array(
'taxonomy' => 'product_visibility',
'field' => 'term_taxonomy_id',
'terms' => array( $outofstock_term->term_taxonomy_id ),
'operator' => 'NOT IN'
);
}
}
}
}
}
if( ! function_exists( 'avia_wc_set_hidden_prod_query_params' ) )
{
/**
* Returns the query parameters for the catalog visibility "hidden" feature for selecting the products.
*
* @since 4.1.3
* @param array $meta_query
* @param array $tax_query
* @param string $catalog_visibility 'show'|'hide'|'' for all
*/
function avia_wc_set_hidden_prod_query_params( array &$meta_query, array &$tax_query, $catalog_visibility = '' )
{
if( avia_woocommerce_version_check( '3.0.0') )
{
switch( $catalog_visibility )
{
case 'show':
$operator = 'IN';
break;
case 'hide':
$operator = 'NOT IN';
break;
default:
$operator = '';
}
if( in_array( $operator, array( 'IN', 'NOT IN' ) ) )
{
$hidden_term = get_term_by( 'name', 'exclude-from-catalog', 'product_visibility' );
if( $hidden_term instanceof WP_Term )
{
$tax_query[] = array(
'taxonomy' => 'product_visibility',
'field' => 'term_taxonomy_id',
'terms' => array( $hidden_term->term_taxonomy_id ),
'operator' => $operator
);
}
}
}
}
}
if( ! function_exists( 'avia_wc_set_featured_prod_query_params' ) )
{
/**
* Returns the query parameters for the catalog visibility "hidden" feature for selecting the products.
*
* @since 4.1.3
* @param array $meta_query
* @param array $tax_query
* @param string $catalog_visibility 'show'|'hide'|'' for all
*/
function avia_wc_set_featured_prod_query_params( array &$meta_query, array &$tax_query, $catalog_visibility = '' )
{
if( avia_woocommerce_version_check( '3.0.0') )
{
switch( $catalog_visibility )
{
case 'show':
$operator = 'IN';
break;
case 'hide':
$operator = 'NOT IN';
break;
default:
$operator = '';
}
if( in_array( $operator, array( 'IN', 'NOT IN' ) ) )
{
$featured_term = get_term_by( 'name', 'featured', 'product_visibility' );
if( $featured_term instanceof WP_Term )
{
$tax_query[] = array(
'taxonomy' => 'product_visibility',
'field' => 'term_taxonomy_id',
'terms' => array( $featured_term->term_taxonomy_id ),
'operator' => $operator
);
}
}
}
}
}
if( ! function_exists( 'avia_wc_set_additional_filter_args' ) )
{
/**
* Add additional filters from user selections in widget like
* - minimum / maximum price filter
*
* @since 4.5.5
* @param array $meta_query
* @param array $tax_query
*/
function avia_wc_set_additional_filter_args( array &$meta_query, array &$tax_query )
{
/**
* Filter for Minimum / Maximum Price
*/
$args = array();
if( isset( $_REQUEST['min_price'] ) && is_numeric( $_REQUEST['min_price'] ) )
{
$args['min_price'] = $_REQUEST['min_price'];
}
if( isset( $_REQUEST['max_price'] ) && is_numeric( $_REQUEST['max_price'] ) )
{
$args['max_price'] = $_REQUEST['max_price'];
}
if( ! empty( $args ) )
{
$meta_query[] = wc_get_min_max_price_meta_query( $args );
}
/**
* Additional filters - see woocommerce\includes\class-wc-query.php::get_tax_query()
* ==================
*/
$product_visibility_terms = wc_get_product_visibility_term_ids();
$product_visibility_not_in = array( is_search() && $main_query ? $product_visibility_terms['exclude-from-search'] : $product_visibility_terms['exclude-from-catalog'] );
/**
* Filter for rating
*/
if ( isset( $_REQUEST['rating_filter'] ) )
{
$rating_filter = array_filter( array_map( 'absint', explode( ',', $_REQUEST['rating_filter'] ) ) );
$rating_terms = array();
for ( $i = 1; $i <= 5; $i ++ )
{
if ( in_array( $i, $rating_filter, true ) && isset( $product_visibility_terms[ 'rated-' . $i ] ) )
{
$rating_terms[] = $product_visibility_terms[ 'rated-' . $i ];
}
}
if ( ! empty( $rating_terms ) )
{
$tax_query[] = array(
'taxonomy' => 'product_visibility',
'field' => 'term_taxonomy_id',
'terms' => $rating_terms,
'operator' => 'IN',
'rating_filter' => true,
);
}
}
/**
* Filter for additional attribute filters
*/
$layered_nav_chosen_attributes = WC_Query::get_layered_nav_chosen_attributes();
foreach ( $layered_nav_chosen_attributes as $taxonomy => $data )
{
$tax_query[] = array(
'taxonomy' => $taxonomy,
'field' => 'slug',
'terms' => $data['terms'],
'operator' => 'and' === $data['query_type'] ? 'AND' : 'IN',
'include_children' => false,
);
}
}
}
if( ! function_exists( 'avia_wc_get_product_query_order_args' ) )
{
/**
* Returns the ordering args, either the default catalog settings or the user selected.
* Calls standard WC function to set filter hooks for order by
* and removes previously set filter hooks
*
* @since < 4.0
* @modified 4.5.6
* @param string $order_by
* @param string $order
* @return array
*/
function avia_wc_get_product_query_order_args( $order_by = '', $order = '' )
{
$def_orderby = avia_wc_get_default_catalog_order_by();
$order_by = empty( $order_by ) ? $def_orderby['orderby'] : $order_by;
$order = empty( $order ) ? $def_orderby['order'] : $order;
// remove and set filter hooks !!
WC()->query->remove_ordering_args();
$ordering_args = WC()->query->get_catalog_ordering_args( $order_by, $order );
return $ordering_args;
}
}
if( ! function_exists( 'avia_wc_get_default_catalog_order_by' ) )
{
/**
* Returns the default settings for catalog order by and clears any set filter hook by this function
*
* With Enfold 4.7.6.4 default $order extended to be equal to WC()->query->get_catalog_ordering_args()
*
* @return array
*/
function avia_wc_get_default_catalog_order_by()
{
// does not always return correct values !!!
// $args = WC()->query->get_catalog_ordering_args();
$orderby_value = apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
// Get order + orderby args from string
$orderby_value = explode( '-', $orderby_value );
$orderby = esc_attr( $orderby_value[0] );
if( ! empty( $orderby_value[1] ) )
{
$order = $orderby_value[1];
}
else
{
switch( $orderby )
{
case 'relevance':
case 'date':
$order = 'DESC';
break;
default:
$order = 'ASC';
break;
}
}
$args = array();
$args['orderby'] = strtolower( $orderby );
$args['order'] = ( 'DESC' === strtoupper( $order ) ) ? 'DESC' : 'ASC';
$args['meta_key'] = '';
return $args;
}
}
if( ! function_exists( 'avia_wc_clear_catalog_ordering_args_filters' ) )
{
/**
* Remove all filters set by a call to WC()->query->get_catalog_ordering_args();
*/
function avia_wc_clear_catalog_ordering_args_filters()
{
WC()->query->remove_ordering_args();
}
}
add_filter( 'woocommerce_product_is_visible', 'avia_wc_product_is_visible', 10, 2 );
if( ! function_exists( 'avia_wc_product_is_visible' ) )
{
/**
* Allows to change the default visibility for products in catalog.
*
* WC checks this in the loop when showing products on a catalog page - as we allow user to show/hide products out of stock in various
* builder elements we have to force the display even if visibility is false
*
* @param boolean $visible
* @param int $product_id
* @return boolean
*/
function avia_wc_product_is_visible( $visible, $product_id )
{
global $avia_config;
if( ! isset( $avia_config['woocommerce']['catalog_product_visibility'] ) )
{
return $visible;
}
switch( $avia_config['woocommerce']['catalog_product_visibility'] )
{
case 'show_all':
return true;
case 'hide_out_of_stock':
$product = wc_get_product( $product_id );
if( ! $product instanceof WC_Product )
{
return $visible;
}
return $product->is_in_stock();
case 'use_default':
default:
return $visible;
}
}
}
if( ! function_exists( 'avia_wc_remove_inline_terms' ) )
{
/**
* If a template builder page with a fullwidth el is used for terms and conditions the terms and conditions are not displayed properly. we need to filter that.
* in case the user uses a template builder page do not display the inline terms. returning an empty string will just show the link to the TOS page
*/
add_filter('woocommerce_format_content', 'avia_wc_remove_inline_terms', 10, 2);
function avia_wc_remove_inline_terms( $apply_filters, $raw_string )
{
if( is_checkout() ) {
$id = wc_get_page_id( 'terms' );
if(get_post_meta($id, '_aviaLayoutBuilder_active', true) == "active")
{
return '';
}
}
return $apply_filters;
}
}
add_filter( 'woocommerce_get_settings_checkout' , 'avia_wc_filter_terms_page_selection', 10 , 2);
if( ! function_exists( 'avia_wc_filter_terms_page_selection' ) )
{
/**
* Filter the content description for TOS page selection
*/
function avia_wc_filter_terms_page_selection($settings)
{
foreach($settings as $key => $setting)
{
if( isset( $setting['id'] ) && ( $setting['id'] == "woocommerce_terms_page_id" ) )
{
$settings[$key]['desc'] .= "
".__('Attention! Pages built with the Enfold Advanced Template Builder will not be displayed at the bottom of the checkout page but only with a link.', 'avia_framework');
break;
}
}
return $settings;
}
}
/**
* Force WC images in widgets to have Enfold default image size
*
* @since 4.4.2
* @added_by Günter
*/
add_action( 'woocommerce_widget_product_item_start', 'avia_wc_widget_product_item_start', 10, 1 );
add_filter( 'woocommerce_product_get_image', 'avia_wc_widget_product_image_size', 10, 6 );
add_action( 'woocommerce_widget_product_item_end', 'avia_wc_widget_product_item_end', 10, 1 );
global $avia_wc_product_widget_active;
$avia_wc_product_widget_active = false;
if( ! function_exists( 'avia_wc_widget_product_item_start' ) )
{
/**
* Set a global variable to limit changeing to widget areas only
*
* @since 4.4.2
* @added_by Günter
* @param array $args
* @return array
*/
function avia_wc_widget_product_item_start( $args )
{
global $avia_wc_product_widget_active;
/**
* @since 4.4.2
* @return boolean
*/
if( false !== apply_filters( 'avf_wc_widget_product_image_size_ignore', false, $args ) )
{
return;
}
$avia_wc_product_widget_active = true;
}
}
if( ! function_exists( 'avia_wc_widget_product_image_size' ) )
{
/**
* Modify default WC behaviour.
* Based on the function WC_Product::get_image
*
* @since 4.4.2
* @param string $image
* @param WC_Product $product
* @param string $size
* @param array $attr
* @param boolean $placeholder
* @param string $image1
* @return string
*/
function avia_wc_widget_product_image_size( $image, $product, $size, $attr, $placeholder, $image1 )
{
global $avia_wc_product_widget_active, $avia_config;
if( ! $avia_wc_product_widget_active )
{
return $image;
}
/**
* @since 4.4.2
* @return string
*/
$size = apply_filters( 'avf_wc_widget_product_image_size', 'widget', $product, $size, $attr, $placeholder );
if ( has_post_thumbnail( $product->get_id() ) )
{
$image = get_the_post_thumbnail( $product->get_id(), $size, $attr );
}
elseif ( ( $parent_id = wp_get_post_parent_id( $product->get_id() ) ) && has_post_thumbnail( $parent_id ) ) // @phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.Found
{
$image = get_the_post_thumbnail( $parent_id, $size, $attr );
}
elseif ( $placeholder )
{
$image = wc_placeholder_img( $size );
}
else
{
$image = '';
}
return $image;
}
}
if( ! function_exists( 'avia_wc_widget_product_item_end' ) )
{
/**
* Reset a global variable to limit changeing to widget areas only
*
* @since 4.4.2
* @param array $args
*/
function avia_wc_widget_product_item_end( $args )
{
global $avia_wc_product_widget_active;
$avia_wc_product_widget_active = false;
}
}
/**
* Fix problem with ALB pages used as "Terms and Conditions" page on checkout.
* WC loads page content above the checkbox with js. With ALB this breaks and might also lead to styling problems.
* Therefore we link to an external page.
*
* Up to WC 3.4.5 no hooks are provided to fix this in php. Therefore we have to add a js snippet.
*
* @since 4.4.2
* @added_by Günter
*/
if( ! is_admin() && avia_woocommerce_version_check( '3.4.0' ) )
{
add_action( 'woocommerce_checkout_terms_and_conditions', 'avia_wc_checkout_terms_and_conditions' );
if( ! function_exists( 'avia_wc_checkout_terms_and_conditions' ) )
{
function avia_wc_checkout_terms_and_conditions()
{
$terms_id = wc_get_page_id('terms');
if( 'active' == Avia_Builder()->get_alb_builder_status( $terms_id ) )
{
add_action( 'wp_footer', 'avia_woocommerce_fix_checkout_term_link' );
}
}
}
if( ! function_exists( 'avia_woocommerce_fix_checkout_term_link' ) )
{
function avia_woocommerce_fix_checkout_term_link()
{
$i = 1;
?>