array(
'class' => array()
),
'br' => array()
);
$mess = wp_kses(__('Your cart is currently empty.', 'elessi-theme'), $allowed_html);
return $mess;
}
endif;
/**
* Link account
*/
if (!function_exists('elessi_link_account')) {
function elessi_link_account() {
$links = false;
/* Active woocommerce */
if (NASA_WOO_ACTIVED) {
$myaccount_page_id = get_option('woocommerce_myaccount_page_id');
if ($myaccount_page_id) {
$links = get_permalink($myaccount_page_id);
}
} else {
$links = !NASA_CORE_USER_LOGGED ? wp_login_url() : admin_url('profile.php');
}
return $links ? $links : home_url('/');
}
}
/**
* Tiny account
*/
if (!function_exists('elessi_tiny_account')) {
function elessi_tiny_account($icon = false) {
global $nasa_opt;
if (isset($nasa_opt['hide_tini_menu_acc']) && $nasa_opt['hide_tini_menu_acc']) {
return '';
}
if (isset($nasa_opt['header-type']) && $nasa_opt['header-type'] == '8') {
return '';
}
$links = elessi_link_account();
$result = '
';
return apply_filters('nasa_tiny_account_ajax', $result);
}
}
/**
* Submenu Account
*/
if (!function_exists('elessi_sub_account')) :
function elessi_sub_account() {
if (!NASA_CORE_USER_LOGGED) {
return '';
}
$submenu = '';
return $submenu;
}
endif;
/**
* icon cart
*/
if (!function_exists('elessi_mini_cart_icon')) :
function elessi_mini_cart_icon() {
global $nasa_opt;
$icon_number = isset($nasa_opt['mini-cart-icon']) ? $nasa_opt['mini-cart-icon'] : '1';
switch ($icon_number) {
case '2':
$icon = '' . wp_kses(__('Availability: ', 'elessi-theme'), array('span' => array())) . esc_html($availability['availability']) . '
', $availability['availability']);
}
}
endif;
/**
* Toggle coupon
*/
if (!function_exists('elessi_wrap_coupon_toggle')) :
function elessi_wrap_coupon_toggle($content) {
return '' . $content . '
';
}
endif;
/**
* Tab Combo Yith Bundle product
*/
if (!function_exists('elessi_combo_tab')) :
function elessi_combo_tab($nasa_viewmore = true) {
global $woocommerce, $nasa_opt, $product;
if (!$woocommerce || !$product || $product->get_type() != NASA_COMBO_TYPE || !$combo = $product->get_bundled_items()) {
return false;
}
$file = ELESSI_CHILD_PATH . '/includes/nasa-combo-products-in-detail.php';
$file = is_file($file) ? $file : ELESSI_THEME_PATH . '/includes/nasa-combo-products-in-detail.php';
ob_start();
include $file;
return ob_get_clean();
}
endif;
/**
* Get All categories product filter in top
*/
if (!function_exists('elessi_get_all_categories')) :
function elessi_get_all_categories($show_children_only = false, $main = false, $hierarchical = true) {
if (!NASA_WOO_ACTIVED) {
return;
}
global $nasa_opt, $wp_query, $post;
$hide_empty = (isset($nasa_opt['hide_empty_cat_top']) && $nasa_opt['hide_empty_cat_top']) ? true : false;
$list_args = array(
'taxonomy' => 'product_cat',
'show_count' => 0,
'hierarchical' => $hierarchical,
'hide_empty' => apply_filters('nasa_top_filter_cats_hide_empty', $hide_empty)
);
/**
* Max depth = 0 ~ all
*/
$depth_top = !isset($nasa_opt['depth_cat_top']) ? 0 : (int) $nasa_opt['depth_cat_top'];
$max_depth = apply_filters('nasa_max_depth_top_filter_cats', $depth_top);
$order = isset($nasa_opt['order_cat_top']) ? $nasa_opt['order_cat_top'] : 'name';
$list_args['menu_order'] = false;
if (apply_filters('nasa_top_filter_categories_orderby', $order) == 'order') {
$list_args['orderby'] = 'meta_value_num';
$list_args['meta_key'] = 'order';
} else {
$list_args['orderby'] = 'title';
}
$current_cat = false;
$cat_ancestors = array();
$root_id = 0;
/**
* post type page
*/
if (
isset($nasa_opt['disable_top_level_cat']) &&
$nasa_opt['disable_top_level_cat'] &&
isset($post->ID) &&
$post->post_type == 'page'
) {
$current_slug = get_post_meta($post->ID, '_nasa_root_category', true);
if ($current_slug) {
$current_cat = get_term_by('slug', $current_slug, 'product_cat');
if ($current_cat && isset($current_cat->term_id)) {
$cat_ancestors = get_ancestors($current_cat->term_id, 'product_cat');
}
}
}
/**
* Archive product category
*/
elseif (is_tax('product_cat')) {
$current_cat = $wp_query->queried_object;
$cat_ancestors = get_ancestors($current_cat->term_id, 'product_cat');
}
/**
* Single product page
*/
elseif (is_singular('product')) {
$terms = wc_get_product_terms(
$post->ID,
'product_cat',
apply_filters(
'woocommerce_product_categories_widget_product_terms_args',
array(
'orderby' => 'parent',
'order' => 'DESC',
)
)
);
if ($terms) {
$main_term = apply_filters('woocommerce_product_categories_widget_main_term', $terms[0], $terms);
$current_cat = $main_term;
$cat_ancestors = get_ancestors($main_term->term_id, 'product_cat');
}
}
/**
* Only Show Children
*/
if ($show_children_only && $current_cat) {
if ($hierarchical) {
$include = array_merge(
$cat_ancestors,
array($current_cat->term_id),
get_terms(
'product_cat',
array(
'fields' => 'ids',
'parent' => 0,
'hierarchical' => true,
'hide_empty' => false,
)
),
get_terms(
'product_cat',
array(
'fields' => 'ids',
'parent' => $current_cat->term_id,
'hierarchical' => true,
'hide_empty' => false,
)
)
);
// Gather siblings of ancestors.
if ($cat_ancestors) {
foreach ($cat_ancestors as $ancestor) {
$include = array_merge(
$include,
get_terms(
'product_cat',
array(
'fields' => 'ids',
'parent' => $ancestor,
'hierarchical' => false,
'hide_empty' => false,
)
)
);
}
}
} else {
// Direct children.
$include = get_terms(
'product_cat',
array(
'fields' => 'ids',
'parent' => $current_cat->term_id,
'hierarchical' => true,
'hide_empty' => false,
)
);
}
$list_args['include'] = implode(',', $include);
if (empty($include)) {
return;
}
}
elseif ((isset($nasa_opt['disable_top_level_cat']) && $nasa_opt['disable_top_level_cat'])) {
$root_id = $cat_ancestors ? end($cat_ancestors) :
($current_cat ? $current_cat->term_id : $root_id);
$list_args['child_of'] = apply_filters('nasa_root_id_top_filter_cats', $root_id);
}
elseif ($show_children_only) {
$list_args['child_of'] = 0;
$list_args['depth'] = 1;
$list_args['hierarchical'] = 1;
}
$list_args['walker'] = new Elessi_Product_Cat_List_Walker($max_depth);
$list_args['title_li'] = '';
$list_args['pad_counts'] = 1;
$list_args['show_option_none'] = esc_html__('No product categories exist.', 'elessi-theme');
$list_args['current_category'] = $current_cat ? $current_cat->term_id : '';
$list_args['current_category_ancestors'] = $cat_ancestors;
$list_args['max_depth'] = '';
$list_args['echo'] = false;
if (!isset($nasa_opt['show_uncategorized']) || !$nasa_opt['show_uncategorized']) {
$uncategorized = get_option('default_product_cat');
if ($uncategorized) {
$list_args['exclude'] = $uncategorized;
}
}
$nasa_top_filter = '' : '
';
$result .= $tmpl ? '' : '';
$result .= $nasa_top_filter;
$result .= $tmpl ? '' : '';
$result .= '
';
return $result;
}
endif;
/**
* nasa_archive_get_sub_categories
*/
add_action('nasa_archive_get_sub_categories', 'elessi_archive_get_sub_categories');
if (!function_exists('elessi_archive_get_sub_categories')) :
function elessi_archive_get_sub_categories() {
$GLOBALS['nasa_cat_loop_delay'] = 0;
echo '
';
woocommerce_product_subcategories(array(
'before' => '
' . esc_html__('Subcategories: ', 'elessi-theme') . '
',
'after' => '
'
));
echo '
';
}
endif;
/**
* Filter Paginate Links
*
* Since 4.6.3
*/
add_filter('paginate_links', 'elessi_paginate_links');
if (!function_exists('elessi_paginate_links')) :
function elessi_paginate_links($link) {
if (!defined('NASA_AJAX_SHOP') || !NASA_AJAX_SHOP) {
return $link;
}
if ('/page/1' === substr($link, strlen($link)-7, 7)) {
return str_replace('/page/1', '', $link);
}
return str_replace('/page/1/', '/', $link);
}
endif;
add_filter('paginate_links_output', 'elessi_modify_paginate_links_output', 10, 2);
if (!function_exists('elessi_modify_paginate_links_output')) :
function elessi_modify_paginate_links_output($r, $args) {
global $nasa_opt;
if (isset($nasa_opt['single_review_ajax']) && $nasa_opt['single_review_ajax'] && NASA_WOO_ACTIVED && is_product()) {
// $comment_order = get_option('comment_order');
$current = (int) $args['current'];
$total = (int) $args['total'];
$link = str_replace('%_%', $args['format'], $args['base']);
$link = str_replace('%#%', $current + 1, $link);
$elclass = $current + 1 > $total ? 'hidden-tag' : '';
$r = '
';
}
return $r;
}
endif;
add_filter('comment_text', 'elessi_custom_comment_text', 30, 3);
if (!function_exists('elessi_custom_comment_text')) :
function elessi_custom_comment_text($comment_text, $comment, $args) {
if (NASA_WOO_ACTIVED && is_product()) {
$comment_text .= '
' . apply_filters('ns_comment_text_read_more', '[...]') . '';
}
return $comment_text;
}
endif;
add_action('pre_get_comments', 'elessi_filter_reviews_product');
if (!function_exists('elessi_filter_reviews_product')) :
function elessi_filter_reviews_product($query) {
if (!NASA_WOO_ACTIVED) {
return;
}
$sort_type = isset($_GET['review_sort']) && $_GET['review_sort'] != '' ? $_GET['review_sort'] : 'date_DESC';
update_option('default_comments_page', 'oldest');
update_option('comment_order', 'asc');
if (is_product()) {
switch ($sort_type) {
case 'rating_ASC':
$query->query_vars['orderby'] = 'meta_value_num';
$query->query_vars['meta_key'] = 'rating';
$query->query_vars['order'] = 'ASC';
break;
case 'rating_DESC':
$query->query_vars['orderby'] = 'meta_value_num';
$query->query_vars['meta_key'] = 'rating';
$query->query_vars['order'] = 'DESC';
break;
case 'media_DESC':
$meta_query = array(
array(
'key' => 'nasa_review_images',
'compare' => 'EXISTS',
),
);
$query->query_vars['meta_query'] = $meta_query;
$query->query_vars['orderby'] = 'comment_date';
$query->query_vars['order'] = 'DESC';
break;
case 'date_ASC':
$query->query_vars['orderby'] = 'comment_date';
$query->query_vars['order'] = 'ASC';
break;
case 'date_DESC':
$query->query_vars['orderby'] = 'comment_date';
$query->query_vars['order'] = 'DESC';
break;
default:
break;
}
}
}
endif;
/**
* Filter Pagination args
*
* Since 4.6.3
*/
add_filter('woocommerce_pagination_args', 'elessi_pagination_args');
if (!function_exists('elessi_pagination_args')) :
function elessi_pagination_args($args) {
if (empty($args)) {
$args = array();
}
$args['prev_text'] = '
';
$args['next_text'] = '
';
$args['type'] = 'list';
$args['end_size'] = 1;
$args['mid_size'] = 1;
return $args;
}
endif;
/**
* No paging url
*/
if (!function_exists('elessi_nopaging_url')) :
function elessi_nopaging_url() {
global $wp;
if (!$wp->request) {
return false;
}
$current_url = home_url($wp->request);
$pattern = '/page(\/)*([0-9\/])*/i';
$nopaging_url = preg_replace($pattern, '', $current_url);
return trailingslashit($nopaging_url);
}
endif;
/**
* Compatible WooCommerce_Advanced_Free_Shipping
* Only with one Rule "subtotal >= Rule"
*/
add_action('nasa_subtotal_free_shipping', 'elessi_subtotal_free_shipping');
add_action('woocommerce_widget_shopping_cart_total', 'elessi_subtotal_free_shipping', 20);
if (!function_exists('elessi_subtotal_free_shipping')) :
function elessi_subtotal_free_shipping($return = false) {
global $nasa_opt;
$value = 0;
$content = '';
/**
* Check active plug-in WooCommerce || WooCommerce_Advanced_Free_Shipping
*/
if (
(isset($nasa_opt['free_shipbar']) && !$nasa_opt['free_shipbar']) ||
!NASA_WOO_ACTIVED ||
!class_exists('WooCommerce_Advanced_Free_Shipping') ||
!function_exists('WAFS')
) {
return $content;
}
/**
* Check setting plug-in
*/
$wafs = WAFS();
if (!isset($wafs->was_method)) {
$wafs->wafs_free_shipping();
}
$wafs_method = isset($wafs->was_method) ? $wafs->was_method : null;
if (!$wafs_method || $wafs_method->enabled === 'no') {
return $content;
}
/**
* Check has
*/
$wafs_posts = get_posts(array(
// 'posts_per_page' => 2,
'post_status' => 'publish',
'post_type' => 'wafs'
));
if (!$wafs_posts || count($wafs_posts) < 1) {
return $content;
}
require_once ELESSI_THEME_PATH . '/cores/nasa-advanced-free-shipping.php';
$out_nsafs = false;
/**
* Check and Rules
*/
foreach ($wafs_posts as $wafs_post) {
$condition_groups = get_post_meta($wafs_post->ID, '_wafs_shipping_method_conditions', true);
if (!$condition_groups || count($condition_groups) < 1) {
continue;
}
$condition_group = reset($condition_groups);
if (!$condition_group || count($condition_group) < 1) {
continue;
}
$nsafs = new Nasa_Advanced_Free_Shipping($condition_group);
if (!$nsafs->render) {
continue;
}
if ($out_nsafs && $out_nsafs->value > $nsafs->value) {
$out_nsafs = $nsafs;
}
if (!$out_nsafs && $nsafs->render) {
$out_nsafs = $nsafs;
}
}
if ($out_nsafs) {
$content = $out_nsafs->output_html();
}
if (!$return) {
echo $content;
return;
}
return $content;
}
endif;
/**
* Add Free_Shipping to Cart page
*/
add_action('woocommerce_cart_contents', 'elessi_subtotal_free_shipping_in_cart');
if (!function_exists('elessi_subtotal_free_shipping_in_cart')) :
function elessi_subtotal_free_shipping_in_cart() {
$content = elessi_subtotal_free_shipping(true);
if ($content !== '') {
echo '
| ' . $content . ' |
';
}
}
endif;
/**
* Before account Navigation
*/
add_action('woocommerce_before_account_navigation', 'elessi_before_account_nav');
if (!function_exists('elessi_before_account_nav')) :
function elessi_before_account_nav() {
if (!NASA_WOO_ACTIVED || !NASA_CORE_USER_LOGGED) {
return;
}
$current_user = wp_get_current_user();
?>
ID, 60); ?>
display_name); ?>
';
}
endif;
/**
* Account Dashboard Square
*/
add_action('woocommerce_account_dashboard', 'elessi_account_dashboard_nav');
if (!function_exists('elessi_account_dashboard_nav')) :
function elessi_account_dashboard_nav() {
if (!NASA_WOO_ACTIVED || !NASA_CORE_USER_LOGGED) {
return;
}
$extra_class = 'nasa-MyAccount-navigation';
$file = ELESSI_CHILD_PATH . '/includes/nasa-acc-nav.php';
include is_file($file) ? $file : ELESSI_THEME_PATH . '/includes/nasa-acc-nav.php';
}
endif;
/**
* Custom class Single product Price
*/
add_filter('woocommerce_product_price_class', 'elessi_product_price_class');
if (!function_exists('elessi_product_price_class')) :
function elessi_product_price_class($class) {
$class .= ' nasa-single-product-price';
return $class;
}
endif;
/**
* Custom class Single product tabs
*/
add_filter('nasa_single_product_tabs_style', 'elessi_single_product_tabs_class');
if (!function_exists('elessi_single_product_tabs_class')) :
function elessi_single_product_tabs_class($class) {
global $nasa_opt;
$classes = isset($nasa_opt['tab_style_info']) ? $nasa_opt['tab_style_info'] : $class;
return $classes;
}
endif;
/**
* Override woocommerce_catalog_orderby
*/
add_filter('woocommerce_catalog_orderby', 'elessi_wc_catalog_orderby');
if (!function_exists('elessi_wc_catalog_orderby')) :
function elessi_wc_catalog_orderby($catalogs) {
return array(
'menu_order' => __('Default sorting', 'elessi-theme'),
'popularity' => __('Popularity', 'elessi-theme'),
'rating' => __('Average rating', 'elessi-theme'),
'date' => __('Latest', 'elessi-theme'),
'price' => __('Price: Ascending', 'elessi-theme'),
'price-desc' => __('Price: Descending', 'elessi-theme'),
);
}
endif;
/**
* Get Root term_id
*/
if (!function_exists('elessi_get_root_term_id')) :
function elessi_get_root_term_id() {
return function_exists('nasa_root_term_id') ? nasa_root_term_id() : false;
}
endif;
/**
* Hook Before render shop
*/
add_action('nasa_before_render_shop', 'elessi_override_options_shop');
if (!function_exists('elessi_override_options_shop')) :
function elessi_override_options_shop() {
global $nasa_opt;
$mobile_app = (isset($nasa_opt['nasa_in_mobile']) && $nasa_opt['nasa_in_mobile'] && isset($nasa_opt['mobile_layout']) && $nasa_opt['mobile_layout'] == 'app') ? true : false;
/**
* Override for Root Category
*/
$root_cat_id = !$mobile_app ? elessi_get_root_term_id() : false;
if ($root_cat_id) {
/* Override cat side-bar layout */
$cat_sidebar_style = get_term_meta($root_cat_id, 'cat_sidebar_layout', true);
if ($cat_sidebar_style != '') {
$nasa_opt['category_sidebar'] = $cat_sidebar_style;
}
/**
* Product Type view
*/
$cat_type_view = get_term_meta($root_cat_id, 'cat_type_view', true);
if ($cat_type_view != '') {
$nasa_opt['products_type_view'] = $cat_type_view;
}
/**
* Change Shop Layout Mode
*/
$cat_change_shop_layout = get_term_meta($root_cat_id, 'cat_change_shop_layout', true);
if ($cat_change_shop_layout != '') {
$nasa_opt['option_change_shop_layout'] = $cat_change_shop_layout;
}
/**
* Product Column Icon Style
*/
$cat_change_layout_type = get_term_meta($root_cat_id, 'cat_change_layout_type', true);
if ($cat_change_layout_type != '') {
$nasa_opt['nasa_change_layout_view'] = $cat_change_layout_type;
}
/**
* Product Change View mode
*/
$cat_change_view = get_term_meta($root_cat_id, 'cat_change_view', true);
if ($cat_change_view != '') {
$nasa_opt['enable_change_view'] = $cat_change_view == -1 ? false : '1';
}
/**
* Product Option Column Select To Display
*/
$cat_multicheck_options_cols_display = get_term_meta($root_cat_id, 'cat_multicheck_options_cols_display', true);
if (!empty($cat_multicheck_options_cols_display)) {
$nasa_opt['multicheck_options_cols_display'] = $cat_multicheck_options_cols_display;
}
/**
* Product Per row
*/
$cat_per_row = get_term_meta($root_cat_id, 'cat_per_row', true);
if ($cat_per_row != '') {
$nasa_opt['products_per_row'] = $cat_per_row;
}
/**
* Product Per row Medium
*/
$cat_per_row_medium = get_term_meta($root_cat_id, 'cat_per_row_medium', true);
if ($cat_per_row_medium != '') {
$nasa_opt['products_per_row_tablet'] = $cat_per_row_medium;
}
/**
* Product Per row Small
*/
$cat_per_row_small = get_term_meta($root_cat_id, 'cat_per_row_small', true);
if ($cat_per_row_small != '') {
$nasa_opt['products_per_row_small'] = $cat_per_row_small;
}
/**
* Products layout_style
*/
$cat_layout_style = get_term_meta($root_cat_id, 'cat_layout_style', true);
if ($cat_layout_style != '') {
$nasa_opt['products_layout_style'] = $cat_layout_style;
}
/**
* Products masonry_mode
*/
$cat_masonry_mode = get_term_meta($root_cat_id, 'cat_masonry_mode', true);
if ($cat_masonry_mode != '') {
$nasa_opt['products_masonry_mode'] = $cat_masonry_mode;
}
/**
* Products Recommended Columns
*/
$cat_recommend_columns = get_term_meta($root_cat_id, 'cat_recommend_columns', true);
if ($cat_recommend_columns != '') {
$nasa_opt['recommend_columns_desk'] = $cat_recommend_columns;
}
/**
* Products Recommend Columns Medium
*/
$cat_recommend_columns_medium = get_term_meta($root_cat_id, 'cat_recommend_columns_medium', true);
if ($cat_recommend_columns_medium != '') {
$nasa_opt['recommend_columns_tablet'] = $cat_recommend_columns_medium;
}
/**
* Products Recommended Columns Small
*/
$cat_recommend_columns_small = get_term_meta($root_cat_id, 'cat_recommend_columns_small', true);
if ($cat_recommend_columns_small != '') {
$nasa_opt['recommend_columns_small'] = $cat_recommend_columns_small;
}
}
if ($mobile_app) {
$nasa_opt['category_sidebar'] = 'top';
}
$GLOBALS['nasa_opt'] = $nasa_opt;
}
endif;
/**
* Hook Before render shop
*/
add_action('nasa_before_render_single_product', 'elessi_override_options_single_product');
if (!function_exists('elessi_override_options_single_product')) :
function elessi_override_options_single_product() {
global $nasa_opt;
/**
* Override for Root Category
*/
$root_cat_id = elessi_get_root_term_id();
if ($root_cat_id) {
/**
* Products Relate Columns
*/
$cat_relate_columns = get_term_meta($root_cat_id, 'cat_relate_columns', true);
if ($cat_relate_columns != '') {
$nasa_opt['relate_columns_desk'] = $cat_relate_columns;
}
/**
* Products Relate Columns Medium
*/
$cat_relate_columns_medium = get_term_meta($root_cat_id, 'cat_relate_columns_medium', true);
if ($cat_relate_columns_medium != '') {
$nasa_opt['relate_columns_tablet'] = $cat_relate_columns_medium;
}
/**
* Products Relate Columns Small
*/
$cat_relate_columns_small = get_term_meta($root_cat_id, 'cat_relate_columns_small', true);
if ($cat_relate_columns_small != '') {
$nasa_opt['relate_columns_small'] = $cat_relate_columns_small;
}
}
$GLOBALS['nasa_opt'] = $nasa_opt;
}
endif;
/**
* Add sku to product search
*/
add_action('pre_get_posts', 'elessi_pre_get_posts_sku');
if (!function_exists('elessi_pre_get_posts_sku')) :
function elessi_pre_get_posts_sku($query) {
global $nasa_opt;
// conditions - change the post type clause if you're not searching woocommerce or 'product' post type
if (
NASA_CORE_IN_ADMIN ||
!isset($nasa_opt['sp_search_sku']) ||
!$nasa_opt['sp_search_sku'] ||
!$query->is_main_query() ||
!$query->is_search() ||
'product' != get_query_var('post_type')
){
return;
}
add_filter('posts_join', 'elessi_sku_search_join');
add_filter('posts_where', 'elessi_sku_search_where');
add_filter('posts_groupby', 'elessi_sku_search_groupby');
}
endif;
/**
* Filter JOIN with _sku
*/
if (!function_exists('elessi_sku_search_join')) :
function elessi_sku_search_join($join) {
global $wpdb;
// change to your meta key if not woo
$join .= ' LEFT JOIN ' . $wpdb->postmeta . ' nspm ON (' . $wpdb->posts . '.ID = nspm.post_id AND nspm.meta_key="_sku")';
return $join;
}
endif;
/**
* Filter WHERE with _sku
*/
if (!function_exists('elessi_sku_search_where')) :
function elessi_sku_search_where($where) {
global $wpdb;
return preg_replace(
"/\(\s*{$wpdb->posts}.post_title\s+LIKE\s*(\'[^\']+\')\s*\)/",
'(' . $wpdb->posts . '.post_title LIKE $1) OR (nspm.meta_value LIKE $1)',
$where
);
}
endif;
/**
* Filter GROUP BY id with _sku
*/
if (!function_exists('elessi_sku_search_groupby')) :
function elessi_sku_search_groupby($groupby) {
global $wpdb;
$nsgroupby = $wpdb->posts . '.ID';
if (preg_match("/$nsgroupby/", $groupby)) {
// grouping we need is already there
return $groupby;
}
if (!strlen(trim($groupby))) {
// groupby was empty, use ours
return $nsgroupby;
}
// wasn't empty, append ours
return $groupby . ', ' . $nsgroupby;
}
endif;
/**
* Cart Total Coupons - Label
*/
add_filter('woocommerce_cart_totals_coupon_label', 'elessi_cart_totals_coupon_label');
if (!function_exists('elessi_cart_totals_coupon_label')) :
function elessi_cart_totals_coupon_label($label) {
return esc_html__('Coupon', 'elessi-theme');
}
endif;
/**
* Cart Total Coupons - HTML
*/
add_filter('woocommerce_cart_totals_coupon_html', 'elessi_cart_totals_coupon_html', 10, 3);
if (!function_exists('elessi_cart_totals_coupon_html')) :
function elessi_cart_totals_coupon_html($coupon_html, $coupon, $discount_amount_html) {
$code = $coupon->get_code();
$href = add_query_arg('remove_coupon', rawurlencode($code), defined('WOOCOMMERCE_CHECKOUT') ? wc_get_checkout_url() : wc_get_cart_url());
$coupon_html = '
' .
'' .
'' . $code . '' .
$discount_amount_html .
'';
return $coupon_html;
}
endif;
/**
* get List Coupons - Publish
*/
if (!function_exists('elessi_wc_publish_coupons')) :
function elessi_wc_publish_coupons() {
global $nasa_opt;
$coupons = array();
if (isset($nasa_opt['mini_cart_p_coupon']) && $nasa_opt['mini_cart_p_coupon']) {
$coupons_fetch = explode("\n", $nasa_opt['mini_cart_p_coupon']);
if (!empty($coupons_fetch)) {
foreach ($coupons_fetch as $coupon) {
$code = trim($coupon);
$coupon_obj = new WC_Coupon($code);
if ($coupon_obj instanceof WC_Coupon && $coupon_obj->get_id()) {
$coupons[] = $coupon_obj;
}
}
}
}
return $coupons;
}
endif;
/**
* Comment media img Template
*/
add_filter('woocommerce_product_review_comment_form_args', 'elessi_comment_media_upload', 9999);
if (!function_exists('elessi_comment_media_upload')) :
function elessi_comment_media_upload($comment_form) {
global $nasa_opt;
if (!isset($nasa_opt['comment_media']) || !$nasa_opt['comment_media'] || !isset($comment_form['comment_field'])) {
return $comment_form;
}
$svg_alert = '
';
$cam_img = '
';
$plus_svg = '
';
$max_size = isset($nasa_opt['maxsize_comment_media']) && (int) $nasa_opt['maxsize_comment_media'] ? (int) $nasa_opt['maxsize_comment_media'] : 1024;
$max_files = isset($nasa_opt['maxfiles_comment_media']) && (int) $nasa_opt['maxfiles_comment_media'] ? (int) $nasa_opt['maxfiles_comment_media'] : 3;
$label = sprintf(esc_html__('Maximum file size is %s kB, max %s files', 'elessi-theme'), $max_size, $max_files);
$label2 = '
' . $cam_img . '' .
'
' . esc_html__('Upload photos', 'elessi-theme') . ' (0/' . $max_files .')' .
'' . $svg_alert . $label . '';
$media_html = '' .
'' .
'' .
' ' .
'
';
if (!NASA_CORE_USER_LOGGED) {
$comment_form['fields']['nasa-comment-media-video'] = $media_html;
} else {
$comment_form['comment_field'] .= $media_html;
}
return $comment_form;
}
endif;
/**
* Comment media video Template
*/
add_filter('woocommerce_product_review_comment_form_args', 'elessi_comment_media_upload_video', 9999);
if (!function_exists('elessi_comment_media_upload_video')) :
function elessi_comment_media_upload_video($comment_form) {
global $nasa_opt;
if (!isset($nasa_opt['comment_media_video']) || !$nasa_opt['comment_media_video'] || !isset($comment_form['comment_field'])) {
return $comment_form;
}
$svg_alert = '';
$cam_img = '';
$plus_svg = '';
$max_size = isset($nasa_opt['maxsize_comment_media_video']) && (int) $nasa_opt['maxsize_comment_media_video'] ? (int) $nasa_opt['maxsize_comment_media_video'] : 1024;
$max_files = isset($nasa_opt['maxfiles_comment_media_video']) && (int) $nasa_opt['maxfiles_comment_media_video'] ? (int) $nasa_opt['maxfiles_comment_media_video'] : 1;
$label = sprintf(_n('Maximum file size is %s kB, max %s file', 'Maximum file size is %s kB, max %s files', $max_files, 'elessi-theme'), $max_size,$max_files);
$label2 = '' . $cam_img . '' .
'' . sprintf(_n('Upload video', 'Upload videos', $max_files, 'elessi-theme')) . ' (0/' . $max_files . ')' .
'' . $svg_alert . $label . '';
// video input
$media_html = '' .
'' .
'' .
'' .
'
';
if (!NASA_CORE_USER_LOGGED) {
$comment_form['fields']['nasa-comment-media'] = $media_html;
} else {
$comment_form['comment_field'] .= $media_html;
}
return $comment_form;
}
endif;
/**
* Process comment media
*/
add_filter('preprocess_comment', 'elessi_preprocess_review_media', 10);
if (!function_exists('elessi_preprocess_review_media')) :
function elessi_preprocess_review_media($commentdata) {
global $nasa_opt;
$files_img = isset($_FILES['ns_image_upload']) && !empty($_FILES['ns_image_upload']) ? $_FILES['ns_image_upload'] : array();
$files_video = isset($_FILES['ns_video_upload']) && !empty($_FILES['ns_video_upload']) ? $_FILES['ns_video_upload'] : array();
if (empty($files_img) && empty($files_video)) {
return $commentdata;
}
if (isset($nasa_opt['comment_media']) && $nasa_opt['comment_media'] && !empty($files_img)) {
$max_size = isset($nasa_opt['maxsize_comment_media']) && (int) $nasa_opt['maxsize_comment_media'] ? (int) $nasa_opt['maxsize_comment_media'] : 1024;
$max_files = isset($nasa_opt['maxfiles_comment_media']) && (int) $nasa_opt['maxfiles_comment_media'] ? (int) $nasa_opt['maxfiles_comment_media'] : 3;
/**
* Allow maxfiles upload
*/
if (isset($files_img['name']) && count($files_img['name']) > $max_files) {
$mess = '' . esc_html__('Error: ', 'elessi-theme') . '' . sprintf(esc_html__('Maximum number of image files allowed is: %s file(s)', 'elessi-theme'), $max_files);
wp_die($mess);
}
/**
* Allow maxsize upload
*/
if (isset($files_img['size']) && !empty($files_img['size'])) {
foreach ($files_img['size'] as $k => $size) {
if (!$size) {
if (isset($files_img['name'][$k])) {
unset($files_img['name'][$k]);
}
if (isset($files_img['type'][$k])) {
unset($files_img['type'][$k]);
}
if (isset($files_img['size'][$k])) {
unset($files_img['size'][$k]);
}
continue;
}
if ($size > ($max_size * 1024)) {
$mess = '' . esc_html__('Error: ', 'elessi-theme') . '' . sprintf(esc_html__('Max image size allowed: %s kB', 'elessi-theme'), $max_size);
wp_die($mess);
}
}
}
/**
* Allow Types upload
*/
if (isset($files_img['type']) && !empty($files_img['type'])) {
foreach ($files_img['type'] as $type) {
$type_file = strtolower($type);
if (!in_array($type_file, array("image/jpg", "image/jpeg", "image/bmp", "image/png", "image/gif" ))) {
wp_die(esc_html__('Only format image accepted: JPG, JPEG, BMP, PNG, GIF', 'elessi-theme'));
}
}
}
}
if (isset($nasa_opt['comment_media_video']) && $nasa_opt['comment_media_video'] && !empty($files_video)) {
$max_size = isset($nasa_opt['maxsize_comment_media_video']) && (int) $nasa_opt['maxsize_comment_media_video'] ? (int) $nasa_opt['maxsize_comment_media_video'] : 1024;
$max_files = isset($nasa_opt['maxfiles_comment_media_video']) && (int) $nasa_opt['maxfiles_comment_media_video'] ? (int) $nasa_opt['maxfiles_comment_media_video'] : 1;
/**
* Allow maxfiles upload
*/
if (isset($files_video['name']) && count($files_video['name']) > $max_files) {
$mess = '' . esc_html__('Error: ', 'elessi-theme') . '' . sprintf(esc_html__('Maximum number of video files allowed is: %s file(s)', 'elessi-theme'), $max_files);
wp_die($mess);
}
/**
* Allow maxsize upload
*/
if (isset($files_video['size']) && !empty($files_video['size'])) {
foreach ($files_video['size'] as $k => $size) {
if (!$size) {
if (isset($files_video['name'][$k])) {
unset($files_video['name'][$k]);
}
if (isset($files_video['type'][$k])) {
unset($files_video['type'][$k]);
}
if (isset($files_video['size'][$k])) {
unset($files_video['size'][$k]);
}
continue;
}
if ($size > ($max_size * 1024)) {
$mess = '' . esc_html__('Error: ', 'elessi-theme') . '' . sprintf(esc_html__('Max video size allowed: %s kB', 'elessi-theme'), $max_size);
wp_die($mess);
}
}
}
/**
* Allow Types upload
*/
if (isset($files_video['type']) && !empty($files_video['type'])) {
foreach ($files_video['type'] as $type) {
$type_file = strtolower($type);
if (!in_array($type_file, array("video/mp4", "video/avi", "video/mpeg", "video/mov" ))) {
wp_die(esc_html__('Only format video accepted: MP4, AVI, MPEG, MOV', 'elessi-theme'));
}
}
}
}
/**
* Allow upload images
*/
add_action('comment_post', 'elessi_add_review_media', 10, 1);
return $commentdata;
}
endif;
/**
* Add Review images
*/
if (!function_exists('elessi_add_review_media')) :
function elessi_add_review_media($comment_id) {
$comment = get_comment($comment_id);
$post_id = isset($comment->comment_post_ID) ? $comment->comment_post_ID : null;
$files_img = $_FILES["ns_image_upload"];
$files_video = $_FILES["ns_video_upload"];
$files = array();
if (!empty($files_img) && !empty($files_video)) {
foreach ($files_img as $key => $value) {
$files[$key] = array_merge($files_img[$key], $files_video[$key]);
}
} else {
$files = !empty($files_img) ? $files_img : $files_video;
}
$media_id = array();
if (!empty($files['name'])) {
require_once ABSPATH . 'wp-admin/includes/image.php';
require_once ABSPATH . 'wp-admin/includes/file.php';
require_once ABSPATH . 'wp-admin/includes/media.php';
add_filter('intermediate_image_sizes_advanced', 'elessi_comment_img_sizes');
add_filter('big_image_size_threshold', '__return_false');
foreach ($files['name'] as $key => $value) {
if ($files['size'][$key]) {
$file = array(
'name' => apply_filters('nasa_photo_reviews_image_file_name', $value, $comment_id, $post_id),
'type' => $files['type'][$key],
'tmp_name' => $files['tmp_name'][$key],
'error' => $files['error'][$key],
'size' => $files['size'][$key]
);
$_FILES["upload_file"] = $file;
$attachment_id = media_handle_upload("upload_file", $post_id);
if (is_wp_error($attachment_id)) {
wp_die($attachment_id->get_error_message());
} else {
$media_id[] = $attachment_id;
}
}
}
remove_filter('intermediate_image_sizes_advanced', 'elessi_comment_img_sizes');
}
if (!empty($media_id)) {
update_comment_meta($comment_id, 'nasa_review_images', $media_id);
}
}
endif;
if (!function_exists('get_latest_reviews_attachment_ids_with_images')) :
function get_latest_reviews_attachment_ids_with_images($product_id, $limit = 5) {
$attachment_ids= [];
$k = 0;
$args = array(
'post_id' => $product_id,
// 'number' => $limit,
'status' => 'approve',
'meta_query' => array(
array(
'key' => 'nasa_review_images',
'compare' => 'EXISTS'
),
),
'orderby' => 'comment_date',
'order' => 'DESC',
);
$comments = get_comments($args);
if (!empty($comments)) {
foreach ($comments as $comment) {
$review_images = get_comment_meta($comment->comment_ID, 'nasa_review_images', true);
if (!empty($review_images) && is_array($review_images)) {
foreach ($review_images as $attachment_id) {
$k++;
if (count($attachment_ids) < 5) {
$attachment_ids[] = $attachment_id;
}
}
}
}
}
return ['attachment_ids' => $attachment_ids, 'count' => $k];
}
endif;
/**
* Image size upload for Images review product
*/
if (!function_exists('elessi_comment_img_sizes')) :
function elessi_comment_img_sizes($sizes) {
if (isset($sizes['thumbnail'])) {
return array('thumbnail' => $sizes['thumbnail']);
}
return $sizes;
}
endif;
/**
* Show Review images
*/
add_action('woocommerce_review_before', 'elessi_review_images', 10, 1);
if (!function_exists('elessi_review_images')) :
function elessi_review_images($comment) {
global $nasa_opt;
if (!isset($nasa_opt['comment_media']) || !$nasa_opt['comment_media']) {
return;
}
$file = ELESSI_CHILD_PATH . '/includes/nasa-review-images.php';
include is_file($file) ? $file : ELESSI_THEME_PATH . '/includes/nasa-review-images.php';
}
endif;
// add_action('woocommerce_review_after_comment_text', 'elessi_review_helpful', 10, 1);
add_action('woocommerce_review_before', 'elessi_review_helpful', 10, 1);
if (!function_exists('elessi_review_helpful')) :
function elessi_review_helpful($comment) {
global $nasa_opt;
if (!isset($nasa_opt['ns_comment_helpful']) || !$nasa_opt['ns_comment_helpful']) {
return;
}
$file = ELESSI_CHILD_PATH . '/includes/nasa-review-helpful.php';
include is_file($file) ? $file : ELESSI_THEME_PATH . '/includes/nasa-review-helpful.php';
}
endif;
/**
* Add Svg Account Dashboard Square
*/
if (!function_exists('elessi_add_svg_images')) :
function elessi_add_svg_images($endpoint) {
$svg = '';
switch ($endpoint) {
case 'orders':
$svg = '';
break;
case 'downloads':
$svg = '';
break;
case 'edit-address':
$svg = '';
break;
case 'edit-account':
$svg = '';
break;
case 'customer-logout':
$svg = '';
break;
case '1':
default:
$svg = '';
break;
}
return $svg;
}
endif;
/**
* Add Svg into post mesg
*/
add_filter('wp_kses_allowed_html', 'elessi_wp_kses_allowed_html_svg', 10, 2);
if (!function_exists('elessi_wp_kses_allowed_html_svg')) :
function elessi_wp_kses_allowed_html_svg($allowedposttags, $context) {
if ($context === 'post') {
$allowedposttags['svg'] = array(
'xmlns' => true,
'viewbox' => true,
'width' => true,
'height' => true,
);
$allowedposttags['path'] = array(
'd' => true,
'fill' => true,
);
}
return $allowedposttags;
}
endif;
/**
* Ajax return json for Submit Review
*/
add_filter('comment_post_redirect', 'elessi_comment_post_redirect', 10, 2);
if (!function_exists('elessi_comment_post_redirect')) :
function elessi_comment_post_redirect($location, $comment) {
/**
* No change with Customer Reviews for WooCommerce plugin
*/
if (function_exists('cusrev_init') || $comment->comment_type !== 'review') {
return $location;
}
$location = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : preg_replace('/comment-page-\d+.*$/', '', $location);
$parsed_url = parse_url($location);
$query_params = array();
parse_str($parsed_url['query'] ?? '', $query_params);
$query_params['review_sort'] = 'date_DESC';
$parsed_url['query'] = http_build_query($query_params);
$location = $parsed_url['scheme'] . '://' . $parsed_url['host'] . $parsed_url['path'] . '?' . $parsed_url['query'];
$html = file_get_contents($location);
$response = array(
'code' => 'success',
'html' => $html,
'comment_id' => '#li-comment-' . $comment->comment_ID,
'message' => esc_html__('Your review has been submitted', 'elessi-theme'),
);
header('Content-Type: application/json');
echo json_encode($response);
exit;
}
endif;
add_filter('comment_class', 'elessi_add_custom_class_to_review', 10, 5);
if (!function_exists('elessi_add_custom_class_to_review')) :
function elessi_add_custom_class_to_review($classes, $css_class, $comment_ID, $comment, $post) {
if (get_post_type($post) == 'product') {
$classes[] = 'ns-product-review';
}
return $classes;
}
endif;
add_action('woocommerce_review_before', 'elessi_review_confetti', 10, 1);
if (!function_exists('elessi_review_confetti')) :
function elessi_review_confetti() {
global $nasa_opt;
$theme_version = isset($nasa_opt['js_theme_version']) && $nasa_opt['js_theme_version'] ? apply_filters('nasa_version_assets', NASA_VERSION) : null;
wp_enqueue_script('jquery-confetti', ELESSI_THEME_URI . '/assets/js/min/jquery.confetti.min.js', array('jquery'), $theme_version, true);
}
endif;