rip_tags( get_post_meta( $post_thumbnail_id, '_wp_attachment_image_alt', true ) ) );
$image = wp_get_attachment_image_src( $post_thumbnail_id, $image_size );
if ( $image ) {
$image_trans = get_template_directory_uri() . '/images/transparent.png';
$image_trans = apply_filters( 'martfury_image_transparent', $image_trans );
if ( $attributes ) {
$full_size_image = wp_get_attachment_image_src( $post_thumbnail_id, 'full' );
$output = sprintf(
'',
esc_url( $image_trans ),
esc_url( $image[0] ),
esc_attr( $alt ),
esc_attr( $css_class ),
esc_attr( $full_size_image[0] ),
esc_attr( $full_size_image[0] ),
esc_attr( $attributes['data-large_image_width'] ),
esc_attr( $attributes['data-large_image_height'] )
);
} else {
$output = sprintf(
'
',
esc_url( $image_trans ),
esc_url( $image[0] ),
esc_attr( $alt ),
esc_attr( $css_class ),
esc_attr( $image[1] ),
esc_attr( $image[2] )
);
}
}
} else {
if ( $attributes ) {
$attributes['class'] = $css_class;
}
$output = wp_get_attachment_image( $post_thumbnail_id, $image_size, false, $attributes );
}
return $output;
}
/**
* Get current page URL for layered nav items.
* @return string
*/
if ( ! function_exists( 'martfury_get_page_base_url' ) ) :
function martfury_get_page_base_url() {
if ( defined( 'SHOP_IS_ON_FRONT' ) ) {
$link = home_url();
} elseif ( is_post_type_archive( 'product' ) || is_page( wc_get_page_id( 'shop' ) ) ) {
$link = get_post_type_archive_link( 'product' );
} elseif ( is_product_category() ) {
$link = get_term_link( get_query_var( 'product_cat' ), 'product_cat' );
} elseif ( is_product_tag() ) {
$link = get_term_link( get_query_var( 'product_tag' ), 'product_tag' );
} else {
$queried_object = get_queried_object();
if ( $queried_object ) {
$link = get_term_link( $queried_object->slug, $queried_object->taxonomy );
}
}
return apply_filters( 'martfury_get_page_base_url', $link );
}
endif;
/**
* Get catalog layout
*
* @since 1.0
*/
if ( ! function_exists( 'martfury_get_catalog_layout' ) ) :
function
martfury_get_catalog_layout() {
$layout = '10';
if ( martfury_is_vendor_page() ) {
$layout = '12';
} elseif ( is_search() ) {
$layout = '10';
} elseif ( function_exists( 'is_shop' ) && is_shop() ) {
$layout = martfury_get_option( 'shop_layout' );
} elseif ( function_exists( 'is_product_category' ) && is_product_category() && martfury_get_product_category_level() == 0 ) {
$layout = martfury_get_option( 'products_cat_level_1_layout' );
if ( function_exists( 'get_term_meta' ) ) {
$queried_object = get_queried_object();
$cat_layout = get_term_meta( $queried_object->term_id, 'mf_cat_layout', true );
$layout = $cat_layout ? $cat_layout : $layout;
}
}
return apply_filters( 'martfury_get_catalog_layout', $layout );
}
endif;
/**
* Get catalog layout
*
* @since 1.0
*/
if ( ! function_exists( 'martfury_get_catalog_full_width' ) ) :
function martfury_get_catalog_full_width() {
if ( ! martfury_is_catalog() && ! martfury_is_vendor_page() ) {
return false;
}
$catalog_layout = martfury_get_catalog_layout();
if ( $catalog_layout == '1' && intval( martfury_get_option( 'catalog_full_width_1' ) ) ) {
return true;
} elseif ( $catalog_layout == '3' && intval( martfury_get_option( 'catalog_full_width_3' ) ) ) {
return true;
} elseif ( $catalog_layout == '10' ) {
if ( is_search() ) {
if ( intval( martfury_get_option( 'search_full_width' ) ) ) {
return true;
}
} else {
if ( intval( martfury_get_option( 'catalog_full_width_10' ) ) ) {
return true;
}
}
} elseif ( $catalog_layout == '12' && intval( martfury_get_option( 'catalog_full_width_12' ) ) ) {
return true;
}
return false;
}
endif;
/**
* Get category level
*
* @since 1.0
*/
if ( ! function_exists( 'martfury_get_product_category_level' ) ) :
function martfury_get_product_category_level() {
global $wp_query;
$current_cat = $wp_query->get_queried_object();
if ( empty( $current_cat ) ) {
return 0;
}
$term_id = $current_cat->term_id;
return count( get_ancestors( $term_id, 'product_cat' ) );
}
endif;
/**
* Get catalog layout
*
* @since 1.0
*/
if ( ! function_exists( 'martfury_get_filtered_term_product_counts' ) ) :
function martfury_get_filtered_term_product_counts( $term_ids, $taxonomy = false, $query_type = false ) {
global $wpdb;
if ( ! class_exists( 'WC_Query' ) ) {
return false;
}
$tax_query = WC_Query::get_main_tax_query();
$meta_query = WC_Query::get_main_meta_query();
if ( 'or' === $query_type ) {
foreach ( $tax_query as $key => $query ) {
if ( is_array( $query ) && $taxonomy === $query['taxonomy'] ) {
unset( $tax_query[ $key ] );
}
}
}
if ( 'product_brand' === $taxonomy ) {
foreach ( $tax_query as $key => $query ) {
if ( is_array( $query ) ) {
if ( $query['taxonomy'] === 'product_brand' ) {
unset( $tax_query[ $key ] );
if ( preg_match( '/pa_/', $query['taxonomy'] ) ) {
unset( $tax_query[ $key ] );
}
}
}
}
}
$meta_query = new WP_Meta_Query( $meta_query );
$tax_query = new WP_Tax_Query( $tax_query );
$meta_query_sql = $meta_query->get_sql( 'post', $wpdb->posts, 'ID' );
$tax_query_sql = $tax_query->get_sql( $wpdb->posts, 'ID' );
// Generate query
$query = array();
$query['select'] = "SELECT COUNT( DISTINCT {$wpdb->posts}.ID ) as term_count, terms.term_id as term_count_id";
$query['from'] = "FROM {$wpdb->posts}";
$query['join'] = "
INNER JOIN {$wpdb->term_relationships} AS term_relationships ON {$wpdb->posts}.ID = term_relationships.object_id
INNER JOIN {$wpdb->term_taxonomy} AS term_taxonomy USING( term_taxonomy_id )
INNER JOIN {$wpdb->terms} AS terms USING( term_id )
" . $tax_query_sql['join'] . $meta_query_sql['join'];
$query['where'] = "
WHERE {$wpdb->posts}.post_type IN ( 'product' )
AND {$wpdb->posts}.post_status = 'publish'
" . $tax_query_sql['where'] . $meta_query_sql['where'] . "
AND terms.term_id IN (" . implode( ',', array_map( 'absint', $term_ids ) ) . ")
";
if ( $search = WC_Query::get_main_search_query_sql() ) {
$query['where'] .= ' AND ' . $search;
}
$query['group_by'] = "GROUP BY terms.term_id";
$query = apply_filters( 'woocommerce_get_filtered_term_product_counts_query', $query );
$query = implode( ' ', $query );
// We have a query - let's see if cached results of this query already exist.
$query_hash = md5( $query );
$cache = apply_filters( 'woocommerce_layered_nav_count_maybe_cache', true );
if ( true === $cache ) {
$cached_counts = (array) get_transient( 'wc_layered_nav_counts_' . sanitize_title( $taxonomy ) );
} else {
$cached_counts = array();
}
if ( ! isset( $cached_counts[ $query_hash ] ) ) {
$results = $wpdb->get_results( $query, ARRAY_A );
$counts = array_map( 'absint', wp_list_pluck( $results, 'term_count', 'term_count_id' ) );
$cached_counts[ $query_hash ] = $counts;
set_transient( 'wc_layered_nav_counts_' . sanitize_title( $taxonomy ), $cached_counts, DAY_IN_SECONDS );
}
return array_map( 'absint', (array) $cached_counts[ $query_hash ] );
}
endif;
/**
* Get socials
*
* @since 1.0.0
*
*
* @return string
*/
if ( ! function_exists( 'martfury_get_socials' ) ) :
function martfury_get_socials() {
$socials = array(
'facebook' => esc_html__( 'Facebook', 'martfury' ),
'twitter' => esc_html__( 'Twitter', 'martfury' ),
'google' => esc_html__( 'Google', 'martfury' ),
'tumblr' => esc_html__( 'Tumblr', 'martfury' ),
'flickr' => esc_html__( 'Flickr', 'martfury' ),
'vimeo' => esc_html__( 'Vimeo', 'martfury' ),
'youtube' => esc_html__( 'Youtube', 'martfury' ),
'linkedin' => esc_html__( 'LinkedIn', 'martfury' ),
'pinterest' => esc_html__( 'Pinterest', 'martfury' ),
'dribbble' => esc_html__( 'Dribbble', 'martfury' ),
'spotify' => esc_html__( 'Spotify', 'martfury' ),
'instagram' => esc_html__( 'Instagram', 'martfury' ),
'tumbleupon' => esc_html__( 'Tumbleupon', 'martfury' ),
'wordpress' => esc_html__( 'WordPress', 'martfury' ),
'rss' => esc_html__( 'Rss', 'martfury' ),
'deviantart' => esc_html__( 'Deviantart', 'martfury' ),
'share' => esc_html__( 'Share', 'martfury' ),
'skype' => esc_html__( 'Skype', 'martfury' ),
'behance' => esc_html__( 'Behance', 'martfury' ),
'apple' => esc_html__( 'Apple', 'martfury' ),
'yelp' => esc_html__( 'Yelp', 'martfury' ),
);
return apply_filters( 'martfury_header_socials', $socials );
}
endif;
/**
* Get page header layout
*
* @return array
*/
if ( ! function_exists( 'martfury_get_page_header' ) ) :
function martfury_get_page_header() {
if ( is_404() || is_page_template( 'template-homepage.php' ) || is_page_template( 'template-home-full-width.php' ) || is_page_template( 'template-coming-soon-page.php' ) ) {
return false;
}
$page_header = array( 'title', 'breadcrumb' );
if ( martfury_is_blog() ) {
if ( ! intval( martfury_get_option( 'page_header_blog' ) ) ) {
return false;
}
$page_header = martfury_get_option( 'page_header_blog_els' );
} elseif ( is_page() ) {
if ( ! intval( martfury_get_option( 'page_header_page' ) ) ) {
return false;
}
$custom_layout = get_post_meta( get_the_ID(), 'custom_page_header', true );
if ( $custom_layout ) {
$hide_page_header = get_post_meta( get_the_ID(), 'hide_page_header', true );
if ( $hide_page_header ) {
return false;
}
if ( get_post_meta( get_the_ID(), 'hide_breadcrumb', true ) ) {
$key = array_search( 'breadcrumb', $page_header );
if ( $key !== false ) {
unset( $page_header[ $key ] );
}
}
if ( get_post_meta( get_the_ID(), 'hide_title', true ) ) {
$key = array_search( 'title', $page_header );
if ( $key !== false ) {
unset( $page_header[ $key ] );
}
}
} else {
$page_header = martfury_get_option( 'page_header_pages_els' );
}
} elseif ( is_search() ) {
$page_header = array( 'title', 'breadcrumb' );
} elseif ( function_exists( 'is_shop' ) && is_shop() ) {
$shop_id = get_option( 'woocommerce_shop_page_id' );
$custom_layout = get_post_meta( $shop_id, 'custom_page_header', true );
if ( $custom_layout ) {
$hide_page_header = get_post_meta( $shop_id, 'hide_page_header', true );
if ( $hide_page_header ) {
return false;
}
if ( get_post_meta( $shop_id, 'hide_breadcrumb', true ) ) {
$key = array_search( 'breadcrumb', $page_header );
if ( $key !== false ) {
unset( $page_header[ $key ] );
}
}
if ( get_post_meta( $shop_id, 'hide_title', true ) ) {
$key = array_search( 'title', $page_header );
if ( $key !== false ) {
unset( $page_header[ $key ] );
}
}
}
}
if ( martfury_is_vendor_page() ) {
$page_header = martfury_get_option( 'page_header_vendor_els' );
}
return apply_filters( 'martfury_get_page_header', $page_header );
}
endif;
/**
* Get recently viewed products
*
* @return string
*/
if ( ! function_exists( 'martfury_recently_viewed_products' ) ) :
function martfury_recently_viewed_products( $atts ) {
$viewed_products = ! empty( $_COOKIE['woocommerce_recently_viewed'] ) ? (array) explode( '|', $_COOKIE['woocommerce_recently_viewed'] ) : array();
$viewed_products = array_reverse( array_filter( array_map( 'absint', $viewed_products ) ) );
$output = array();
$thumbnail_size = 'thumbnail';
if ( function_exists( 'wc_get_image_size' ) ) {
$gallery_thumbnail = wc_get_image_size( 'gallery_thumbnail' );
$thumbnail_size = apply_filters( 'woocommerce_gallery_thumbnail_size', array(
$gallery_thumbnail['width'],
$gallery_thumbnail['height']
) );
}
$output[] = '