/** * Woocommerce helper functions */ if ( ! function_exists( 'stockholm_qode_return_woocommerce_global_variable' ) ) { function stockholm_qode_return_woocommerce_global_variable() { if ( stockholm_qode_is_woocommerce_installed() ) { global $product; return $product; } } } if ( ! function_exists( 'stockholm_qode_add_product_to_meta_boxes' ) ) { function stockholm_qode_add_product_to_meta_boxes( $metaboxes ) { $metaboxes[] = 'product'; return $metaboxes; } add_filter( 'stockholm_qode_filter_meta_box_post_types_save', 'stockholm_qode_add_product_to_meta_boxes' ); } if ( ! function_exists( 'stockholm_qode_is_yith_wcqv_install' ) ) { function stockholm_qode_is_yith_wcqv_install() { return defined( 'YITH_WCQV' ); } } if ( ! function_exists( 'stockholm_qode_is_yith_wcwl_install' ) ) { function stockholm_qode_is_yith_wcwl_install() { return defined( 'YITH_WCWL' ); } } if ( ! function_exists( 'stockholm_qode_get_woo_shortcode_module_template_part' ) ) { /** * Loads module template part. * * @param string $template name of the template to load * @param string $module name of the module folder * @param string $slug * @param array $params array of parameters to pass to template * * @return html * @see stockholm_qode_get_template_part() */ function stockholm_qode_get_woo_shortcode_module_template_part( $template, $module, $slug = '', $params = array() ) { //HTML Content from template $html = ''; $template_path = 'framework/modules/woocommerce/shortcodes/' . $module; $temp = $template_path . '/' . $template; if ( is_array( $params ) && count( $params ) ) { extract( $params ); } $templates = array(); if ( $temp !== '' ) { if ( $slug !== '' ) { $templates[] = "{$temp}-{$slug}.php"; } $templates[] = $temp . '.php'; } $located = stockholm_qode_find_template_path( $templates ); if ( $located ) { ob_start(); include( $located ); $html = ob_get_clean(); } return $html; } } if ( ! function_exists( 'stockholm_qode_product_single_enable_default_gallery_features' ) ) { function stockholm_qode_product_single_enable_default_gallery_features() { if ( stockholm_qode_options()->getOptionValue( 'woo_product_single_enable_default_gallery_features' ) == 'yes' ) { add_theme_support( 'wc-product-gallery-zoom' ); add_theme_support( 'wc-product-gallery-lightbox' ); add_theme_support( 'wc-product-gallery-slider' ); } } add_action( 'init', 'stockholm_qode_product_single_enable_default_gallery_features' ); } if ( ! function_exists( 'stockholm_qode_woocommerce_sale_percentage' ) ) { /** * Function that social share for product page * Return string */ function stockholm_qode_woocommerce_sale_percentage( $price, $sale_price ) { if ( $price > 0 ) { return '-' . ( 100 - round( ( $sale_price * 100 ) / $price ) ) . '%'; } else { return esc_html__( 'SALE', 'stockholm' ); } } } if ( ! function_exists( 'stockholm_qode_woocommerce_share_tag_before' ) ) { /** * Function that adds tag before share and like section */ function stockholm_qode_woocommerce_share_tag_before() { echo '
' . esc_html__( 'No products were found!', 'stockholm' ) . '
'; endif; wp_reset_postdata(); $return_obj = array( 'html' => $html, ); echo json_encode( $return_obj ); exit; } add_action( 'wp_ajax_nopriv_stockholm_qode_action_product_ajax_load_category', 'stockholm_qode_product_ajax_load_category' ); add_action( 'wp_ajax_stockholm_qode_action_product_ajax_load_category', 'stockholm_qode_product_ajax_load_category' ); } if ( ! function_exists( 'stockholm_qode_woo_elegant_pl_body_class' ) ) { function stockholm_qode_woo_elegant_pl_body_class( $classes ) { if ( stockholm_qode_is_woocommerce_installed() && stockholm_qode_options()->getOptionValue( 'woo_products_list_type' ) == 'elegant' ) { $classes[] = 'qode-elegant-product-list'; } return $classes; } add_filter( 'body_class', 'stockholm_qode_woo_elegant_pl_body_class' ); } if ( ! function_exists( 'stockholm_qode_product_list_standard_actions' ) ) { function stockholm_qode_product_list_standard_actions( $params ) { add_action( 'stockholm_qode_action_pl_standard_woocommerce_before_shop_loop_item', 'woocommerce_show_product_loop_sale_flash', 5 ); add_action( 'stockholm_qode_action_pl_standard_woocommerce_before_shop_loop_item', 'stockholm_qode_get_woocommerce_out_of_stock', 5 ); add_action( 'stockholm_qode_action_pl_standard_woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open', 10 ); add_action( 'stockholm_qode_action_pl_standard_woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 ); add_action( 'stockholm_qode_action_pl_standard_woocommerce_shop_loop_item_hover_image', 'stockholm_qode_woocommerce_shop_loop_hover_image', 10 ); add_action( 'stockholm_qode_action_pl_standard_woocommerce_shop_loop_item_hover_link_close', 'woocommerce_template_loop_product_link_close', 15 ); add_action( 'stockholm_qode_action_pl_standard_woocommerce_shop_loop_product_simple_button', 'stockholm_qode_woocommerce_shop_loop_button', 5 ); if ( $params['display_categories'] != '' && $params['display_categories'] == 'yes' ) { add_action( 'stockholm_qode_action_pl_standard_woocommerce_shop_loop_item_categories', 'stockholm_qode_woocommerce_shop_loop_categories', 5 ); } add_action( 'stockholm_qode_action_pl_standard_woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_link_open', 5 ); add_action( 'stockholm_qode_action_pl_standard_woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title', 10 ); add_action( 'stockholm_qode_action_pl_standard_woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_link_close', 15 ); add_action( 'stockholm_qode_action_pl_standard_woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 ); } add_action( 'stockholm_qode_action_pl_standard_initial_setup', 'stockholm_qode_product_list_standard_actions', 5, 1 ); } if ( ! function_exists( 'stockholm_qode_product_list_simple_actions' ) ) { function stockholm_qode_product_list_simple_actions() { add_action( 'stockholm_qode_action_pl_simple_woocommerce_before_shop_loop_item', 'woocommerce_show_product_loop_sale_flash', 5 ); add_action( 'stockholm_qode_action_pl_simple_woocommerce_before_shop_loop_item', 'stockholm_qode_get_woocommerce_out_of_stock', 5 ); add_action( 'stockholm_qode_action_pl_simple_woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open', 10 ); add_action( 'stockholm_qode_action_pl_simple_woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 ); add_action( 'stockholm_qode_action_pl_simple_woocommerce_shop_loop_item_hover_link_close', 'woocommerce_template_loop_product_link_close', 15 ); add_action( 'stockholm_qode_action_pl_simple_woocommerce_shop_loop_item_overlay', 'woocommerce_template_loop_product_link_open', 5 ); add_action( 'stockholm_qode_action_pl_simple_woocommerce_shop_loop_item_overlay', 'woocommerce_template_loop_product_link_close', 10 ); add_action( 'stockholm_qode_action_pl_simple_woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_link_open', 5 ); add_action( 'stockholm_qode_action_pl_simple_woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title', 10 ); add_action( 'stockholm_qode_action_pl_simple_woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_link_close', 15 ); add_action( 'stockholm_qode_action_pl_simple_woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 ); } add_action( 'stockholm_qode_action_pl_simple_initial_setup', 'stockholm_qode_product_list_simple_actions', 5 ); } if ( ! function_exists( 'stockholm_qode_woocommerce_shop_loop_hover_image' ) ) { /** * Function that prints hover image on standard product list */ function stockholm_qode_woocommerce_shop_loop_hover_image() { $product = stockholm_qode_return_woocommerce_global_variable(); $product_hover_image = ''; $product_gallery_ids = $product->get_gallery_attachment_ids(); if ( ! empty( $product_gallery_ids ) ) { //get product image url, shop catalog size $product_hover_image = wp_get_attachment_image( $product_gallery_ids[0], 'shop_catalog' ); } echo stockholm_qode_get_module_part( $product_hover_image ); } } if ( ! function_exists( 'stockholm_qode_woocommerce_shop_loop_categories' ) ) { /** * Function that prints html with product categories */ function stockholm_qode_woocommerce_shop_loop_categories() { $product = stockholm_qode_return_woocommerce_global_variable(); echo '