get_gallery_image_ids()[0] ) ? wc_get_product()->get_gallery_image_ids()[0] : null;
if ( $image_id ) {
echo wp_get_attachment_image( $image_id, 'woocommerce_thumbnail', '', [ 'class' => 'arendelle-product-image-back'] ) ;
}
}
}
/**
* Wislist count
*/
if ( defined( 'YITH_WCWL' ) && ! function_exists( 'arendelle_wishlist_count' ) ) {
function arendelle_wishlist_count() {
ob_start(); ?>
yith_wcwl_count_all_products()
) );
}
add_action( 'wp_ajax_yith_wcwl_update_wishlist_count', 'arendelle_wishlist_ajax_update_count' );
add_action( 'wp_ajax_nopriv_yith_wcwl_update_wishlist_count', 'arendelle_wishlist_ajax_update_count' );
}
/**
* Wislist JS
*/
if ( defined( 'YITH_WCWL' ) && ! function_exists( 'arendelle_wishlist_enqueue_script' ) ) {
function arendelle_wishlist_enqueue_script() {
wp_add_inline_script(
'jquery-yith-wcwl',
"
jQuery( function( $ ) {
$( document ).on( 'added_to_wishlist removed_from_wishlist', function() {
$.get( yith_wcwl_l10n.ajax_url, {
action: 'yith_wcwl_update_wishlist_count'
}, function( data ) {
if ( 0 === data.count ) {
$('.arendelle-menu-wishlist__count').addClass('d-none');
} else {
$('.arendelle-menu-wishlist__count').removeClass('d-none')
}
$('.yith-wcwl-items-count').html( data.count );
} );
} );
} );
"
);
}
add_action( 'wp_enqueue_scripts', 'arendelle_wishlist_enqueue_script', 20 );
}
/**
* WooCommerce cart
*/
if ( ! function_exists( 'arendelle_woo_cart_icon' ) ) {
function arendelle_woo_cart_icon( $minicart_show = false, $auto_open = true ) {
static $called = false;
$auto_open = get_theme_mod( 'arendelle_settings_woocommerce_auto_open_mini_cart', true );
if ( ! arendelle_is_woocommerce_activated() || is_null( WC()->cart ) ) {
return;
}
$count = WC()->cart->get_cart_contents_count();
?>
cart->get_cart_contents_count();
// count
if ( 0 === $count ) {
$fragments['.arendelle-menu-cart__count'] = '';
} else {
$fragments['.arendelle-menu-cart__count'] = '';
}
// mini-cart
ob_start();
echo '';
if ( 0 === $count ) {
echo '
';
echo '
';
}
woocommerce_mini_cart();
if ( 0 === $count ) {
echo '
';
}
echo '
';
$fragments['.arendelle-offcanvas__mini-cart'] = ob_get_clean();
return $fragments;
}
if ( ! function_exists( 'arendelle_shop_before_content' ) ) {
/**
* Archives layout before
*/
function arendelle_shop_before_content() {
?>
';
echo do_shortcode( '[yith_quick_view]' );
echo '
';
}
}
}
if ( ! function_exists( 'arendelle_product_add_to_cart' ) ) {
/**
* Product actions open
*/
function arendelle_product_add_to_cart() {
echo '
';
echo woocommerce_template_loop_add_to_cart();
echo '
';
}
}
if ( ! function_exists( 'arendelle_product_actions_close' ) ) {
/**
* Product actions close
*/
function arendelle_product_actions_close() {
?>
';
woocommerce_template_loop_product_link_open();
echo get_the_title(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
woocommerce_template_loop_product_link_close();
echo '';
}
}
if ( ! function_exists( 'arendelle_after_product_price' ) ) {
/**
* Product after price
*/
function arendelle_after_product_price() {
echo '
';
}
}
if ( ! function_exists( 'arendelle_product_share' ) ) {
/**
* Product share
*/
function arendelle_product_share() {
if ( ! get_theme_mod( 'arendelle_settings_product_share_buttons_show', true ) ) {
return;
}
if ( function_exists( 'arendelle_social_sharing_buttons' ) ) : ?>
' . esc_html__( 'Share', 'arendelle' ) . '';
echo arendelle_social_sharing_buttons( 'socials--no-base', 'product' );
?>
' : '';
return $defaults;
}
}
if ( ! function_exists( 'arendelle_shop_tag_cloud_widget' ) ) {
/**
* Tag cloud font size
*/
function arendelle_shop_tag_cloud_widget( $args ) {
$args = array(
'smallest' => 10,
'largest' => 10,
'taxonomy' => 'product_tag'
);
return $args;
}
}
/* Product Badges
---------------------------------------------------------- */
if ( ! function_exists( 'arendelle_product_badge' ) ) {
/**
* Product sale badge
*/
function arendelle_product_badge() {
global $post, $product;
// Out of Stock only on simple products
if ( $product->get_type() === 'simple' && arendelle_out_of_stock()) { ?>
is_on_sale() && get_theme_mod( 'arendelle_settings_woocommerce_product_sale_badge', 'percent' ) !== 'disabled' ) {
// Display percentage
if ( get_theme_mod( 'arendelle_settings_woocommerce_product_sale_badge', 'percent' ) === 'percent' ) {
if ( $product->get_type() === 'variable' ) {
// Get product variation prices (regular and sale)
$product_variation_prices = $product->get_variation_prices();
$highest_sale_percent = 0;
foreach( $product_variation_prices['regular_price'] as $key => $regular_price ) {
// Get sale price for current variation
$sale_price = $product_variation_prices['sale_price'][$key];
// Is product variation on sale?
if ( $sale_price < $regular_price ) {
$sale_percent = round( ( ( $regular_price - $sale_price ) / $regular_price ) * 100 );
// Is current sale percent highest?
if ( $sale_percent > $highest_sale_percent ) {
$highest_sale_percent = $sale_percent;
}
}
}
if ( $highest_sale_percent > 0 ) {
// Return the highest product variation sale percent
echo apply_filters('woocommerce_sale_flash', '- ' . $highest_sale_percent . '% ' . esc_html__( 'Off', 'arendelle' ) . '', $post, $product);
}
} else {
$regular_price = $product->get_regular_price();
$sale_percent = 0;
// Make sure the percentage value can be calculated
if ( intval( $regular_price ) > 0 ) {
$sale_percent = round( ( ( $regular_price - $product->get_sale_price() ) / $regular_price ) * 100 );
}
if ( $sale_percent > 0 ) {
echo apply_filters('woocommerce_sale_flash', '-' . $sale_percent . '% ' . esc_html__( 'Off', 'arendelle' ) . '', $post, $product );
}
}
// Or display text
} else {
echo apply_filters( 'woocommerce_sale_flash', '' . esc_html__( 'Sale', 'arendelle' ) . '', $post, $product );
}
}
}
}
}
add_action( 'arendelle_product_badge', 'arendelle_product_badge', 3 );
if ( ! function_exists( 'arendelle_out_of_stock' ) ) {
/**
* Out of Stock Check
*/
function arendelle_out_of_stock() {
global $post;
$status = get_post_meta( $post->ID, '_stock_status', true );
if ( $status == 'outofstock' ) {
return true;
} else {
return false;
}
}
}