get_price() && $product->is_on_sale() ) { // collect prices from $price html string $prices = array_map( function( $item ) { return array( $item, (float) preg_replace( "/[^0-9.]/", "", html_entity_decode( $item, ENT_QUOTES, 'UTF-8' ) ) ); }, explode( ' ', strip_tags( $price ) ) ); $price = isset( $prices[0][0] ) ? 'Original Price: ' . $prices[0][0] . '' : ''; $price .= isset( $prices[1][0] ) ? 'Sale Price: ' . $prices[1][0] . '' : ''; if ( $product->get_regular_price() ) { // set saved amount with currency symbol placed as defined in options $price .= 'You saved: ' . sprintf( get_woocommerce_price_format(), get_woocommerce_currency_symbol(), $prices[0][1] - $prices[1][1] ) . ''; } } return $price; }, 10, 2 ); add_action ('check_woocommerce', 'alfw_woocommerce_not_install_notice'); /** * @param $atts */ function alfw_slider_render_func($atts) { global $wpdb, $lookbook_slider_effects; if ( !in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { do_action( 'check_woocommerce'); return; } $upload_dir_info = wp_upload_dir(); $wp_root_path = get_home_path(); $site_url = get_site_url(); $plugin_folder_name = pathinfo(ALTIMA_LOOKBOOK_PLUGIN_DIR); wp_enqueue_script('hotspots'); wp_enqueue_script('actual'); wp_enqueue_script('carousel'); wp_enqueue_script('flip'); wp_enqueue_script('scrolV'); wp_enqueue_script('shuffle'); wp_enqueue_script('tile'); wp_enqueue_script('additionalEffect'); wp_enqueue_script('swipe'); //$wpdb->show_errors(); extract($atts); /** * Get slider options */ $show_desc = get_option("wplb_free_show_desc_in_popup"); $show_addcart = get_option("wplb_free_show_addcart_in_popup"); $path_2_pic = get_option('wplb_free_hspt_icon', $site_url . '/wp-content/plugins/'.$plugin_folder_name['basename'].'/admin/images/hotspot-icon.png'); if (empty($path_2_pic)) { $path_2_pic = $site_url . '/wp-content/plugins/'.$plugin_folder_name['basename'].'/admin/images/hotspot-icon.png'; } $hot_point_icon = ''; $only_visible_element = 'AND `status`=1'; if (@$admin) $only_visible_element = ''; $slider = $wpdb->get_results( $wpdb->prepare( "SELECT slider.* FROM `" . $wpdb->prefix . SLIDER_TABLE . "` AS slider WHERE `slider`.`id` = %d $only_visible_element", $slider_id ), ARRAY_A ); if (!empty($slider)) { $slides = $wpdb->get_results( $wpdb->prepare( "SELECT slide.* FROM `" . $wpdb->prefix . SLIDES_TABLE . "` AS slide WHERE slider_id = %d $only_visible_element ORDER BY order_flag", $slider[0]['id'] ), ARRAY_A ); } if (empty($slides)){ echo __('No slides available in this slider!'); }else { $effects = unserialize($slider[0]['slider_effect']); $slider_count = count($slides); //var_dump(json_decode($slides[0]['hotsposts'])); alfw_control_js($slider[0]['id']); /** * Work with sliders effect */ if (!empty($effects)){ $effects_string = ''; if (in_array('all', $effects)) { unset($lookbook_slider_effects['all']); unset($lookbook_slider_effects['none']); $fx_names = array_keys($lookbook_slider_effects); $fx_count = count($fx_names); $sl_count = $slider_count; for ($i = 0; $i < $sl_count; $i++) { $slides[$i]['fx'] = 'data-cycle-fx="'.$fx_names[rand(2,$fx_count)].'"'; } }elseif (in_array('none', $effects)) { $effects_string = 'data-cycle-fx="none"'; }else { $fx_count = count($effects)-1; $sl_count = $slider_count; for ($i=0; $i<$sl_count; $i++) { $slides[$i]['fx'] = 'data-cycle-fx="'.$effects[rand(0,$fx_count)].'"'; } } } echo '
'; /** * Output content before */ if (!empty($slider[0]['content_before'])) { echo '
'.$slider[0]['content_before'].'
'; } /** * Showing the caption */ $caption_plugin = ''; if ($slider[0]['show_slide_caption']){ $caption_plugin = 'data-cycle-caption-plugin="caption2"'; } /** * Adding thumbneil pager */ $thumb = ''; $simple_pager = ''; if ($slider[0]['show_thumbnails']){ $thumb = 'data-cycle-pager="#no-template-pager" data-cycle-pager-template=""'; }else{ $simple_pager =' data-cycle-pager="#pagernav_' . $slider[0]['id'] . ' .cycle" data-cycle-pager-template="
  • {{slideNum}}
  • "'; } /** * Output the slider * cycle-slideshow */ echo '
    '; /** * Showing the caption */ if ($slider_count > 1) { if ($slider[0]['show_slide_caption']) { echo '
    '; //echo '
    '; } } /** * Showing nawigation buttons */ if ($slider[0]['show_navigation'] && ($slider_count > 1)) { $hover = ''; if ($slider[0]['navigation_on_hover_state_only']){ $hover = 'hover'; } echo '
    '; echo '
    '; echo '
    '; } foreach($slides as &$slide) { /** * Add to hotspot product information */ $hotspots = json_decode($slide['hotsposts']); if (!empty($hotspots)) { foreach ($hotspots as &$point) { /** * $point->sku - it's post id not product sku */ if (!empty($point->sku) && is_numeric($point->sku)){ $post_data = get_post($point->sku, ARRAY_A); try { $product = new WC_Product( $post_data['ID'] ); $price = $product->get_price_html(); $stock_status = $product->is_in_stock() ? 'In stock' : 'Out of stock'; $product_url = get_permalink($post_data['ID']); $url = wp_get_attachment_image_src( get_post_thumbnail_id($post_data['ID'])); $status_block = ''; $price_block = ''; $text_block = ''; $addcart_block = ''; $img_block = ''; if ($show_desc) { $img_block = (!empty($url[0])) ? '' : ''; } switch($post_data['post_type']){ case 'post': if ($show_desc) { $text_block = mb_substr(strip_tags($post_data['post_content']), 0, 100); } break; case 'page': if ($show_desc) { $text_block = mb_substr(strip_tags($post_data['post_content']), 0, 100); } break; case 'product': $status_block = '
    ' . $stock_status . '
    '; $price_block = '
    '.$price.'
    '; if ($show_desc) { $text_block = mb_substr(strip_tags($post_data['post_excerpt']), 0, 100); } if ($show_addcart) { $addcart_block = '
    '; } break; } $point->text = '
    ' . $post_data['post_title'] . ' ' . $status_block . '
    ' . $img_block . ' ' . $text_block . '
    ' . $price_block . ' ' . $addcart_block . '
    ' . $hot_point_icon; }catch (Exception $e) { $point->text = '' . $hot_point_icon; } }else { $point->text = '' . $hot_point_icon; } } $slide['hotsposts'] = json_encode($hotspots); } /** * Output slides */ $a_start = $a_end = ''; if (!empty($slide['link'])){ $a_start = ''; $a_end = ''; } $overley = ''; if ($slider_count > 1) { if ($slider[0]['show_slide_caption']) { $overley = '
    '.$slide['caption'].' 
    '; } } echo '
    ' . $a_start . ''.$slide['caption'].'' . $overley . $a_end . '
    '."\n"; } echo '
    '; unset($slide); echo '
    '; alfw_add_hotspots($slides, $slider[0]['id']); /** * Showing thumbneils pages */ if ( $slider_count > 1) { if ($slider[0]['show_thumbnails']) { alfw_thumbnails_js($slider[0]['id']); echo '
    '; }else { /** * Simple pager */ echo '
    '; } } /** * Output content after */ if (!empty($slider[0]['content_after'])) { echo '
    '.$slider[0]['content_after'].'
    '; } echo '
    '; } } add_shortcode( 'slider_render', 'alfw_slider_render_func'); function alfw_add_hotspots($slides, $slider_id) { foreach ($slides as $slide): $hotspots[] = $slide['hotsposts']; endforeach; ?>