get_attributes() public method

Returns product attributes.
public get_attributes ( string $context = 'view' ) : array
$context string
return array
 /**
  * Add woo attributes to a custom field with the same name
  *
  * @param $custom_fields
  * @param $post_id
  *
  * @return mixed
  */
 public function filter_custom_fields($custom_fields, $post_id)
 {
     if (!isset($custom_fields)) {
         $custom_fields = array();
     }
     // Get the product correponding to this post
     $product = new WC_Product($post_id);
     foreach ($product->get_attributes() as $attribute) {
         //$terms = wc_get_product_terms( $product->id, $attribute['name'], array( 'fields' => 'names' ) );
         // Remove the eventual 'pa_' prefix from the attribute name
         $attribute_name = $attribute['name'];
         if (substr($attribute_name, 0, 3) == 'pa_') {
             $attribute_name = substr($attribute_name, 3, strlen($attribute_name));
         }
         $custom_fields[$attribute_name] = explode(',', $product->get_attribute($attribute['name']));
     }
     return $custom_fields;
 }
/** Modified Function - create matrix for row -- 03/02/2016 **/
function woocommerce_bulk_variations_create_matrix_v24($post_id)
{
    // 2.0 Compat
    if (function_exists('get_product')) {
        $_product = get_product($post_id);
    } else {
        $_product = new WC_Product($post_id);
    }
    $attributes = $_product->get_attributes();
    //Get first attribute -- 03/02/2016
    if (is_array($attributes) && count($attributes) > 0) {
        foreach ($attributes as $att) {
            $row_attribute = $att['name'];
            break;
        }
    }
    $av_temp = $_product->get_variation_attributes();
    $av = array();
    if (isset($attributes[$row_attribute]) && $attributes[$row_attribute]['is_taxonomy']) {
        $row_term_values = WC_Bulk_Variations_Compatibility::wc_get_product_terms($post_id, $row_attribute, 'all');
        foreach ($row_term_values as $row_term_value) {
            if (in_array($row_term_value->slug, $av_temp[$row_attribute])) {
                $av[$row_attribute][] = $row_term_value->slug;
            }
        }
    } else {
        $av[$row_attribute] = $av_temp[$row_attribute];
    }
    $grid = array();
    foreach ($av[$row_attribute] as $row_value) {
        $grid[$row_value] = null;
    }
    //Now sanitize the attributes, since $product->get_available_variations returns the variations sanitized, but get_variation_attributes does not
    $row_attribute = sanitize_title($row_attribute);
    $pv = $_product->get_available_variations();
    $filter = new WC_Bulk_Variation_Array_Filter('attribute_' . $row_attribute, $pv);
    foreach ($grid as $row_key => &$field_value) {
        $field_value = $filter->get_matches($row_key);
    }
    $matrix_data = array('row_attribute' => $row_attribute, 'matrix_rows' => array_values($av[$row_attribute]), 'matrix' => $grid);
    return $matrix_data;
}
 /**
  * Save variations.
  *
  * @param WC_Product $product
  * @param WP_REST_Request $request
  * @return bool
  * @throws WC_REST_Exception
  */
 protected function save_variations_data($product, $request)
 {
     global $wpdb;
     $variations = $request['variations'];
     $attributes = $product->get_attributes();
     foreach ($variations as $menu_order => $variation) {
         $variation_id = isset($variation['id']) ? absint($variation['id']) : 0;
         // Generate a useful post title.
         $variation_post_title = sprintf(__('Variation #%s of %s', 'woocommerce'), $variation_id, esc_html(get_the_title($product->id)));
         // Update or Add post.
         if (!$variation_id) {
             $post_status = isset($variation['visible']) && false === $variation['visible'] ? 'private' : 'publish';
             $new_variation = array('post_title' => $variation_post_title, 'post_content' => '', 'post_status' => $post_status, 'post_author' => get_current_user_id(), 'post_parent' => $product->id, 'post_type' => 'product_variation', 'menu_order' => $menu_order);
             $variation_id = wp_insert_post($new_variation);
             do_action('woocommerce_create_product_variation', $variation_id);
         } else {
             $update_variation = array('post_title' => $variation_post_title, 'menu_order' => $menu_order);
             if (isset($variation['visible'])) {
                 $post_status = false === $variation['visible'] ? 'private' : 'publish';
                 $update_variation['post_status'] = $post_status;
             }
             $wpdb->update($wpdb->posts, $update_variation, array('ID' => $variation_id));
             do_action('woocommerce_update_product_variation', $variation_id);
         }
         // Stop with we don't have a variation ID.
         if (is_wp_error($variation_id)) {
             throw new WC_REST_Exception('woocommerce_rest_cannot_save_product_variation', $variation_id->get_error_message(), 400);
         }
         // SKU.
         if (isset($variation['sku'])) {
             $sku = get_post_meta($variation_id, '_sku', true);
             $new_sku = wc_clean($variation['sku']);
             if ('' === $new_sku) {
                 update_post_meta($variation_id, '_sku', '');
             } elseif ($new_sku !== $sku) {
                 if (!empty($new_sku)) {
                     $unique_sku = wc_product_has_unique_sku($variation_id, $new_sku);
                     if (!$unique_sku) {
                         throw new WC_REST_Exception('woocommerce_rest_product_sku_already_exists', __('The SKU already exists on another product.', 'woocommerce'), 400);
                     } else {
                         update_post_meta($variation_id, '_sku', $new_sku);
                     }
                 } else {
                     update_post_meta($variation_id, '_sku', '');
                 }
             }
         }
         // Thumbnail.
         if (isset($variation['image']) && is_array($variation['image'])) {
             $image = current($variation['image']);
             if ($image && is_array($image)) {
                 if (isset($image['position']) && 0 === $image['position']) {
                     $attachment_id = isset($image['id']) ? absint($image['id']) : 0;
                     if (0 === $attachment_id && isset($image['src'])) {
                         $upload = wc_rest_upload_image_from_url(wc_clean($image['src']));
                         if (is_wp_error($upload)) {
                             throw new WC_REST_Exception('woocommerce_product_image_upload_error', $upload->get_error_message(), 400);
                         }
                         $attachment_id = wc_rest_set_uploaded_image_as_attachment($upload, $product->id);
                     }
                     // Set the image alt if present.
                     if (!empty($image['alt'])) {
                         update_post_meta($attachment_id, '_wp_attachment_image_alt', wc_clean($image['alt']));
                     }
                     // Set the image name if present.
                     if (!empty($image['name'])) {
                         wp_update_post(array('ID' => $attachment_id, 'post_title' => $image['name']));
                     }
                     update_post_meta($variation_id, '_thumbnail_id', $attachment_id);
                 }
             } else {
                 delete_post_meta($variation_id, '_thumbnail_id');
             }
         }
         // Virtual variation.
         if (isset($variation['virtual'])) {
             $is_virtual = true === $variation['virtual'] ? 'yes' : 'no';
             update_post_meta($variation_id, '_virtual', $is_virtual);
         }
         // Downloadable variation.
         if (isset($variation['downloadable'])) {
             $is_downloadable = true === $variation['downloadable'] ? 'yes' : 'no';
             update_post_meta($variation_id, '_downloadable', $is_downloadable);
         } else {
             $is_downloadable = get_post_meta($variation_id, '_downloadable', true);
         }
         // Shipping data.
         $this->save_product_shipping_data($variation_id, $variation);
         // Stock handling.
         if (isset($variation['manage_stock'])) {
             $manage_stock = true === $variation['manage_stock'] ? 'yes' : 'no';
         } else {
             $manage_stock = get_post_meta($variation_id, '_manage_stock', true);
         }
         update_post_meta($variation_id, '_manage_stock', '' === $manage_stock ? 'no' : $manage_stock);
         if (isset($variation['in_stock'])) {
             $stock_status = true === $variation['in_stock'] ? 'instock' : 'outofstock';
         } else {
             $stock_status = get_post_meta($variation_id, '_stock_status', true);
         }
         wc_update_product_stock_status($variation_id, '' === $stock_status ? 'instock' : $stock_status);
         if ('yes' === $manage_stock) {
             $backorders = get_post_meta($variation_id, '_backorders', true);
             if (isset($variation['backorders'])) {
                 $backorders = $variation['backorders'];
             }
             update_post_meta($variation_id, '_backorders', '' === $backorders ? 'no' : $backorders);
             if (isset($variation['stock_quantity'])) {
                 wc_update_product_stock($variation_id, wc_stock_amount($variation['stock_quantity']));
             } elseif (isset($request['inventory_delta'])) {
                 $stock_quantity = wc_stock_amount(get_post_meta($variation_id, '_stock', true));
                 $stock_quantity += wc_stock_amount($request['inventory_delta']);
                 wc_update_product_stock($variation_id, wc_stock_amount($stock_quantity));
             }
         } else {
             delete_post_meta($variation_id, '_backorders');
             delete_post_meta($variation_id, '_stock');
         }
         // Regular Price.
         if (isset($variation['regular_price'])) {
             $regular_price = '' === $variation['regular_price'] ? '' : $variation['regular_price'];
         } else {
             $regular_price = get_post_meta($variation_id, '_regular_price', true);
         }
         // Sale Price.
         if (isset($variation['sale_price'])) {
             $sale_price = '' === $variation['sale_price'] ? '' : $variation['sale_price'];
         } else {
             $sale_price = get_post_meta($variation_id, '_sale_price', true);
         }
         if (isset($variation['date_on_sale_from'])) {
             $date_from = $variation['date_on_sale_from'];
         } else {
             $date_from = get_post_meta($variation_id, '_sale_price_dates_from', true);
             $date_from = '' === $date_from ? '' : date('Y-m-d', $date_from);
         }
         if (isset($variation['date_on_sale_to'])) {
             $date_to = $variation['date_on_sale_to'];
         } else {
             $date_to = get_post_meta($variation_id, '_sale_price_dates_to', true);
             $date_to = '' === $date_to ? '' : date('Y-m-d', $date_to);
         }
         _wc_save_product_price($variation_id, $regular_price, $sale_price, $date_from, $date_to);
         // Tax class.
         if (isset($variation['tax_class'])) {
             if ($variation['tax_class'] !== 'parent') {
                 update_post_meta($variation_id, '_tax_class', wc_clean($variation['tax_class']));
             } else {
                 delete_post_meta($variation_id, '_tax_class');
             }
         }
         // Downloads.
         if ('yes' === $is_downloadable) {
             // Downloadable files.
             if (isset($variation['downloads']) && is_array($variation['downloads'])) {
                 $this->save_downloadable_files($product->id, $variation['downloads'], $variation_id);
             }
             // Download limit.
             if (isset($variation['download_limit'])) {
                 update_post_meta($variation_id, '_download_limit', -1 === $variation['download_limit'] ? '' : absint($variation['download_limit']));
             }
             // Download expiry.
             if (isset($variation['download_expiry'])) {
                 update_post_meta($variation_id, '_download_expiry', -1 === $variation['download_expiry'] ? '' : absint($variation['download_expiry']));
             }
         } else {
             update_post_meta($variation_id, '_download_limit', '');
             update_post_meta($variation_id, '_download_expiry', '');
             update_post_meta($variation_id, '_downloadable_files', '');
         }
         // Description.
         if (isset($variation['description'])) {
             update_post_meta($variation_id, '_variation_description', wp_kses_post($variation['description']));
         }
         // Update taxonomies.
         if (isset($variation['attributes'])) {
             $updated_attribute_keys = array();
             foreach ($variation['attributes'] as $attribute) {
                 $attribute_id = 0;
                 $attribute_name = '';
                 // Check ID for global attributes or name for product attributes.
                 if (!empty($attribute['id'])) {
                     $attribute_id = absint($attribute['id']);
                     $attribute_name = wc_attribute_taxonomy_name_by_id($attribute_id);
                 } elseif (!empty($attribute['name'])) {
                     $attribute_name = sanitize_title($attribute['name']);
                 }
                 if (!$attribute_id && !$attribute_name) {
                     continue;
                 }
                 if (isset($attributes[$attribute_name])) {
                     $_attribute = $attributes[$attribute_name];
                 }
                 if (isset($_attribute['is_variation']) && $_attribute['is_variation']) {
                     $_attribute_key = 'attribute_' . sanitize_title($_attribute['name']);
                     $updated_attribute_keys[] = $_attribute_key;
                     if (isset($_attribute['is_taxonomy']) && $_attribute['is_taxonomy']) {
                         // Don't use wc_clean as it destroys sanitized characters
                         $_attribute_value = isset($attribute['option']) ? sanitize_title(stripslashes($attribute['option'])) : '';
                     } else {
                         $_attribute_value = isset($attribute['option']) ? wc_clean(stripslashes($attribute['option'])) : '';
                     }
                     update_post_meta($variation_id, $_attribute_key, $_attribute_value);
                 }
             }
             // Remove old taxonomies attributes so data is kept up to date - first get attribute key names.
             $delete_attribute_keys = $wpdb->get_col($wpdb->prepare("SELECT meta_key FROM {$wpdb->postmeta} WHERE meta_key LIKE 'attribute_%%' AND meta_key NOT IN ( '" . implode("','", $updated_attribute_keys) . "' ) AND post_id = %d;", $variation_id));
             foreach ($delete_attribute_keys as $key) {
                 delete_post_meta($variation_id, $key);
             }
         }
         do_action('woocommerce_rest_save_product_variation', $variation_id, $menu_order, $variation);
     }
     // Update parent if variable so price sorting works and stays in sync with the cheapest child.
     WC_Product_Variable::sync($product->id);
     // Update default attributes options setting.
     if (isset($request['default_attribute'])) {
         $request['default_attributes'] = $request['default_attribute'];
     }
     if (isset($request['default_attributes']) && is_array($request['default_attributes'])) {
         $default_attributes = array();
         foreach ($request['default_attributes'] as $attribute) {
             $attribute_id = 0;
             $attribute_name = '';
             // Check ID for global attributes or name for product attributes.
             if (!empty($attribute['id'])) {
                 $attribute_id = absint($attribute['id']);
                 $attribute_name = wc_attribute_taxonomy_name_by_id($attribute_id);
             } elseif (!empty($attribute['name'])) {
                 $attribute_name = sanitize_title($attribute['name']);
             }
             if (!$attribute_id && !$attribute_name) {
                 continue;
             }
             if (isset($attributes[$attribute_name])) {
                 $_attribute = $attributes[$attribute_name];
                 if ($_attribute['is_variation']) {
                     $value = '';
                     if (isset($attribute['option'])) {
                         if ($_attribute['is_taxonomy']) {
                             // Don't use wc_clean as it destroys sanitized characters.
                             $value = sanitize_title(trim(stripslashes($attribute['option'])));
                         } else {
                             $value = wc_clean(trim(stripslashes($attribute['option'])));
                         }
                     }
                     if ($value) {
                         $default_attributes[$attribute_name] = $value;
                     }
                 }
             }
         }
         update_post_meta($product->id, '_default_attributes', $default_attributes);
     }
     return true;
 }
 function TS_VCSC_WooCommerce_ImageGrid_Basic_Function($atts, $content = null)
 {
     global $VISUAL_COMPOSER_EXTENSIONS;
     global $product;
     global $woocommerce;
     ob_start();
     wp_enqueue_script('ts-extend-hammer');
     wp_enqueue_script('ts-extend-nacho');
     wp_enqueue_style('ts-extend-nacho');
     wp_enqueue_style('ts-font-ecommerce');
     wp_enqueue_style('ts-extend-simptip');
     wp_enqueue_style('ts-extend-animations');
     wp_enqueue_style('ts-visual-composer-extend-front');
     wp_enqueue_script('ts-visual-composer-extend-front');
     extract(shortcode_atts(array('selection' => 'recent_products', 'category' => '', 'ids' => '', 'orderby' => 'date', 'order' => 'desc', 'products_total' => 12, 'exclude_outofstock' => 'false', 'post_type' => 'product', 'limit_posts' => 'true', 'limit_by' => 'category', 'limit_term' => '', 'filter_by' => 'category', 'posts_limit' => 25, 'content_images_size' => 'medium', 'filters_show' => 'true', 'filters_available' => 'Available Groups', 'filters_selected' => 'Filtered Groups', 'filters_nogroups' => 'No Groups', 'filters_toggle' => 'Toggle Filter', 'filters_toggle_style' => '', 'filters_showall' => 'Show All', 'filters_showall_style' => '', 'data_grid_machine' => 'internal', 'data_grid_invalid' => 'false', 'data_grid_target' => '_blank', 'data_grid_breaks' => '240,480,720,960', 'data_grid_width' => 250, 'data_grid_space' => 2, 'data_grid_order' => 'false', 'data_grid_always' => 'true', 'data_grid_price' => 'true', 'fullwidth' => 'false', 'breakouts' => 6, 'margin_top' => 0, 'margin_bottom' => 0, 'el_id' => '', 'el_class' => '', 'css' => ''), $atts));
     // Check for Front End Editor
     if ($VISUAL_COMPOSER_EXTENSIONS->TS_VCSC_VCFrontEditMode == "true") {
         $grid_class = 'ts-image-link-grid-edit';
         $grid_message = '<div class="ts-composer-frontedit-message">' . __('The grid is currently viewed in front-end edit mode; grid and filter features are disabled for performance and compatibility reasons.', "ts_visual_composer_extend") . '</div>';
         $image_style = 'width: 20%; height: 100%; display: inline-block; margin: 0; padding: 0;';
         $grid_style = 'height: 100%;';
         $frontend_edit = 'true';
     } else {
         if ($data_grid_machine == 'internal') {
             $grid_class = 'ts-image-link-grid';
         } else {
             if ($data_grid_machine == 'freewall') {
                 $grid_class = 'ts-freewall-link-grid';
             }
         }
         $image_style = '';
         $grid_style = '';
         $grid_message = '';
         $frontend_edit = 'false';
     }
     $randomizer = mt_rand(999999, 9999999);
     if (!empty($el_id)) {
         $modal_id = $el_id;
     } else {
         $modal_id = 'ts-vcsc-product-link-grid-' . $randomizer;
     }
     $valid_images = 0;
     if (!empty($data_grid_breaks)) {
         $data_grid_breaks = str_replace(' ', '', $data_grid_breaks);
         $count_columns = substr_count($data_grid_breaks, ",") + 1;
     } else {
         $count_columns = 0;
     }
     $i = -1;
     $b = 0;
     $output = '';
     if ($filters_toggle_style != '') {
         wp_enqueue_style('ts-extend-buttonsflat');
     }
     wp_enqueue_style('ts-extend-multiselect');
     wp_enqueue_script('ts-extend-multiselect');
     $meta_query = '';
     $menu_tax = 'product_cat';
     $limit_tax = 'product_cat';
     // Recent Products
     if ($selection == "recent_products") {
         $meta_query = WC()->query->get_meta_query();
     }
     // Featured Products
     if ($selection == "featured_products") {
         $meta_query = array(array('key' => '_visibility', 'value' => array('catalog', 'visible'), 'compare' => 'IN'), array('key' => '_featured', 'value' => 'yes'));
     }
     // Top Rated Products
     if ($selection == "top_rated_products") {
         add_filter('posts_clauses', array(WC()->query, 'order_by_rating_post_clauses'));
         $meta_query = WC()->query->get_meta_query();
     }
     // Final Query Arguments
     $args = array('post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'posts_per_page' => $products_total, 'orderby' => $orderby, 'order' => $order, 'paged' => 1, 'meta_query' => $meta_query);
     // Products on Sale
     if ($selection == "sale_products") {
         $product_ids_on_sale = woocommerce_get_product_ids_on_sale();
         $meta_query = array();
         $meta_query[] = $woocommerce->query->visibility_meta_query();
         $meta_query[] = $woocommerce->query->stock_status_meta_query();
         $args['meta_query'] = $meta_query;
         $args['post__in'] = $product_ids_on_sale;
     }
     // Best Selling Products
     if ($selection == "best_selling_products") {
         $args['meta_key'] = 'total_sales';
         $args['orderby'] = 'meta_value_num';
         $args['meta_query'] = array(array('key' => '_visibility', 'value' => array('catalog', 'visible'), 'compare' => 'IN'));
     }
     // Products in Single Category
     if ($selection == "product_category") {
         $args['tax_query'] = array(array('taxonomy' => 'product_cat', 'terms' => array(esc_attr($category)), 'field' => 'slug', 'operator' => 'IN'));
     }
     // Products in Multiple Categories
     if ($selection == "product_categories") {
         $args['tax_query'] = array(array('taxonomy' => 'product_cat', 'terms' => explode(",", $ids), 'field' => 'term_id', 'operator' => 'IN'));
     }
     // Start WordPress Query
     $loop = new WP_Query($args);
     if ($data_grid_machine == 'internal') {
         $class_name = 'ts-image-link-grid-frame';
     } else {
         if ($data_grid_machine == 'freewall') {
             wp_enqueue_script('ts-extend-freewall');
             $class_name = 'ts-image-freewall-grid-frame';
         }
     }
     if (function_exists('vc_shortcode_custom_css_class')) {
         $css_class = apply_filters(VC_SHORTCODE_CUSTOM_CSS_FILTER_TAG, $el_class . ' ' . $class_name . ' ' . vc_shortcode_custom_css_class($css, ' '), 'TS_VCSC_WooCommerce_ImageGrid_Basic', $atts);
     } else {
         $css_class = $class_name . ' ' . $el_class;
     }
     $fullwidth_allow = "true";
     $postCounter = 0;
     $modal_gallery = '';
     // Front-Edit Message
     if ($frontend_edit == "true") {
         $modal_gallery .= $grid_message;
         if ($loop->have_posts()) {
             while ($loop->have_posts()) {
                 $loop->the_post();
                 $matched_terms = 0;
                 $post_thumbnail = get_the_post_thumbnail();
                 if ($matched_terms == 0 && ($post_thumbnail != '' || $data_grid_invalid == "false")) {
                     $postCounter++;
                     if ($postCounter < $posts_limit + 1) {
                         $product_id = get_the_ID();
                         $product_title = get_the_title($product_id);
                         $post = get_post($product_id);
                         $product = new WC_Product($product_id);
                         $attachment_ids = $product->get_gallery_attachment_ids();
                         $product_sku = $product->get_sku();
                         $attributes = $product->get_attributes();
                         $stock = $product->is_in_stock() ? 'true' : 'false';
                         if ('' != $post_thumbnail) {
                             $grid_image = wp_get_attachment_image_src(get_post_thumbnail_id(), $content_images_size);
                             $modal_image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full');
                             $grid_image = $grid_image[0];
                             $modal_image = $modal_image[0];
                         } else {
                             $grid_image = TS_VCSC_GetResourceURL('images/defaults/no_featured.png');
                             $modal_image = TS_VCSC_GetResourceURL('images/defaults/no_featured.png');
                         }
                         $categories = array();
                         if (taxonomy_exists($menu_tax)) {
                             foreach (get_the_terms($loop->post->ID, $menu_tax) as $term) {
                                 array_push($categories, $term->name);
                             }
                             $categories = implode($categories, ',');
                         }
                         $valid_images++;
                         $modal_gallery .= '<a style="' . $image_style . '" href="' . get_permalink() . '" target="_blank" title="' . get_the_title() . '">';
                         $modal_gallery .= '<img id="ts-image-link-picture-' . $randomizer . '-' . $i . '" class="ts-image-link-picture" src="' . $grid_image . '" rel="link-group-' . $randomizer . '" data-include="true" data-image="' . $modal_image . '" width="100%" height="auto" title="' . get_the_title() . '" data-groups="' . $categories . '" data-target="' . $data_grid_target . '" data-link="' . get_permalink() . '">';
                         $modal_gallery .= '</a>';
                         $categories = array();
                     }
                 }
             }
         } else {
             echo __("No products could be found.", "ts_visual_composer_extend");
         }
         wp_reset_postdata();
         wp_reset_query();
     } else {
         if ($loop->have_posts()) {
             if ($data_grid_machine == 'freewall') {
                 $filter_settings = 'data-gridfilter="' . $filters_show . '" data-gridavailable="' . $filters_available . '" data-gridselected="' . $filters_selected . '" data-gridnogroups="' . $filters_nogroups . '" data-gridtoggle="' . $filters_toggle . '" data-gridtogglestyle="' . $filters_toggle_style . '" data-gridshowall="' . $filters_showall . '" data-gridshowallstyle="' . $filters_showall_style . '"';
                 $modal_gallery .= '<div id="ts-lightbox-freewall-grid-' . $randomizer . '-container" class="ts-lightbox-freewall-grid-container" data-random="' . $randomizer . '" data-width="' . $data_grid_width . '" data-gutter="' . $data_grid_space . '" ' . $filter_settings . ' style="margin-top: ' . $margin_top . 'px; margin-bottom: ' . $margin_bottom . 'px;">';
             }
             while ($loop->have_posts()) {
                 $loop->the_post();
                 $matched_terms = 0;
                 $post_thumbnail = get_the_post_thumbnail();
                 if ($matched_terms == 0 && ($post_thumbnail != '' || $data_grid_invalid == "false")) {
                     $postCounter++;
                     if ($postCounter < $posts_limit + 1) {
                         $product_id = get_the_ID();
                         $product_title = get_the_title($product_id);
                         $post = get_post($product_id);
                         $product = new WC_Product($product_id);
                         $attachment_ids = $product->get_gallery_attachment_ids();
                         $product_sku = $product->get_sku();
                         $attributes = $product->get_attributes();
                         $stock = $product->is_in_stock() ? 'true' : 'false';
                         if ('' != $post_thumbnail) {
                             $grid_image = wp_get_attachment_image_src(get_post_thumbnail_id(), $content_images_size);
                             $modal_image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full');
                             $grid_image = $grid_image[0];
                             $modal_image = $modal_image[0];
                         } else {
                             $grid_image = TS_VCSC_GetResourceURL('images/defaults/no_featured.png');
                             $modal_image = TS_VCSC_GetResourceURL('images/defaults/no_featured.png');
                         }
                         $categories = array();
                         if (taxonomy_exists($menu_tax)) {
                             if ($filters_show == "true") {
                                 foreach (get_the_terms($loop->post->ID, $menu_tax) as $term) {
                                     array_push($categories, $term->name);
                                 }
                             }
                             $categories = implode($categories, ',');
                         }
                         $valid_images++;
                         $costs = $product->price;
                         $costs = is_numeric($costs) ? wc_price($costs) : $costs;
                         $costs = strip_tags($costs);
                         if ($data_grid_price == "true") {
                             $price = $costs . ' / ';
                         } else {
                             $price = '';
                         }
                         if ($data_grid_machine == 'internal') {
                             $modal_gallery .= '<img id="ts-image-link-picture-' . $randomizer . '-' . $i . '" class="ts-image-link-picture" src="' . $grid_image . '" rel="link-group-' . $randomizer . '" data-no-lazy="1" data-price="' . $costs . '" data-include="true" data-image="' . $modal_image . '" width="100%" height="auto" title="' . $price . get_the_title() . '" data-groups="' . $categories . '" data-target="' . $data_grid_target . '" data-link="' . get_permalink() . '">';
                         } else {
                             if ($data_grid_machine == 'freewall') {
                                 $modal_gallery .= '<div id="ts-lightbox-freewall-item-' . $randomizer . '-' . $i . '-parent" class="ts-lightbox-freewall-item ts-lightbox-freewall-active ' . $el_class . ' nchgrid-item nchgrid-tile" data-fixSize="false" data-groups="' . $categories . '" data-target="' . $data_grid_target . '" data-link="' . get_permalink() . '" data-showing="true" data-groups="' . (!empty($categories) ? str_replace('/', ',', $categories) : "") . '" style="width: ' . $data_grid_width . 'px; margin: 0; padding: 0;">';
                                 $modal_gallery .= '<a id="ts-lightbox-freewall-item-' . $randomizer . '-' . $i . '" href="' . get_permalink() . '" target="' . $data_grid_target . '" title="' . get_the_title() . '">';
                                 $modal_gallery .= '<img id="ts-lightbox-freewall-picture-' . $randomizer . '-' . $i . '" class="ts-lightbox-freewall-picture" src="' . $grid_image . '" width="100%" height="auto" title="' . $price . get_the_title() . '">';
                                 $modal_gallery .= '<div class="nchgrid-caption"></div>';
                                 $modal_gallery .= '<div class="nchgrid-caption-text ' . ($data_grid_always == 'true' ? 'nchgrid-caption-text-always' : '') . '">' . $price . get_the_title() . '</div>';
                                 $modal_gallery .= '</a>';
                                 $modal_gallery .= '</div>';
                             }
                         }
                         $categories = array();
                     }
                 }
             }
             if ($data_grid_machine == 'freewall') {
                 $modal_gallery .= '</div>';
             }
         } else {
             echo __("No products could be found.", "ts_visual_composer_extend");
         }
         wp_reset_postdata();
         wp_reset_query();
     }
     if ($valid_images < $count_columns) {
         $data_grid_string = explode(',', $data_grid_breaks);
         $data_grid_breaks = array();
         foreach ($data_grid_string as $single_break) {
             $b++;
             if ($b <= $valid_images) {
                 array_push($data_grid_breaks, $single_break);
             } else {
                 break;
             }
         }
         $data_grid_breaks = implode(",", $data_grid_breaks);
     } else {
         $data_grid_breaks = $data_grid_breaks;
     }
     $output .= '<div id="' . $modal_id . '-frame" class="' . $grid_class . ' ' . $css_class . ' ' . ($fullwidth == "true" && $fullwidth_allow == "true" ? "ts-lightbox-nacho-full-frame" : "") . '" data-random="' . $randomizer . '" data-grid="' . $data_grid_breaks . '" data-margin="' . $data_grid_space . '" data-always="' . $data_grid_always . '" data-order="' . $data_grid_order . '" data-break-parents="' . $breakouts . '" data-inline="' . $frontend_edit . '" data-gridfilter="' . $filters_show . '" data-gridavailable="' . $filters_available . '" data-gridselected="' . $filters_selected . '" data-gridnogroups="' . $filters_nogroups . '" data-gridtoggle="' . $filters_toggle . '" data-gridtogglestyle="' . $filters_toggle_style . '" data-gridshowall="' . $filters_showall . '" data-gridshowallstyle="' . $filters_showall_style . '" style="margin-top: ' . $margin_top . 'px; margin-bottom: ' . $margin_bottom . 'px; position: relative;">';
     if ($data_grid_machine == 'internal') {
         $output .= '<div id="nch-lb-grid-' . $randomizer . '" class="nch-lb-grid" data-filter="nch-lb-filter-' . $randomizer . '" style="' . $grid_style . '" data-toggle="nch-lb-toggle-' . $randomizer . '" data-random="' . $randomizer . '">';
     }
     $output .= $modal_gallery;
     if ($data_grid_machine == 'internal') {
         $output .= '</div>';
     }
     $output .= '</div>';
     echo $output;
     $myvariable = ob_get_clean();
     return $myvariable;
 }
Example #5
0
 private function get_product_from_post($post_id)
 {
     $woocommerce_ver_below_2_1 = false;
     if (version_compare(WOOCOMMERCE_VERSION, '2.1', '<')) {
         $woocommerce_ver_below_2_1 = true;
     }
     if ($woocommerce_ver_below_2_1) {
         $product = new WC_Product_Simple($post_id);
     } else {
         $product = new WC_Product($post_id);
     }
     //$post_categories = wp_get_post_categories( $post_id );
     //$categories = get_the_category();
     try {
         $thumbnail = $product->get_image();
         if ($thumbnail) {
             if (preg_match('/data-lazy-src="([^\\"]+)"/s', $thumbnail, $match)) {
                 $thumbnail = $match[1];
             } else {
                 if (preg_match('/data-lazy-original="([^\\"]+)"/s', $thumbnail, $match)) {
                     $thumbnail = $match[1];
                 } else {
                     if (preg_match('/lazy-src="([^\\"]+)"/s', $thumbnail, $match)) {
                         // Animate Lazy Load Wordpress Plugin
                         $thumbnail = $match[1];
                     } else {
                         if (preg_match('/data-echo="([^\\"]+)"/s', $thumbnail, $match)) {
                             $thumbnail = $match[1];
                         } else {
                             preg_match('/<img(.*)src(.*)=(.*)"(.*)"/U', $thumbnail, $result);
                             $thumbnail = array_pop($result);
                         }
                     }
                 }
             }
         }
     } catch (Exception $e) {
         $err_msg = "exception raised in thumbnails";
         self::send_error_report($err_msg);
         $thumbnail = '';
     }
     // handling scheduled sale price update
     if (!$woocommerce_ver_below_2_1) {
         $sale_price_dates_from = get_post_meta($post_id, '_sale_price_dates_from', true);
         $sale_price_dates_to = get_post_meta($post_id, '_sale_price_dates_to', true);
         if ($sale_price_dates_from || $sale_price_dates_to) {
             self::schedule_sale_price_update($post_id, null);
         }
         if ($sale_price_dates_from) {
             self::schedule_sale_price_update($post_id, $sale_price_dates_from);
         }
         if ($sale_price_dates_to) {
             self::schedule_sale_price_update($post_id, $sale_price_dates_to);
         }
     }
     $product_tags = array();
     foreach (wp_get_post_terms($post_id, 'product_tag') as $tag) {
         $product_tags[] = $tag->name;
     }
     $product_brands = array();
     if (taxonomy_exists('product_brand')) {
         foreach (wp_get_post_terms($post_id, 'product_brand') as $brand) {
             $product_brands[] = $brand->name;
         }
     }
     $taxonomies = array();
     try {
         $all_taxonomies = get_option('wcis_taxonomies');
         if (is_array($all_taxonomies)) {
             foreach ($all_taxonomies as $taxonomy) {
                 if (taxonomy_exists($taxonomy) && !array_key_exists($taxonomy, $taxonomies)) {
                     foreach (wp_get_post_terms($post_id, $taxonomy) as $taxonomy_value) {
                         if (!array_key_exists($taxonomy, $taxonomies)) {
                             $taxonomies[$taxonomy] = array();
                         }
                         $taxonomies[$taxonomy][] = $taxonomy_value->name;
                     }
                 }
             }
         }
     } catch (Exception $e) {
     }
     $acf_fields = array();
     try {
         if (class_exists('acf') && function_exists('get_field')) {
             $all_acf_fields = get_option('wcis_acf_fields');
             if (is_array($all_acf_fields)) {
                 foreach ($all_acf_fields as $acf_field_name) {
                     $acf_field_value = get_field($acf_field_name, $post_id);
                     if ($acf_field_value) {
                         $acf_fields[$acf_field_name] = $acf_field_value;
                     }
                 }
             }
         }
     } catch (Exception $e) {
     }
     $send_product = array('product_id' => $product->id, 'currency' => get_woocommerce_currency(), 'price' => $product->get_price(), 'url' => get_permalink($product->id), 'thumbnail_url' => $thumbnail, 'action' => 'insert', 'description' => $product->get_post_data()->post_content, 'short_description' => $product->get_post_data()->post_excerpt, 'name' => $product->get_title(), 'sku' => $product->get_sku(), 'categories' => $product->get_categories(), 'tag' => $product_tags, 'store_id' => get_current_blog_id(), 'identifier' => (string) $product->id, 'product_brand' => $product_brands, 'taxonomies' => $taxonomies, 'acf_fields' => $acf_fields, 'sellable' => $product->is_purchasable(), 'visibility' => $product->is_visible(), 'stock_quantity' => $product->get_stock_quantity(), 'is_managing_stock' => $product->managing_stock(), 'is_backorders_allowed' => $product->backorders_allowed(), 'is_purchasable' => $product->is_purchasable(), 'is_in_stock' => $product->is_in_stock(), 'product_status' => get_post_status($post_id));
     try {
         $variable = new WC_Product_Variable($post_id);
         $variations = $variable->get_available_variations();
         $variations_sku = '';
         if (!empty($variations)) {
             foreach ($variations as $variation) {
                 if ($product->get_sku() != $variation['sku']) {
                     $variations_sku .= $variation['sku'] . ' ';
                 }
             }
         }
         $send_product['variations_sku'] = $variations_sku;
         $all_attributes = $product->get_attributes();
         $attributes = array();
         if (!empty($all_attributes)) {
             foreach ($all_attributes as $attr_mame => $value) {
                 if ($all_attributes[$attr_mame]['is_taxonomy']) {
                     if (!$woocommerce_ver_below_2_1) {
                         $attributes[$attr_mame] = wc_get_product_terms($post_id, $attr_mame, array('fields' => 'names'));
                     } else {
                         $attributes[$attr_mame] = woocommerce_get_product_terms($post_id, $attr_mame, 'names');
                     }
                 } else {
                     $attributes[$attr_mame] = $product->get_attribute($attr_mame);
                 }
             }
         }
         $send_product['attributes'] = $attributes;
         $send_product['total_variable_stock'] = $variable->get_total_stock();
         try {
             if (version_compare(WOOCOMMERCE_VERSION, '2.2', '>=')) {
                 if (function_exists('wc_get_product')) {
                     $original_product = wc_get_product($product->id);
                     if (is_object($original_product)) {
                         $send_product['visibility'] = $original_product->is_visible();
                         $send_product['product_type'] = $original_product->product_type;
                     }
                 }
             } else {
                 if (function_exists('get_product')) {
                     $original_product = get_product($product->id);
                     if (is_object($original_product)) {
                         $send_product['visibility'] = $original_product->is_visible();
                         $send_product['product_type'] = $original_product->product_type;
                     }
                 }
             }
         } catch (Exception $e) {
         }
     } catch (Exception $e) {
         $err_msg = "exception raised in attributes";
         self::send_error_report($err_msg);
     }
     if (!$woocommerce_ver_below_2_1) {
         try {
             $send_product['price_compare_at_price'] = $product->get_regular_price();
             $send_product['price_min'] = $variable->get_variation_price('min');
             $send_product['price_max'] = $variable->get_variation_price('max');
             $send_product['price_min_compare_at_price'] = $variable->get_variation_regular_price('min');
             $send_product['price_max_compare_at_price'] = $variable->get_variation_regular_price('max');
         } catch (Exception $e) {
             $send_product['price_compare_at_price'] = null;
             $send_product['price_min'] = null;
             $send_product['price_max'] = null;
             $send_product['price_min_compare_at_price'] = null;
             $send_product['price_max_compare_at_price'] = null;
         }
     } else {
         $send_product['price_compare_at_price'] = null;
         $send_product['price_min'] = null;
         $send_product['price_max'] = null;
         $send_product['price_min_compare_at_price'] = null;
         $send_product['price_max_compare_at_price'] = null;
     }
     $send_product['description'] = self::content_filter_shortcode_with_content($send_product['description']);
     $send_product['short_description'] = self::content_filter_shortcode_with_content($send_product['short_description']);
     $send_product['description'] = self::content_filter_shortcode($send_product['description']);
     $send_product['short_description'] = self::content_filter_shortcode($send_product['short_description']);
     try {
         if (defined('ICL_SITEPRESS_VERSION') && is_plugin_active('woocommerce-multilingual/wpml-woocommerce.php') && function_exists('wpml_get_language_information')) {
             if (version_compare(ICL_SITEPRESS_VERSION, '3.2', '>=')) {
                 $language_info = apply_filters('wpml_post_language_details', NULL, $post_id);
             } else {
                 $language_info = wpml_get_language_information($post_id);
             }
             if ($language_info && is_array($language_info) && array_key_exists('locale', $language_info)) {
                 // WP_Error could be returned from wpml_get_language_information(...)
                 $send_product['lang'] = $language_info['locale'];
             }
         }
     } catch (Exception $e) {
     }
     return $send_product;
 }
 public function wpmp_content_invoice($order, $order_detail_by_order_id)
 {
     $msg = '<!-- Content -->';
     $msg .= '<table border="0" cellpadding="20" cellspacing="0" width="100%">';
     $msg .= '<tr>';
     $msg .= '<td valign="top" style="padding: 48px;">';
     $msg .= '<div id="body_content_inner" style="color: #737373;  font-size: 14px; line-height: 150%; text-align: left;"">';
     $msg .= '<p style="margin: 0 0 16px;">You have received an order from ' . $order->billing_first_name . ' ' . $order->billing_last_name . '. The order is as follows:</p>';
     $msg .= '<h2 style="color: #557da1; display: block; font-size: 18px; font-weight: bold; line-height: 130%; margin: 16px 0 8px; text-align: left;"">';
     $msg .= 'Order #' . $order->id . ' ( ' . date_i18n(wc_date_format(), strtotime($order->order_date)) . ' )';
     $msg .= '</h2>';
     $msg .= '<table cellspacing="0" cellpadding="6" style="width: 100%; border: 1px solid #eee;" border="1" bordercolor="#eee">';
     $msg .= '<thead>';
     $msg .= '<tr>';
     $msg .= '<th scope="col" style="text-align: left; border: 1px solid #eee; padding: 12px;">Product</th>';
     $msg .= '<th scope="col" style="text-align: left; border: 1px solid #eee; padding: 12px;">Quantity</th>';
     $msg .= '<th scope="col" style="text-align: left; border: 1px solid #eee; padding: 12px;">Price</th>';
     $msg .= '</tr>';
     $msg .= '</thead>';
     $msg .= '<tbody>';
     $total_payment = 0;
     $cur_symbol = get_woocommerce_currency_symbol(get_option('woocommerce_currency'));
     foreach ($order_detail_by_order_id as $product_id => $details) {
         for ($i = 0; $i < count($details); $i++) {
             $total_payment = $total_payment + intval($details[$i]['product_total_price']);
             if ($details[$i]['variable_id'] == 0) {
                 $msg .= '<tr>';
                 $msg .= '<td style="text-align: left; vertical-align: middle; border: 1px solid #eee; word-wrap: break-word; padding: 12px;">' . $details[$i]['product_name'];
                 $msg .= '<br>';
                 $msg .= '<small></small>';
                 $msg .= '</td>';
                 $msg .= '<td style="text-align: left; vertical-align: middle; border: 1px solid #eee; padding: 12px;">' . $details[$i]['qty'] . '</td>';
                 $msg .= '<td style="text-align: left; vertical-align: middle; border: 1px solid #eee; padding: 12px;">';
                 $msg .= '<span class="amount">' . $cur_symbol . $details[$i]['product_total_price'] . '</span>';
                 $msg .= '</td>';
                 $msg .= '</tr>';
             } else {
                 $product = new WC_Product($product_id);
                 $attribute = $product->get_attributes();
                 $attribute_name = '';
                 foreach ($attribute as $key => $value) {
                     $attribute_name = $value['name'];
                 }
                 $variation = new WC_Product_Variation($details[$i]['variable_id']);
                 $aaa = $variation->get_variation_attributes();
                 $attribute_prop = strtoupper($aaa['attribute_' . strtolower($attribute_name)]);
                 $msg .= '<tr>';
                 $msg .= '<td style="text-align: left; vertical-align: middle; border: 1px solid #eee; word-wrap: break-word; padding: 12px;">' . $details[$i]['product_name'];
                 $msg .= '<br><small>' . $attribute_name . ':' . $attribute_prop . '</small>';
                 $msg .= '</td>';
                 $msg .= '<td style="text-align: left; vertical-align: middle; border: 1px solid #eee; padding: 12px;">' . $details[$i]['qty'] . '</td>';
                 $msg .= '<td style="text-align: left; vertical-align: middle; border: 1px solid #eee; padding: 12px;">';
                 $msg .= '<span class="amount">' . $cur_symbol . $details[$i]['product_total_price'] . '</span>';
                 $msg .= '</td>';
                 $msg .= '</tr>';
             }
         }
     }
     $msg .= '</tbody>';
     $msg .= '<tfoot>';
     /*$msg .= '<!--  <tr>';
           $msg .= '<th scope="row" colspan="2" style="text-align: left; border: 1px solid #eee; border-top-width: 4px; padding: 12px;">Subtotal:</th>';
           $msg .= '<td style="text-align: left; border: 1px solid #eee; border-top-width: 4px; padding: 12px;">';
               $msg .= '<span class="amount"></span>';
           $msg .= '</td>';
       $msg .= '</tr> -->';*/
     $msg .= '<tr>';
     $msg .= '<th scope="row" colspan="2" style="text-align: left; border: 1px solid #eee; padding: 12px;">Shipping:</th>';
     $msg .= '<td style="text-align: left; border: 1px solid #eee; padding: 12px;">' . $order->get_shipping_method() . '</td>';
     $msg .= '</tr>';
     $msg .= '<tr>';
     $msg .= '<th scope="row" colspan="2" style="text-align: left; border: 1px solid #eee; padding: 12px;">Payment Method:</th>';
     $msg .= '<td style="text-align: left; border: 1px solid #eee; padding: 12px;">' . $order->payment_method_title . '</td>';
     $msg .= '</tr>';
     $msg .= '<tr>';
     $msg .= '<th scope="row" colspan="2" style="text-align: left; border: 1px solid #eee; padding: 12px;">Total:</th>';
     $msg .= '<td style="text-align: left; border: 1px solid #eee; padding: 12px;">';
     $msg .= '<span class="amount">' . $total_payment . '</span>';
     $msg .= '</td>';
     $msg .= '</tr>';
     $msg .= '</tfoot>';
     $msg .= '</table>';
     $msg .= '<h2 style="color: #557da1; display: block; font-size: 18px; font-weight: bold; line-height: 130%; margin: 16px 0 8px; text-align: left;">Customer details</h2>';
     $msg .= '<p style="margin: 0 0 16px;">';
     $msg .= '<strong>Email:</strong>';
     if ($order->billing_email) {
         $msg .= $order->billing_email;
     }
     $msg .= '</p>';
     $msg .= '<p style="margin: 0 0 16px;">';
     $msg .= '<strong>Tel:</strong>';
     if ($order->billing_phone) {
         $msg .= $order->billing_phone;
     }
     $msg .= '</p>';
     $msg .= '<table cellspacing="0" cellpadding="0" style="width: 100%; vertical-align: top;" border="0">';
     $msg .= '<tr>';
     $msg .= '<td valign="top" width="50%" style="padding: 12px;">';
     $font = ' font-family: "Helvetica Neue", Helvetica, Roboto, Arial, sans-serif;';
     $msg .= "<h3 style='color: #557da1; display: block;" . $font . " font-size: 16px; font-weight: bold; line-height: 130%; margin: 16px 0 8px; text-align: left;'>Billing address</h3>";
     $msg .= '<p style="margin: 0 0 16px;">' . $order->get_formatted_billing_address();
     $msg .= '</p>';
     $msg .= '</td>';
     if (!wc_ship_to_billing_address_only() && $order->needs_shipping_address() && ($shipping = $order->get_formatted_shipping_address())) {
         $msg .= '<td valign="top" width="50%" style="padding: 12px;">';
         $msg .= "<h3 style='color: #557da1; display: block; font-size: 16px; font-weight: bold; line-height: 130%; margin: 16px 0 8px; text-align: left;'>Shipping address</h3>";
         $msg .= '<p style="margin: 0 0 16px;">' . $shipping;
         $msg .= '</p>';
         $msg .= '</td>';
     }
     $msg .= '</tr>';
     $msg .= '</table>';
     $msg .= '</div>';
     $msg .= '</td>';
     $msg .= '</tr>';
     $msg .= '</table>';
     $msg .= '<!-- End Content -->';
     return $msg;
 }
function woocommerce_link_all_variations()
{
    check_ajax_referer('link-variations', 'security');
    @set_time_limit(0);
    $post_id = intval($_POST['post_id']);
    if (!$post_id) {
        die;
    }
    $variations = array();
    $_product = new WC_Product($post_id);
    // Put variation attributes into an array
    foreach ($_product->get_attributes() as $attribute) {
        if (!$attribute['is_variation']) {
            continue;
        }
        $attribute_field_name = 'attribute_' . sanitize_title($attribute['name']);
        if ($attribute['is_taxonomy']) {
            $post_terms = wp_get_post_terms($post_id, $attribute['name']);
            $options = array();
            foreach ($post_terms as $term) {
                $options[] = $term->slug;
            }
        } else {
            $options = explode('|', $attribute['value']);
        }
        $options = array_map('trim', $options);
        $variations[$attribute_field_name] = $options;
    }
    // Quit out if none were found
    if (sizeof($variations) == 0) {
        die;
    }
    // Get existing variations so we don't create duplicated
    $available_variations = array();
    foreach ($_product->get_children() as $child_id) {
        $child = $_product->get_child($child_id);
        if ($child instanceof WC_Product_Variation) {
            $available_variations[] = $child->get_variation_attributes();
        }
    }
    // Created posts will all have the following data
    $variation_post_data = array('post_title' => 'Product #' . $post_id . ' Variation', 'post_content' => '', 'post_status' => 'publish', 'post_author' => get_current_user_id(), 'post_parent' => $post_id, 'post_type' => 'product_variation');
    // Now find all combinations and create posts
    if (!function_exists('array_cartesian')) {
        function array_cartesian($input)
        {
            $result = array();
            while (list($key, $values) = each($input)) {
                // If a sub-array is empty, it doesn't affect the cartesian product
                if (empty($values)) {
                    continue;
                }
                // Special case: seeding the product array with the values from the first sub-array
                if (empty($result)) {
                    foreach ($values as $value) {
                        $result[] = array($key => $value);
                    }
                } else {
                    // Second and subsequent input sub-arrays work like this:
                    //   1. In each existing array inside $product, add an item with
                    //      key == $key and value == first item in input sub-array
                    //   2. Then, for each remaining item in current input sub-array,
                    //      add a copy of each existing array inside $product with
                    //      key == $key and value == first item in current input sub-array
                    // Store all items to be added to $product here; adding them on the spot
                    // inside the foreach will result in an infinite loop
                    $append = array();
                    foreach ($result as &$product) {
                        // Do step 1 above. array_shift is not the most efficient, but it
                        // allows us to iterate over the rest of the items with a simple
                        // foreach, making the code short and familiar.
                        $product[$key] = array_shift($values);
                        // $product is by reference (that's why the key we added above
                        // will appear in the end result), so make a copy of it here
                        $copy = $product;
                        // Do step 2 above.
                        foreach ($values as $item) {
                            $copy[$key] = $item;
                            $append[] = $copy;
                        }
                        // Undo the side effecst of array_shift
                        array_unshift($values, $product[$key]);
                    }
                    // Out of the foreach, we can add to $results now
                    $result = array_merge($result, $append);
                }
            }
            return $result;
        }
    }
    $variation_ids = array();
    $added = 0;
    $possible_variations = array_cartesian($variations);
    foreach ($possible_variations as $variation) {
        // Check if variation already exists
        if (in_array($variation, $available_variations)) {
            continue;
        }
        $variation_id = wp_insert_post($variation_post_data);
        $variation_ids[] = $variation_id;
        foreach ($variation as $key => $value) {
            update_post_meta($variation_id, $key, $value);
        }
        $added++;
        // Max 100
        if ($added > 49) {
            break;
        }
    }
    echo $added;
    die;
}
 /**
  * Find a matching (enabled) variation within a variable product.
  *
  * @since  2.7.0
  * @param  WC_Product $product Variable product.
  * @param  array $match_attributes Array of attributes we want to try to match.
  * @return int Matching variation ID or 0.
  */
 public function find_matching_product_variation($product, $match_attributes = array())
 {
     $query_args = array('post_parent' => $product->get_id(), 'post_type' => 'product_variation', 'orderby' => 'menu_order', 'order' => 'ASC', 'fields' => 'ids', 'post_status' => 'publish', 'numberposts' => 1, 'meta_query' => array());
     // Allow large queries in case user has many variations or attributes.
     $GLOBALS['wpdb']->query('SET SESSION SQL_BIG_SELECTS=1');
     foreach ($product->get_attributes() as $attribute) {
         if (!$attribute->get_variation()) {
             continue;
         }
         $attribute_field_name = 'attribute_' . sanitize_title($attribute->get_name());
         if (!isset($match_attributes[$attribute_field_name])) {
             return 0;
         }
         $value = wc_clean($match_attributes[$attribute_field_name]);
         $query_args['meta_query'][] = array('relation' => 'OR', array('key' => $attribute_field_name, 'value' => array('', $value), 'compare' => 'IN'), array('key' => $attribute_field_name, 'compare' => 'NOT EXISTS'));
     }
     $variations = get_posts($query_args);
     if ($variations && !is_wp_error($variations)) {
         return current($variations);
     } elseif (version_compare(get_post_meta($product->get_id(), '_product_version', true), '2.4.0', '<')) {
         /**
          * Pre 2.4 handling where 'slugs' were saved instead of the full text attribute.
          * Fallback is here because there are cases where data will be 'synced' but the product version will remain the same.
          */
         return array_map('sanitize_title', $match_attributes) === $match_attributes ? 0 : $this->find_matching_product_variation($product, array_map('sanitize_title', $match_attributes));
     }
     return 0;
 }
 function TS_VCSC_WooCommerce_Grid_Basic_Function($atts, $content = null)
 {
     global $VISUAL_COMPOSER_EXTENSIONS;
     global $product;
     global $woocommerce;
     ob_start();
     if ($VISUAL_COMPOSER_EXTENSIONS->TS_VCSC_VCFrontEditMode == "true") {
         if ($VISUAL_COMPOSER_EXTENSIONS->TS_VCSC_LoadFrontEndForcable == "false") {
             wp_enqueue_style('ts-visual-composer-extend-front');
         }
     } else {
         wp_enqueue_script('ts-extend-hammer');
         wp_enqueue_script('ts-extend-nacho');
         wp_enqueue_style('ts-extend-nacho');
         wp_enqueue_style('ts-extend-dropdown');
         wp_enqueue_script('ts-extend-dropdown');
         wp_enqueue_style('ts-font-ecommerce');
         wp_enqueue_style('ts-extend-animations');
         wp_enqueue_style('dashicons');
         if ($VISUAL_COMPOSER_EXTENSIONS->TS_VCSC_LoadFrontEndForcable == "false") {
             wp_enqueue_style('ts-extend-buttons');
             wp_enqueue_style('ts-visual-composer-extend-front');
             wp_enqueue_script('ts-extend-isotope');
             wp_enqueue_script('ts-visual-composer-extend-front');
         }
         add_action('wp_footer', array($this, 'TS_VCSC_WooCommerce_Grid_Function_Isotope'), 9999);
     }
     extract(shortcode_atts(array('selection' => 'recent_products', 'category' => '', 'ids' => '', 'orderby' => 'date', 'order' => 'desc', 'products_total' => 12, 'exclude_outofstock' => 'false', 'show_image' => 'true', 'show_link' => 'true', 'link_page' => 'false', 'link_target' => '_parent', 'show_rating' => 'true', 'show_stock' => 'true', 'show_price' => 'true', 'show_cart' => 'true', 'show_info' => 'true', 'show_content' => 'excerpt', 'cutoff_characters' => 400, 'lightbox_group_name' => 'nachogroup', 'lightbox_size' => 'full', 'lightbox_effect' => 'random', 'lightbox_speed' => 5000, 'lightbox_social' => 'true', 'lightbox_backlight_choice' => 'predefined', 'lightbox_backlight_color' => '#0084E2', 'lightbox_backlight_custom' => '#000000', 'image_position' => 'ts-imagefloat-center', 'hover_type' => 'ts-imagehover-style1', 'hover_active' => 'false', 'overlay_trigger' => 'ts-trigger-hover', 'rating_maximum' => 5, 'rating_value' => 0, 'rating_dynamic' => '', 'rating_quarter' => 'true', 'rating_size' => 16, 'rating_auto' => 'false', 'rating_rtl' => 'false', 'rating_symbol' => 'other', 'rating_icon' => 'ts-ecommerce-starfull1', 'color_rated' => '#FFD800', 'color_empty' => '#e3e3e3', 'caption_show' => 'false', 'caption_position' => 'left', 'caption_digits' => '.', 'caption_danger' => '#d9534f', 'caption_warning' => '#f0ad4e', 'caption_info' => '#5bc0de', 'caption_primary' => '#428bca', 'caption_success' => '#5cb85c', 'post_type' => 'product', 'date_format' => 'F j, Y', 'time_format' => 'l, g:i A', 'filter_menu' => 'true', 'layout_menu' => 'true', 'sort_menu' => 'false', 'directions_menu' => 'false', 'filter_by' => 'product_cat', 'layout' => 'masonry', 'column_width' => 285, 'layout_break' => 600, 'show_periods' => 'false', 'sort_by' => 'postName', 'sort_order' => 'asc', 'posts_limit' => 25, 'posts_lazy' => 'false', 'posts_ajax' => 10, 'posts_load' => 'Show More', 'posts_trigger' => 'click', 'margin_top' => 0, 'margin_bottom' => 0, 'el_id' => '', 'el_class' => '', 'css' => ''), $atts));
     $postsgrid_random = mt_rand(999999, 9999999);
     $opening = $closing = $controls = $products = '';
     $posts_limit = $products_total;
     if (!empty($el_id)) {
         $posts_container_id = $el_id;
     } else {
         $posts_container_id = 'ts-vcsc-woocommerce-grid-' . $postsgrid_random;
     }
     // Backlight Color
     if ($lightbox_backlight_choice == "predefined") {
         $lightbox_backlight_selection = $lightbox_backlight_color;
     } else {
         $lightbox_backlight_selection = $lightbox_backlight_custom;
     }
     // Check for Front End Editor
     if ($VISUAL_COMPOSER_EXTENSIONS->TS_VCSC_VCFrontEditMode == "true") {
         $product_style = '';
         $frontend_edit = 'true';
         $description_style = 'display: none; padding: 15px;';
     } else {
         $product_style = '';
         $frontend_edit = 'false';
         $description_style = 'display: none; padding: 15px;';
     }
     $meta_query = '';
     // Recent Products
     if ($selection == "recent_products") {
         $meta_query = WC()->query->get_meta_query();
     }
     // Featured Products
     if ($selection == "featured_products") {
         $meta_query = array(array('key' => '_visibility', 'value' => array('catalog', 'visible'), 'compare' => 'IN'), array('key' => '_featured', 'value' => 'yes'));
     }
     // Top Rated Products
     if ($selection == "top_rated_products") {
         add_filter('posts_clauses', array(WC()->query, 'order_by_rating_post_clauses'));
         $meta_query = WC()->query->get_meta_query();
     }
     // Final Query Arguments
     $args = array('post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'posts_per_page' => $products_total, 'orderby' => $orderby, 'order' => $order, 'paged' => 1, 'meta_query' => $meta_query);
     // Products on Sale
     if ($selection == "sale_products") {
         $product_ids_on_sale = woocommerce_get_product_ids_on_sale();
         $meta_query = array();
         $meta_query[] = $woocommerce->query->visibility_meta_query();
         $meta_query[] = $woocommerce->query->stock_status_meta_query();
         $args['meta_query'] = $meta_query;
         $args['post__in'] = $product_ids_on_sale;
     }
     // Best Selling Products
     if ($selection == "best_selling_products") {
         $args['meta_key'] = 'total_sales';
         $args['orderby'] = 'meta_value_num';
         $args['meta_query'] = array(array('key' => '_visibility', 'value' => array('catalog', 'visible'), 'compare' => 'IN'));
     }
     // Products in Single Category
     if ($selection == "product_category") {
         $args['tax_query'] = array(array('taxonomy' => 'product_cat', 'terms' => array(esc_attr($category)), 'field' => 'slug', 'operator' => 'IN'));
     }
     // Products in Multiple Categories
     if ($selection == "product_categories") {
         $args['tax_query'] = array(array('taxonomy' => 'product_cat', 'terms' => explode(",", $ids), 'field' => 'term_id', 'operator' => 'IN'));
     }
     $menu_tax = 'product_cat';
     $limit_tax = 'product_cat';
     // Start WordPress Query
     $loop = new WP_Query($args);
     // Language Settings: Isotope Posts
     $TS_VCSC_Isotope_Posts_Language = get_option('ts_vcsc_extend_settings_translationsIsotopePosts', '');
     if ($TS_VCSC_Isotope_Posts_Language == false || empty($TS_VCSC_Isotope_Posts_Language)) {
         $TS_VCSC_Isotope_Posts_Language = $VISUAL_COMPOSER_EXTENSIONS->TS_VCSC_Isotope_Posts_Language_Defaults;
     }
     if (function_exists('vc_shortcode_custom_css_class')) {
         $css_class = apply_filters(VC_SHORTCODE_CUSTOM_CSS_FILTER_TAG, ' ' . vc_shortcode_custom_css_class($css, ' '), 'TS_VCSC_WooCommerce_Grid_Basic', $atts);
     } else {
         $css_class = '';
     }
     if ($VISUAL_COMPOSER_EXTENSIONS->TS_VCSC_VCFrontEditMode == 'false') {
         $isotope_posts_list_class = 'ts-posts-timeline-view';
     } else {
         $isotope_posts_list_class = 'ts-posts-timeline-edit';
     }
     if ($VISUAL_COMPOSER_EXTENSIONS->TS_VCSC_VCFrontEditMode == 'true') {
         echo '<div id="ts-isotope-posts-grid-frontend-' . $postsgrid_random . '" class="ts-isotope-posts-grid-frontend" style="border: 1px solid #ededed; padding: 10px;">';
         echo '<div style="font-weight: bold;">"Basic Products Isotope Grid"</div>';
         echo '<div style="margin-bottom: 20px;">The element has been disabled in order to ensure compatiblity with the Visual Composer Front-End Editor.</div>';
         echo '<div>' . __("Number of Products", "ts_visual_composer_extend") . ': ' . $posts_limit . '</div>';
         $front_edit_reverse = array("excerpt" => __('Excerpt', "ts_visual_composer_extend"), "cutcharacters" => __('Character Limited Content', "ts_visual_composer_extend"), "complete" => __('Full Content', "ts_visual_composer_extend"));
         foreach ($front_edit_reverse as $key => $value) {
             if ($key == $show_content) {
                 echo '<div>' . __("Content Length", "ts_visual_composer_extend") . ': ' . $value . '</div>';
             }
         }
         $front_edit_reverse = array("masonry" => __('Centered Masonry', "ts_visual_composer_extend"), "fitRows" => __('Fit Rows', "ts_visual_composer_extend"), "straightDown" => __('Straight Down', "ts_visual_composer_extend"));
         foreach ($front_edit_reverse as $key => $value) {
             if ($key == $layout) {
                 echo '<div>' . __("Content", "ts_visual_composer_extend") . ': ' . $value . '</div>';
             }
         }
         $front_edit_reverse = array("postName" => __('Product Name', "ts_visual_composer_extend"), "postPrice" => __('Product Price', "ts_visual_composer_extend"), "postRating" => __('Product Rating', "ts_visual_composer_extend"), "postDate" => __('Product Date', "ts_visual_composer_extend"), "postModified" => __('Product Modified', "ts_visual_composer_extend"));
         foreach ($front_edit_reverse as $key => $value) {
             if ($key == $sort_by) {
                 echo '<div>' . __("Sort Criterion", "ts_visual_composer_extend") . ': ' . $value . '</div>';
             }
         }
         $front_edit_reverse = array("asc" => __('Bottom to Top', "ts_visual_composer_extend"), "desc" => __('Top to Bottom', "ts_visual_composer_extend"));
         foreach ($front_edit_reverse as $key => $value) {
             if ($key == $sort_order) {
                 echo '<div>' . __("Initial Order", "ts_visual_composer_extend") . ': ' . $value . '</div>';
             }
         }
         echo '<div>' . __("Show Filter Button", "ts_visual_composer_extend") . ': ' . $filter_menu . '</div>';
         echo '<div>' . __("Show Layout Button", "ts_visual_composer_extend") . ': ' . $layout_menu . '</div>';
         echo '<div>' . __("Show Sort Criterion Button", "ts_visual_composer_extend") . ': ' . $sort_menu . '</div>';
         echo '<div>' . __("Show Directions Buttons", "ts_visual_composer_extend") . ': ' . $directions_menu . '</div>';
         echo '</div>';
     } else {
         $opening .= '<div id="' . $posts_container_id . '" class="ts-isotope-posts-grid-parent ' . ($layout == 'spineTimeline' ? 'ts-timeline ' : 'ts-postsgrid ') . 'ts-timeline-' . $sort_order . ' ts-posts-timeline ' . $isotope_posts_list_class . ' ' . $css_class . '" style="margin-top: ' . $margin_top . 'px; margin-bottom: ' . $margin_bottom . ';" data-lazy="' . $posts_lazy . '" data-count="' . $posts_limit . '" data-ajax="' . $posts_ajax . '" data-trigger="' . $posts_trigger . '" data-column="' . $column_width . '" data-layout="' . $layout . '" data-sort="' . $sort_by . '" data-order="' . $sort_order . '" data-break="' . $layout_break . '" data-type="' . $post_type . '">';
         // Create Individual Post Output
         $postCounter = 0;
         $postCategories = array();
         $categoriesCount = 0;
         if (post_type_exists($post_type) && $loop->have_posts()) {
             $products .= '<div class="ts-timeline-content">';
             $products .= '<ul id="ts-isotope-posts-grid-' . $postsgrid_random . '" class="ts-isotope-posts-grid ts-timeline-list" data-layout="' . $layout . '" data-key="' . $postsgrid_random . '">';
             while ($loop->have_posts()) {
                 $loop->the_post();
                 $postCounter++;
                 $product_id = get_the_ID();
                 $product_title = get_the_title($product_id);
                 $post = get_post($product_id);
                 $product = new WC_Product($product_id);
                 $attachment_ids = $product->get_gallery_attachment_ids();
                 $price = $product->get_price_html();
                 $product_sku = $product->get_sku();
                 $attributes = $product->get_attributes();
                 $stock = $product->is_in_stock() ? 'true' : 'false';
                 $onsale = $product->is_on_sale() ? 'true' : 'false';
                 // Rating Settings
                 $rating_html = $product->get_rating_html();
                 $rating = $product->get_average_rating();
                 if ($rating == '') {
                     $rating = 0;
                 }
                 if ($rating_quarter == "true") {
                     $rating_value = floor($rating * 4) / 4;
                 } else {
                     $rating_value = $rating;
                 }
                 $rating_value = number_format($rating_value, 2, $caption_digits, '');
                 if ($rating_rtl == "false") {
                     $rating_width = $rating_value / $rating_maximum * 100;
                 } else {
                     $rating_width = 100 - $rating_value / $rating_maximum * 100;
                 }
                 if ($rating_symbol == "other") {
                     if ($rating_icon == "ts-ecommerce-starfull1") {
                         $rating_class = 'ts-rating-stars-star1';
                     } else {
                         if ($rating_icon == "ts-ecommerce-starfull2") {
                             $rating_class = 'ts-rating-stars-star2';
                         } else {
                             if ($rating_icon == "ts-ecommerce-starfull3") {
                                 $rating_class = 'ts-rating-stars-star3';
                             } else {
                                 if ($rating_icon == "ts-ecommerce-starfull4") {
                                     $rating_class = 'ts-rating-stars-star4';
                                 } else {
                                     if ($rating_icon == "ts-ecommerce-heartfull") {
                                         $rating_class = 'ts-rating-stars-heart1';
                                     } else {
                                         if ($rating_icon == "ts-ecommerce-heart") {
                                             $rating_class = 'ts-rating-stars-heart2';
                                         } else {
                                             if ($rating_icon == "ts-ecommerce-thumbsup") {
                                                 $rating_class = 'ts-rating-stars-thumb';
                                             } else {
                                                 if ($rating_icon == "ts-ecommerce-ribbon4") {
                                                     $rating_class = 'ts-rating-stars-ribbon';
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 } else {
                     $rating_class = 'ts-rating-stars-smile';
                 }
                 if ($rating_value >= 0 && $rating_value <= 1) {
                     $caption_class = 'ts-label-danger';
                     $caption_background = 'background-color: ' . $caption_danger . ';';
                 } else {
                     if ($rating_value > 1 && $rating_value <= 2) {
                         $caption_class = 'ts-label-warning';
                         $caption_background = 'background-color: ' . $caption_warning . ';';
                     } else {
                         if ($rating_value > 2 && $rating_value <= 3) {
                             $caption_class = 'ts-label-info';
                             $caption_background = 'background-color: ' . $caption_info . ';';
                         } else {
                             if ($rating_value > 3 && $rating_value <= 4) {
                                 $caption_class = 'ts-label-primary';
                                 $caption_background = 'background-color: ' . $caption_primary . ';';
                             } else {
                                 if ($rating_value > 4 && $rating_value <= 5) {
                                     $caption_class = 'ts-label-success';
                                     $caption_background = 'background-color: ' . $caption_success . ';';
                                 }
                             }
                         }
                     }
                 }
                 if (has_post_thumbnail($loop->post->ID)) {
                     $featured = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full');
                     $thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id(), 'thumbnail');
                     $featured = $featured[0];
                     $thumbnail = $thumbnail[0];
                 } else {
                     $featured = woocommerce_placeholder_img_src();
                     $thumbnail = $featured;
                 }
                 $title = get_the_title();
                 // Create Output
                 if ($postCounter < $posts_limit + 1) {
                     $postAttributes = 'data-visible="false" data-price="' . TS_VCSC_CleanNumberData($product->price) . '" data-rating="' . TS_VCSC_CleanNumberData($rating) . '" data-full="' . get_post_time($date_format) . '" data-author="' . get_the_author() . '" data-date="' . get_post_time('U') . '" data-modified="' . get_the_modified_time('U') . '" data-title="' . get_the_title() . '" data-comments="' . get_comments_number() . '" data-id="' . get_the_ID() . '"';
                     if ($exclude_outofstock == "true" && $stock == "true" || $exclude_outofstock == "false") {
                         $product_categories = '';
                         if ($filter_menu == 'true' && taxonomy_exists($menu_tax)) {
                             foreach (get_the_terms($loop->post->ID, $menu_tax) as $term) {
                                 $product_categories .= $term->slug . ' ';
                                 $category_check = 0;
                                 foreach ($postCategories as $index => $array) {
                                     if ($postCategories[$index]['slug'] == $term->slug) {
                                         $category_check++;
                                     }
                                 }
                                 if ($category_check == 0) {
                                     $categoriesCount++;
                                     $categories_array = array('slug' => $term->slug, 'name' => $term->name);
                                     $postCategories[] = $categories_array;
                                 }
                             }
                         }
                         $product_categories .= 'rating-' . TS_VCSC_CleanNumberData($rating) . ' ';
                         $products .= '<li class="ts-timeline-list-item ts-timeline-date-true ts-isotope-posts-list-item ' . $product_categories . '" ' . $postAttributes . ' style="margin: 10px;">';
                         $products .= '<div class="ts-woocommerce-product-slide" style="' . $product_style . '" data-hash="' . $product_id . '">';
                         $products .= '<div id="ts-woocommerce-product-' . $product_id . '" class="ts-image-hover-frame ' . $image_position . ' ts-trigger-hover-adjust" style="width: 100%;">';
                         $products .= '<div id="ts-woocommerce-product-' . $product_id . '-counter" class="ts-fluid-wrapper " style="width: 100%; height: auto;">';
                         $products .= '<div id="ts-woocommerce-product-' . $product_id . '-mask" class="ts-imagehover ' . $hover_type . ' ts-trigger-hover" data-trigger="ts-trigger-hover" data-closer="" style="width: 100%; height: auto;">';
                         // Product Thumbnail
                         $products .= '<div class="ts-woocommerce-product-preview">';
                         $products .= '<img class="ts-woocommerce-product-image" src="' . $featured . '" alt="" />';
                         $products .= '</div>';
                         // Sale Ribbon
                         if ($onsale == "true") {
                             $products .= '<div class="ts-woocommerce-product-ribbon"></div>';
                             $products .= '<i style="" class="ts-woocommerce-product-icon ts-woocommerce-product-sale ts-ecommerce-tagsale"></i>';
                         }
                         $products .= '<div class="ts-woocommerce-product-main">';
                         $products .= '<div class="mask" style="width: 100%; display: block;">';
                         $products .= '<div id="ts-woocommerce-product-' . $product_id . '-maskcontent" class="maskcontent" style="margin: 0; padding: 0;">';
                         // Product Thubmnail
                         if ($show_image == "true") {
                             if ($link_page == "false") {
                                 $products .= '<div class="ts-woocommerce-link-wrapper"><a id="" class="nch-lightbox-media" data-title="' . $title . '" rel="" href="' . $featured . '" target="' . $link_target . '">';
                                 $products .= '<div class="ts-woocommerce-product-thumbnail" style="background-image: url(' . $thumbnail . ');"></div>';
                                 $products .= '</a></div>';
                             } else {
                                 $products .= '<div class="ts-woocommerce-link-wrapper"><a id="" class="" data-title="' . $title . '" rel="" href="' . get_permalink() . '" target="' . $link_target . '">';
                                 $products .= '<div class="ts-woocommerce-product-thumbnail" style="background-image: url(' . $thumbnail . ');"></div>';
                                 $products .= '</a></div>';
                             }
                         }
                         // Product Page Link
                         if ($show_link == "true") {
                             $products .= '<div class="ts-woocommerce-link-wrapper"><a href="' . get_permalink() . '" class="ts-woocommerce-product-link" target="_blank"><i style="" class="ts-woocommerce-product-icon ts-woocommerce-product-view ts-ecommerce-forward"></i></a></div>';
                         }
                         // Product Rating
                         if ($show_rating == "true") {
                             $products .= '<div class="ts-rating-stars-frame" data-auto="' . $rating_auto . '" data-size="' . $rating_size . '" data-width="' . $rating_size * 5 . '" data-rating="' . $rating_value . '" style="margin: 10px 0 0 10px; float: left;">';
                             $products .= '<div class="ts-star-rating' . ($rating_rtl == "false" ? "" : "-rtl") . ' ts-rating-active " style="font-size: ' . $rating_size . 'px; line-height: ' . ($rating_size + 5) . 'px;">';
                             if ($caption_show == "true" && $caption_position == "left") {
                                 $products .= '<div class="ts-rating-caption" style="margin-right: 10px;">';
                                 if ($rating_rtl == "false") {
                                     $products .= '<span class="label ' . $caption_class . '" style="' . $caption_background . '">' . $rating_value . ' / ' . number_format($rating_maximum, 2, $caption_digits, '') . '</span>';
                                 } else {
                                     $products .= '<span class="label ' . $caption_class . '" style="' . $caption_background . '">' . number_format($rating_maximum, 2, $caption_digits, '') . ' / ' . $rating_value . '</span>';
                                 }
                                 $products .= '</div>';
                             }
                             $products .= '<div class="ts-rating-container' . ($rating_rtl == "false" ? "" : "-rtl") . ' ts-rating-glyph-holder ' . $rating_class . '" style="color: ' . ($rating_rtl == "false" ? $color_empty : $color_rated) . ';">';
                             $products .= '<div class="ts-rating-stars ' . $rating_class . '" style="color: ' . ($rating_rtl == "false" ? $color_rated : $color_empty) . '; width: ' . $rating_width . '%;"></div>';
                             $products .= '</div>';
                             if ($caption_show == "true" && $caption_position == "right") {
                                 $products .= '<div class="ts-rating-caption" style="margin-left: 10px;">';
                                 if ($rating_rtl == "false") {
                                     $products .= '<span class="label ' . $caption_class . '" style="' . $caption_background . '">' . $rating_value . ' / ' . number_format($rating_maximum, 2, $caption_digits, '') . '</span>';
                                 } else {
                                     $products .= '<span class="label ' . $caption_class . '" style="' . $caption_background . '">' . number_format($rating_maximum, 2, $caption_digits, '') . ' / ' . $rating_value . '</span>';
                                 }
                                 $products .= '</div>';
                             }
                             $products .= '</div>';
                             $products .= '</div>';
                         }
                         // Product Price
                         if ($show_price == "true") {
                             $products .= '<div class="ts-woocommerce-product-price">';
                             $products .= '<i style="" class="ts-woocommerce-product-icon ts-woocommerce-product-cost ts-ecommerce-pricetag3"></i>';
                             if ($product->price > 0) {
                                 if ($product->price && isset($product->regular_price)) {
                                     $from = $product->regular_price;
                                     $to = $product->price;
                                     if ($from != $to) {
                                         $products .= '<div class="ts-woocommerce-product-regular"><del>' . (is_numeric($from) ? woocommerce_price($from) : $from) . '</del> | </div><div class="ts-woocommerce-product-special">' . (is_numeric($to) ? woocommerce_price($to) : $to) . '</div>';
                                     } else {
                                         $products .= '<div class="ts-woocommerce-product-current">' . (is_numeric($to) ? woocommerce_price($to) : $to) . '</div>';
                                     }
                                 } else {
                                     $to = $product->price;
                                     $products .= '<div class="ts-woocommerce-product-current">' . (is_numeric($to) ? woocommerce_price($to) : $to) . '</div>';
                                 }
                             } else {
                                 $to = $product->price;
                                 $products .= '<div class="ts-woocommerce-product-current">' . (is_numeric($to) ? woocommerce_price($to) : $to) . '</div>';
                             }
                             $products .= '</div>';
                         }
                         $products .= '<div class="ts-woocommerce-product-line"></div>';
                         // Add to Cart Button (Icon)
                         if ($show_cart == "true") {
                             $products .= '<div class="ts-woocommerce-link-wrapper"><a class="ts-woocommerce-product-purchase" href="?add-to-cart=' . $product_id . '" rel="nofollow" data-id="' . $product_id . '" data-sku="' . $product_sku . '"><i style="" class="ts-woocommerce-product-icon ts-woocommerce-product-cart ts-ecommerce-cart4"></i></a></div>';
                         }
                         // View Description Button
                         if ($show_info == "true") {
                             $products .= '<div id="ts-vcsc-modal-' . $product_id . '-trigger" style="" class="ts-vcsc-modal-' . $product_id . '-parent nch-holder ts-vcsc-font-icon ts-font-icons ts-shortcode ts-icon-align-center" style="">';
                             $products .= '<a href="#ts-vcsc-modal-' . $product_id . '" class="nch-lightbox-modal" data-title="" data-open="false" data-delay="0" data-type="html" rel="" data-effect="' . $lightbox_effect . '" data-share="0" data-duration="' . $lightbox_speed . '" data-color="' . $lightbox_backlight_selection . '">';
                             $products .= '<span class="">';
                             $products .= '<i class="ts-font-icon ts-woocommerce-product-icon ts-woocommerce-product-info ts-ecommerce-information1" style=""></i>';
                             $products .= '</span>';
                             $products .= '</a>';
                             $products .= '</div>';
                         }
                         // Product In-Stock or Unavailable
                         if ($show_stock == "true") {
                             $products .= '<div class="ts-woocommerce-product-status">';
                             if ($stock == 'false') {
                                 $products .= '<div class="ts-woocommerce-product-stock"><span class="ts-woocommerce-product-outofstock">' . __('Out of Stock', 'woocommerce') . '</span></div>';
                             } else {
                                 if ($stock == 'true') {
                                     $products .= '<div class="ts-woocommerce-product-stock"><span class="ts-woocommerce-product-instock">' . __('In Stock', 'woocommerce') . '</span></div>';
                                 }
                             }
                             $products .= '</div>';
                         }
                         $products .= '</div>';
                         $products .= '</div>';
                         $products .= '</div>';
                         $products .= '</div>';
                         $products .= '</div>';
                         $products .= '</div>';
                         // Product Title
                         $products .= '<h2 class="ts-woocommerce-product-title">';
                         $products .= $title;
                         $products .= '</h2>';
                         // Product Description
                         if ($show_info == "true") {
                             $products .= '<div id="ts-vcsc-modal-' . $product_id . '" class="ts-modal-content nch-hide-if-javascript" style="' . $description_style . '">';
                             $products .= '<div class="ts-modal-white-header"></div>';
                             $products .= '<div class="ts-modal-white-frame">';
                             $products .= '<div class="ts-modal-white-inner">';
                             $products .= '<h2 style="border-bottom: 1px solid #eeeeee; padding-bottom: 10px; line-height: 32px; font-size: 24px; text-align: left;">' . $title . '</h2>';
                             $products .= '<div class="ts-woocommerce-lightbox-frame" style="width: 100%; height: 32px; margin: 10px auto; padding: 0;">';
                             $products .= '<a style="position: inherit; margin-left: 10px; float: right;" class="ts-woocommerce-product-purchase" href="?add-to-cart=' . $product_id . '" rel="nofollow" data-id="' . $product_id . '" data-sku="' . $product_sku . '"><i style="color: #000000;" class="ts-woocommerce-product-icon ts-woocommerce-product-cart ts-ecommerce-cart4"></i></a>';
                             $products .= '<a href="' . get_permalink() . '" target="_parent" style="position: inherit; margin-left: 10px; float: right;" class="ts-woocommerce-product-link"><i style="color: #000000;" class="ts-woocommerce-product-icon ts-woocommerce-product-view ts-ecommerce-forward"></i></a>';
                             $products .= '<div class="ts-rating-stars-frame" data-auto="' . $rating_auto . '" data-size="' . $rating_size . '" data-width="' . $rating_size * 5 . '" data-rating="' . $rating_value . '" style="margin: 0; float: right;">';
                             $products .= '<div class="ts-star-rating' . ($rating_rtl == "false" ? "" : "-rtl") . ' ts-rating-active " style="font-size: ' . $rating_size . 'px; line-height: ' . ($rating_size + 5) . 'px;">';
                             if ($caption_show == "true" && $caption_position == "left") {
                                 $products .= '<div class="ts-rating-caption" style="margin-right: 10px;">';
                                 if ($rating_rtl == "false") {
                                     $products .= '<span class="label ' . $caption_class . '" style="' . $caption_background . '">' . $rating_value . ' / ' . number_format($rating_maximum, 2, $caption_digits, '') . '</span>';
                                 } else {
                                     $products .= '<span class="label ' . $caption_class . '" style="' . $caption_background . '">' . number_format($rating_maximum, 2, $caption_digits, '') . ' / ' . $rating_value . '</span>';
                                 }
                                 $products .= '</div>';
                             }
                             $products .= '<div class="ts-rating-container' . ($rating_rtl == "false" ? "" : "-rtl") . ' ts-rating-glyph-holder ' . $rating_class . '" style="color: ' . ($rating_rtl == "false" ? $color_empty : $color_rated) . ';">';
                             $products .= '<div class="ts-rating-stars ' . $rating_class . '" style="color: ' . ($rating_rtl == "false" ? $color_rated : $color_empty) . '; width: ' . $rating_width . '%;"></div>';
                             $products .= '</div>';
                             if ($caption_show == "true" && $caption_position == "right") {
                                 $products .= '<div class="ts-rating-caption" style="margin-left: 10px;">';
                                 if ($rating_rtl == "false") {
                                     $products .= '<span class="label ' . $caption_class . '" style="' . $caption_background . '">' . $rating_value . ' / ' . number_format($rating_maximum, 2, $caption_digits, '') . '</span>';
                                 } else {
                                     $products .= '<span class="label ' . $caption_class . '" style="' . $caption_background . '">' . number_format($rating_maximum, 2, $caption_digits, '') . ' / ' . $rating_value . '</span>';
                                 }
                                 $products .= '</div>';
                             }
                             $products .= '</div>';
                             $products .= '</div>';
                             $products .= '<div class="ts-woocommerce-product-price" style="position: inherit; margin-right: 10px; float: left; width: auto; margin-top: 0;">';
                             $products .= '<i style="color: #000000; margin: 0 10px 0 0;" class="ts-woocommerce-product-icon ts-woocommerce-product-cost ts-ecommerce-pricetag3"></i>';
                             if ($product->price > 0) {
                                 if ($product->price && isset($product->regular_price)) {
                                     $from = $product->regular_price;
                                     $to = $product->price;
                                     if ($from != $to) {
                                         $products .= '<div class="ts-woocommerce-product-regular"><del style="color: #7F0000;">' . (is_numeric($from) ? woocommerce_price($from) : $from) . '</del> | </div><div class="ts-woocommerce-product-special">' . (is_numeric($to) ? woocommerce_price($to) : $to) . '</div>';
                                     } else {
                                         $products .= '<div class="ts-woocommerce-product-current">' . (is_numeric($to) ? woocommerce_price($to) : $to) . '</div>';
                                     }
                                 } else {
                                     $to = $product->price;
                                     $products .= '<div class="ts-woocommerce-product-current">' . (is_numeric($to) ? woocommerce_price($to) : $to) . '</div>';
                                 }
                             } else {
                                 $to = $product->price;
                                 $products .= '<div class="ts-woocommerce-product-current">' . (is_numeric($to) ? woocommerce_price($to) : $to) . '</div>';
                             }
                             $products .= '</div>';
                             $products .= '</div>';
                             $products .= '<div class="ts-woocommerce-product-seperator" style="border-bottom: 1px solid #eeeeee; margin: 10px auto 20px auto; width: 100%;"></div>';
                             $products .= '<img style="width: 100%; max-width: 250px; height: auto; margin: 10px auto;" class="ts-woocommerce-product-image" src="' . $featured . '" alt="" />';
                             $products .= '<div class="ts-woocommerce-product-seperator" style="border-bottom: 1px solid #eeeeee; margin: 20px auto 10px auto; width: 100%;"></div>';
                             $products .= '<div style="margin-top: 20px; text-align: justify;">';
                             if ($show_content == "excerpt") {
                                 $products .= get_the_excerpt();
                             } else {
                                 if ($show_content == "cutcharacters") {
                                     $content = apply_filters('the_content', get_the_content());
                                     $excerpt = TS_VCSC_TruncateHTML($content, $cutoff_characters, '...', false, true);
                                     $products .= $excerpt;
                                 } else {
                                     if ($show_content == "complete") {
                                         $products .= get_the_content();
                                     }
                                 }
                             }
                             $products .= '</div>';
                             $products .= '</div>';
                             $products .= '</div>';
                             $products .= '</div>';
                         }
                         $products .= '</div>';
                         $products .= '</li>';
                     }
                 }
             }
             $products .= '</ul>';
             $products .= '</div>';
             if ($posts_lazy == "true") {
                 $products .= '<div class="ts-load-more-wrap">';
                 $products .= '<span class="ts-timeline-load-more">' . $posts_load . '</span>';
                 $products .= '</div>';
             }
             wp_reset_postdata();
         } else {
             $products .= '<p>Nothing found. Please check back soon!</p>';
         }
         // Create Post Controls (Filter, Sort)
         $controls .= '<div id="ts-isotope-posts-grid-controls-' . $postsgrid_random . '" class="ts-isotope-posts-grid-controls">';
         if ($directions_menu == 'true' && $posts_lazy == 'false') {
             $controls .= '<div class="ts-button ts-button-flat ts-timeline-controls-desc ts-isotope-posts-controls-desc ' . ($sort_order == "desc" ? "active" : "") . '"><span class="ts-isotope-posts-controls-desc-image"></span></div>';
             $controls .= '<div class="ts-button ts-button-flat ts-timeline-controls-asc ts-isotope-posts-controls-asc ' . ($sort_order == "asc" ? "active" : "") . '"><span class="ts-isotope-posts-controls-asc-image"></span></div>';
         }
         $controls .= '<div class="ts-isotope-posts-grid-controls-menus">';
         if ($filter_menu == 'true') {
             if ($categoriesCount > 1) {
                 $controls .= '<div id="ts-isotope-posts-filter-trigger-' . $postsgrid_random . '" class="ts-isotope-posts-filter-trigger" data-dropdown="#ts-isotope-posts-filter-' . $postsgrid_random . '" data-horizontal-offset="0" data-vertical-offset="0"><span>' . $TS_VCSC_Isotope_Posts_Language['WooFilterProducts'] . '</span></div>';
                 $controls .= '<div id="ts-isotope-posts-filter-' . $postsgrid_random . '" class="ts-dropdown ts-dropdown-tip ts-dropdown-relative ts-dropdown-anchor-left" style="left: 0px;">';
                 $controls .= '<ul id="" class="ts-dropdown-menu">';
                 $controls .= '<li><label style="font-weight: bold;"><input class="ts-isotope-posts-filter ts-isotope-posts-filter-all" type="checkbox" style="margin-right: 10px;" checked="checked" data-type="all" data-key="' . $postsgrid_random . '" data-filter="*">' . $TS_VCSC_Isotope_Posts_Language['SeeAll'] . '</label></li>';
                 $controls .= '<li class="ts-dropdown-divider"></li>';
                 foreach ($postCategories as $index => $array) {
                     $controls .= '<li><label><input class="ts-isotope-posts-filter ts-isotope-posts-filter-single" type="checkbox" style="margin-right: 10px;" data-type="single" data-key="' . $postsgrid_random . '" data-filter=".' . $postCategories[$index]['slug'] . '">' . $postCategories[$index]['name'] . '</label></li>';
                 }
                 $controls .= '</ul>';
                 $controls .= '</div>';
             }
         }
         if ($layout_menu == 'true') {
             $controls .= '<div id="ts-isotope-posts-layout-trigger-' . $postsgrid_random . '" class="ts-isotope-posts-layout-trigger" data-dropdown="#ts-isotope-posts-layout-' . $postsgrid_random . '" data-horizontal-offset="0" data-vertical-offset="0"><span>' . $TS_VCSC_Isotope_Posts_Language['ButtonLayout'] . '</span></div>';
             $controls .= '<div id="ts-isotope-posts-layout-' . $postsgrid_random . '" class="ts-dropdown ts-dropdown-tip ts-dropdown-relative ts-dropdown-anchor-left" style="left: 0px;">';
             $controls .= '<ul id="" class="ts-dropdown-menu">';
             $controls .= '<li><label><input class="ts-isotope-posts-layout" type="radio" name="radio-group-' . $postsgrid_random . '" data-layout="masonry" style="margin-right: 10px;" ' . ($layout == 'masonry' ? 'checked="checked"' : '') . '>' . $TS_VCSC_Isotope_Posts_Language['Masonry'] . '</label></li>';
             $controls .= '<li><label><input class="ts-isotope-posts-layout" type="radio" name="radio-group-' . $postsgrid_random . '" data-layout="fitRows" style="margin-right: 10px;" ' . ($layout == 'fitRows' ? 'checked="checked"' : '') . '>' . $TS_VCSC_Isotope_Posts_Language['FitRows'] . '</label></li>';
             $controls .= '<li><label><input class="ts-isotope-posts-layout" type="radio" name="radio-group-' . $postsgrid_random . '" data-layout="straightDown" style="margin-right: 10px;" ' . ($layout == 'straightDown' ? 'checked="checked"' : '') . '>' . $TS_VCSC_Isotope_Posts_Language['StraightDown'] . '</label></li>';
             $controls .= '</ul>';
             $controls .= '</div>';
         }
         if ($sort_menu == 'true') {
             $controls .= '<div id="ts-isotope-posts-sort-trigger-' . $postsgrid_random . '" class="ts-isotope-posts-sort-trigger" data-dropdown="#ts-isotope-posts-sort-' . $postsgrid_random . '" data-horizontal-offset="0" data-vertical-offset="0"><span>' . $TS_VCSC_Isotope_Posts_Language['ButtonSort'] . '</span></div>';
             $controls .= '<div id="ts-isotope-posts-sort-' . $postsgrid_random . '" class="ts-dropdown ts-dropdown-tip ts-dropdown-relative ts-dropdown-anchor-left" style="left: 0px;">';
             $controls .= '<ul id="" class="ts-dropdown-menu">';
             $controls .= '<li><label><input class="ts-isotope-posts-sort" type="radio" name="radio-sort-' . $postsgrid_random . '" data-sort="postName" style="margin-right: 10px;" ' . ($sort_by == 'postName' ? 'checked="checked"' : '') . '>' . $TS_VCSC_Isotope_Posts_Language['WooTitle'] . '</label></li>';
             $controls .= '<li><label><input class="ts-isotope-posts-sort" type="radio" name="radio-sort-' . $postsgrid_random . '" data-sort="postPrice" style="margin-right: 10px;" ' . ($sort_by == 'postPrice' ? 'checked="checked"' : '') . '>' . $TS_VCSC_Isotope_Posts_Language['WooPrice'] . '</label></li>';
             $controls .= '<li><label><input class="ts-isotope-posts-sort" type="radio" name="radio-sort-' . $postsgrid_random . '" data-sort="postRatings" style="margin-right: 10px;" ' . ($sort_by == 'postRatings' ? 'checked="checked"' : '') . '>' . $TS_VCSC_Isotope_Posts_Language['WooRating'] . '</label></li>';
             $controls .= '<li><label><input class="ts-isotope-posts-sort" type="radio" name="radio-sort-' . $postsgrid_random . '" data-sort="postDate" style="margin-right: 10px;" ' . ($sort_by == 'postDate' ? 'checked="checked"' : '') . '>' . $TS_VCSC_Isotope_Posts_Language['WooDate'] . '</label></li>';
             $controls .= '<li><label><input class="ts-isotope-posts-sort" type="radio" name="radio-sort-' . $postsgrid_random . '" data-sort="postModified" style="margin-right: 10px;" ' . ($sort_by == 'postModified' ? 'checked="checked"' : '') . '>' . $TS_VCSC_Isotope_Posts_Language['WooModified'] . '</label></li>';
             $controls .= '</ul>';
             $controls .= '</div>';
         }
         $controls .= '</div>';
         $controls .= '<div class="clearFixMe" style="clear:both;"></div>';
         $controls .= '</div>';
         $closing .= '</div>';
         echo $opening;
         echo $controls;
         echo $products;
         echo $closing;
     }
     $myvariable = ob_get_clean();
     return $myvariable;
 }
        function TS_VCSC_WooCommerce_Ticker_Basic_Function($atts, $content = null)
        {
            global $VISUAL_COMPOSER_EXTENSIONS;
            global $product;
            global $woocommerce;
            ob_start();
            wp_enqueue_script('ts-extend-newsticker');
            wp_enqueue_style('ts-font-ecommerce');
            wp_enqueue_style('ts-font-teammatess');
            if ($VISUAL_COMPOSER_EXTENSIONS->TS_VCSC_LoadFrontEndForcable == "false") {
                wp_enqueue_style('ts-extend-animations');
                wp_enqueue_style('ts-visual-composer-extend-front');
                wp_enqueue_script('ts-visual-composer-extend-front');
            }
            extract(shortcode_atts(array('selection' => 'recent_products', 'category' => '', 'ids' => '', 'orderby' => 'date', 'order' => 'desc', 'products_total' => 12, 'exclude_outofstock' => 'false', 'post_type' => 'product', 'date_format' => 'F j, Y', 'time_format' => 'l, g:i A', 'limit_posts' => 'true', 'limit_by' => 'category', 'limit_term' => '', 'filter_menu' => 'true', 'layout_menu' => 'true', 'sort_menu' => 'false', 'directions_menu' => 'false', 'filter_by' => 'category', 'ticker_direction' => 'up', 'ticker_speed' => 3000, 'ticker_break' => 480, 'ticker_border_type' => '', 'ticker_border_thick' => 1, 'ticker_border_color' => '#ededed', 'ticker_border_radius' => '', 'ticker_auto' => 'false', 'ticker_hover' => 'true', 'ticker_controls' => 'true', 'ticker_symbol' => 'false', 'ticker_icon' => '', 'ticker_paint' => '#ffffff', 'ticker_title' => 'true', 'ticker_header' => 'Latest Products', 'ticker_background' => '#D10000', 'ticker_color' => '#ffffff', 'ticker_type' => 'true', 'ticker_image' => 'true', 'ticker_price' => 'true', 'ticker_cart' => 'true', 'ticker_add_item' => 'Add This Item', 'ticker_remove_item' => 'Remove This Item', 'ticker_rating' => 'true', 'ticker_stock' => 'false', 'ticker_side' => 'left', 'ticker_fixed' => 'false', 'ticker_position' => 'top', 'ticker_adjustment' => 0, 'ticker_target' => '_parent', 'posts_limit' => 25, 'rating_maximum' => 5, 'rating_size' => 20, 'rating_quarter' => 'true', 'rating_name' => 'true', 'rating_auto' => 'true', 'rating_position' => 'top', 'rating_rtl' => 'false', 'rating_symbol' => 'other', 'rating_icon' => 'ts-ecommerce-starfull1', 'color_rated' => '#FFD800', 'color_empty' => '#e3e3e3', 'caption_show' => 'true', 'caption_position' => 'left', 'caption_digits' => '.', 'caption_danger' => '#d9534f', 'caption_warning' => '#f0ad4e', 'caption_info' => '#5bc0de', 'caption_primary' => '#428bca', 'caption_success' => '#5cb85c', 'margin_top' => 0, 'margin_bottom' => 0, 'el_id' => '', 'el_class' => '', 'css' => ''), $atts));
            $woo_random = mt_rand(999999, 9999999);
            if (!empty($el_id)) {
                $woo_ticker_id = $el_id;
            } else {
                $woo_ticker_id = 'ts-vcsc-woocommerce-ticker-' . $woo_random;
            }
            $output = '';
            // Check for Front End Editor
            if ($VISUAL_COMPOSER_EXTENSIONS->TS_VCSC_VCFrontEditMode == "true") {
                $frontend_edit = 'true';
                $ticker_fixed = 'false';
                $ticker_auto = 'false';
            } else {
                $frontend_edit = 'false';
                $ticker_fixed = $ticker_fixed;
                $ticker_auto = $ticker_auto;
            }
            $meta_query = '';
            // Recent Products
            if ($selection == "recent_products") {
                $meta_query = WC()->query->get_meta_query();
            }
            // Featured Products
            if ($selection == "featured_products") {
                $meta_query = array(array('key' => '_visibility', 'value' => array('catalog', 'visible'), 'compare' => 'IN'), array('key' => '_featured', 'value' => 'yes'));
            }
            // Top Rated Products
            if ($selection == "top_rated_products") {
                add_filter('posts_clauses', array(WC()->query, 'order_by_rating_post_clauses'));
                $meta_query = WC()->query->get_meta_query();
            }
            // Final Query Arguments
            $args = array('post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'posts_per_page' => $products_total, 'orderby' => $orderby, 'order' => $order, 'paged' => 1, 'meta_query' => $meta_query);
            // Products on Sale
            if ($selection == "sale_products") {
                $product_ids_on_sale = woocommerce_get_product_ids_on_sale();
                $meta_query = array();
                $meta_query[] = $woocommerce->query->visibility_meta_query();
                $meta_query[] = $woocommerce->query->stock_status_meta_query();
                $args['meta_query'] = $meta_query;
                $args['post__in'] = $product_ids_on_sale;
            }
            // Best Selling Products
            if ($selection == "best_selling_products") {
                $args['meta_key'] = 'total_sales';
                $args['orderby'] = 'meta_value_num';
                $args['meta_query'] = array(array('key' => '_visibility', 'value' => array('catalog', 'visible'), 'compare' => 'IN'));
            }
            // Products in Single Category
            if ($selection == "product_category") {
                $args['tax_query'] = array(array('taxonomy' => 'product_cat', 'terms' => array(esc_attr($category)), 'field' => 'slug', 'operator' => 'IN'));
            }
            // Products in Multiple Categories
            if ($selection == "product_categories") {
                $args['tax_query'] = array(array('taxonomy' => 'product_cat', 'terms' => explode(",", $ids), 'field' => 'term_id', 'operator' => 'IN'));
            }
            // Start WordPress Query
            $loop = new WP_Query($args);
            if ($ticker_fixed == "true") {
                $newsticker_class = 'ts-newsticker-fixed';
                $newsticker_position = 'ts-newsticker-' . $ticker_position;
                if ($ticker_position == "top") {
                    $newsticker_style = 'top: ' . $ticker_adjustment . 'px;';
                } else {
                    $newsticker_style = 'bottom: ' . $ticker_adjustment . 'px;';
                }
                $margin_top = 0;
                $margin_bottom = 0;
            } else {
                $newsticker_class = 'ts-newsticker-standard';
                $newsticker_position = '';
                $newsticker_style = '';
            }
            if ($ticker_border_type != '') {
                $newsticker_border = 'border: ' . $ticker_border_thick . 'px ' . $ticker_border_type . ' ' . $ticker_border_color . ';';
            } else {
                $newsticker_border = '';
            }
            if ($ticker_side == "left") {
                $newsticker_elements = 'ts-newsticker-elements-left';
            } else {
                $newsticker_elements = 'ts-newsticker-elements-right';
            }
            if ($ticker_title == "false") {
                $newsticker_header = 'left: 0;';
                $newsticker_controls = 'right: 10px;';
            } else {
                $newsticker_header = '';
                $newsticker_controls = '';
            }
            if (function_exists('vc_shortcode_custom_css_class')) {
                $css_class = apply_filters(VC_SHORTCODE_CUSTOM_CSS_FILTER_TAG, $el_class . ' ' . vc_shortcode_custom_css_class($css, ' '), 'TS_VCSC_WooCommerce_Ticker_Basic', $atts);
            } else {
                $css_class = $slider_class . ' ' . $el_class;
            }
            $output .= '<div id="' . $woo_ticker_id . '" class="ts-newsticker-parent ' . $css_class . '" style="margin-top: ' . $margin_top . 'px; margin-bottom: ' . $margin_bottom . ';">';
            // Create Individual Post Output
            $postCounter = 0;
            $postMonths = array();
            if ($loop->have_posts()) {
                $output .= '<div id="ts-newsticker-oneliner-' . $woo_random . '"
						class="ts-newsticker-oneliner ' . $newsticker_class . ' ' . $newsticker_position . ' ' . $ticker_border_radius . '"
						style="' . $newsticker_style . ' ' . $newsticker_border . '"
						data-ticker="ts-newsticker-ticker-' . $woo_random . '"
						data-controls="ts-newsticker-controls-' . $woo_random . '"
						data-navigation="' . $ticker_controls . '"
						data-break="' . $ticker_break . '"
						data-auto="' . $ticker_auto . '"
						data-speed="' . $ticker_speed . '"
						data-hover="' . $ticker_hover . '"
						data-direction="' . $ticker_direction . '"
						data-parent="' . $woo_ticker_id . '"
						data-side="' . $ticker_side . '"
						data-header="ts-newsticker-header-' . $woo_random . '"
						data-next="ts-newsticker-controls-next-' . $woo_random . '"
						data-prev="ts-newsticker-controls-prev-' . $woo_random . '"
						data-play="ts-newsticker-controls-play-' . $woo_random . '"
						data-stop="ts-newsticker-controls-stop-' . $woo_random . '">';
                $output .= '<div class="ts-newsticker-elements-frame ' . $newsticker_elements . ' ' . $ticker_border_radius . '" style="">';
                // Add Navigation Controls
                $output .= '<div id="ts-newsticker-controls-' . $woo_random . '" class="ts-newsticker-controls" style="' . ($ticker_controls == "true" ? "display: block;" : "display: none;") . ' ' . $newsticker_controls . '">';
                $output .= '<div id="ts-newsticker-controls-next-' . $woo_random . '" style="' . ($ticker_controls == "true" ? "display: block;" : "display: none;") . '" class="ts-newsticker-controls-next"><span class="ts-ecommerce-arrowright5"></span></div>';
                $output .= '<div id="ts-newsticker-controls-prev-' . $woo_random . '" style="' . ($ticker_controls == "true" ? "display: block;" : "display: none;") . '" class="ts-newsticker-controls-prev"><span class="ts-ecommerce-arrowleft5"></span></div>';
                $output .= '<div id="ts-newsticker-controls-stop-' . $woo_random . '" class="ts-newsticker-controls-play" style="' . ($ticker_auto == "true" ? "display: block;" : "display: none;") . '"><span class="ts-ecommerce-pause"></span></div>';
                $output .= '<div id="ts-newsticker-controls-play-' . $woo_random . '" class="ts-newsticker-controls-play" style="' . ($ticker_auto == "true" ? "display: none;" : "display: block;") . '"><span class="ts-ecommerce-play"></span></div>';
                $output .= '</div>';
                if ($ticker_side == "left" && $ticker_title == "true") {
                    $output .= '<div id="ts-newsticker-header-' . $woo_random . '" class="header ' . $ticker_border_radius . '" style="background: ' . $ticker_background . '; color: ' . $ticker_color . '; left: 0;">';
                    if ($ticker_icon != '' && $ticker_icon != 'transparent' && $ticker_symbol == "true") {
                        $output .= '<i class="ts-font-icon ' . $ticker_icon . '" style="color: ' . $ticker_paint . '"></i>';
                    }
                    $output .= '<span>' . $ticker_header . '</span>';
                    $output .= '</div>';
                }
                $output .= '<ul id="ts-newsticker-ticker-' . $woo_random . '" class="newsticker ' . $ticker_border_radius . '" style="' . $newsticker_header . '">';
                while ($loop->have_posts()) {
                    $loop->the_post();
                    $postCounter++;
                    if ($postCounter < $posts_limit + 1) {
                        $postAttributes = 'data-full="' . get_post_time($date_format) . '" data-time="' . get_post_time($time_format) . '" data-author="' . get_the_author() . '" data-date="' . get_post_time('U') . '" data-modified="' . get_the_modified_time('U') . '" data-title="' . get_the_title() . '" data-comments="' . get_comments_number() . '" data-id="' . get_the_ID() . '"';
                        $product_id = get_the_ID();
                        $product_title = get_the_title($product_id);
                        $post = get_post($product_id);
                        $product = new WC_Product($product_id);
                        $attachment_ids = $product->get_gallery_attachment_ids();
                        $price = $product->get_price_html();
                        $product_sku = $product->get_sku();
                        $attributes = $product->get_attributes();
                        $stock = $product->is_in_stock() ? 'true' : 'false';
                        $onsale = $product->is_on_sale() ? 'true' : 'false';
                        // Rating Settings
                        $rating_html = $product->get_rating_html();
                        $rating = $product->get_average_rating();
                        if ($rating == '') {
                            $rating = 0;
                        }
                        if ($rating_quarter == "true") {
                            $rating_value = floor($rating * 4) / 4;
                        } else {
                            $rating_value = $rating;
                        }
                        $rating_value = number_format($rating_value, 2, $caption_digits, '');
                        if ($rating_rtl == "false") {
                            $rating_width = $rating_value / $rating_maximum * 100;
                        } else {
                            $rating_width = 100 - $rating_value / $rating_maximum * 100;
                        }
                        if ($rating_symbol == "other") {
                            if ($rating_icon == "ts-ecommerce-starfull1") {
                                $rating_class = 'ts-rating-stars-star1';
                            } else {
                                if ($rating_icon == "ts-ecommerce-starfull2") {
                                    $rating_class = 'ts-rating-stars-star2';
                                } else {
                                    if ($rating_icon == "ts-ecommerce-starfull3") {
                                        $rating_class = 'ts-rating-stars-star3';
                                    } else {
                                        if ($rating_icon == "ts-ecommerce-starfull4") {
                                            $rating_class = 'ts-rating-stars-star4';
                                        } else {
                                            if ($rating_icon == "ts-ecommerce-heartfull") {
                                                $rating_class = 'ts-rating-stars-heart1';
                                            } else {
                                                if ($rating_icon == "ts-ecommerce-heart") {
                                                    $rating_class = 'ts-rating-stars-heart2';
                                                } else {
                                                    if ($rating_icon == "ts-ecommerce-thumbsup") {
                                                        $rating_class = 'ts-rating-stars-thumb';
                                                    } else {
                                                        if ($rating_icon == "ts-ecommerce-ribbon4") {
                                                            $rating_class = 'ts-rating-stars-ribbon';
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        } else {
                            $rating_class = 'ts-rating-stars-smile';
                        }
                        if ($rating_value >= 0 && $rating_value <= 1) {
                            $caption_class = 'ts-label-danger';
                            $caption_background = 'background-color: ' . $caption_danger . ';';
                        } else {
                            if ($rating_value > 1 && $rating_value <= 2) {
                                $caption_class = 'ts-label-warning';
                                $caption_background = 'background-color: ' . $caption_warning . ';';
                            } else {
                                if ($rating_value > 2 && $rating_value <= 3) {
                                    $caption_class = 'ts-label-info';
                                    $caption_background = 'background-color: ' . $caption_info . ';';
                                } else {
                                    if ($rating_value > 3 && $rating_value <= 4) {
                                        $caption_class = 'ts-label-primary';
                                        $caption_background = 'background-color: ' . $caption_primary . ';';
                                    } else {
                                        if ($rating_value > 4 && $rating_value <= 5) {
                                            $caption_class = 'ts-label-success';
                                            $caption_background = 'background-color: ' . $caption_success . ';';
                                        }
                                    }
                                }
                            }
                        }
                        // Check if Product already in Cart
                        $cart_page_id = wc_get_page_id('cart');
                        $already_added = "false";
                        foreach ($woocommerce->cart->get_cart() as $cart_item_key => $cart_item) {
                            if ($product_id == $cart_item['product_id']) {
                                $already_added = "true";
                                $cart_link = apply_filters('woocommerce_cart_item_remove_link', sprintf('<a class="ts-newsticker-product-remove" href="%s" title="%s" rel="" data-id="' . $product_id . '" data-sku="' . $product_sku . '"><i style="" class="ts-newsticker-product-cart ts-woocommerce-product-cart ts-ecommerce-cross2"></i></a>', esc_url($woocommerce->cart->get_remove_url($cart_item_key)), $ticker_remove_item), $cart_item_key);
                            }
                        }
                        if ($already_added == "false") {
                            $cart_link = '<span class="ts-woocommerce-link-wrapper"><a class="ts-newsticker-product-purchase" href="?add-to-cart=' . $product_id . '" title="' . $ticker_add_item . '" rel="" data-id="' . $product_id . '" data-sku="' . $product_sku . '"><i style="" class="ts-newsticker-product-cart ts-woocommerce-product-cart ts-ecommerce-cart4"></i></a></span>';
                        }
                        $output .= '<li ' . $postAttributes . '>';
                        if ($ticker_image == 'true') {
                            if ('' != get_the_post_thumbnail()) {
                                $thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id(), 'thumbnail');
                                $output .= '<img class="ts-newsticker-image" src="' . $thumbnail[0] . '" style="">';
                            }
                        }
                        $output .= '<span class="ts-woocommerce-link-wrapper"><a href="' . get_permalink() . '" target="' . $ticker_target . '">';
                        $output .= get_the_title();
                        $output .= '</a></span>';
                        // Product Price
                        if ($ticker_price == "true") {
                            $output .= '<span class="ts-newsticker-pricetag" style="">';
                            if ($product->price > 0) {
                                if ($product->price && isset($product->regular_price)) {
                                    $from = $product->regular_price;
                                    $to = $product->price;
                                    if ($from != $to) {
                                        $output .= '<span class="ts-newsticker-product-regular" style="float: none;"><del>' . (is_numeric($from) ? woocommerce_price($from) : $from) . '</del> | </span><span class="ts-newsticker-product-special" style="float: none;">' . (is_numeric($to) ? woocommerce_price($to) : $to) . '</span>';
                                    } else {
                                        $output .= '<span class="ts-newsticker-product-current" style="float: none;">' . (is_numeric($to) ? woocommerce_price($to) : $to) . '</span>';
                                    }
                                } else {
                                    $to = $product->price;
                                    $output .= '<span class="ts-newsticker-product-current" style="float: none;">' . (is_numeric($to) ? woocommerce_price($to) : $to) . '</span>';
                                }
                            } else {
                                $to = $product->price;
                                $output .= '<span class="ts-newsticker-product-current" style="float: none;">' . (is_numeric($to) ? woocommerce_price($to) : $to) . '</span>';
                            }
                            $output .= '</span>';
                        }
                        // Sale Ribbon
                        if ($onsale == "true") {
                            $output .= '<i style="position: inherit" class="ts-newsticker-product-sale ts-woocommerce-product-sale ts-ecommerce-tagsale"></i>';
                        }
                        // Product Rating
                        if ($ticker_rating == "true") {
                            $output .= '<span class="ts-rating-stars-frame" data-auto="false" data-size="' . $rating_size . '" data-width="' . $rating_size * 5 . '" data-rating="' . $rating_value . '" style="margin: 10px 0 0 10px; float: none;">';
                            $output .= '<span class="ts-star-rating' . ($rating_rtl == "false" ? "" : "-rtl") . ' ts-rating-active " style="font-size: ' . $rating_size . 'px; line-height: ' . ($rating_size + 5) . 'px;">';
                            if ($caption_show == "true" && $caption_position == "left") {
                                $output .= '<span class="ts-rating-caption" style="margin-right: 10px;">';
                                if ($rating_rtl == "false") {
                                    $output .= '<span class="label ' . $caption_class . '" style="' . $caption_background . '">' . $rating_value . ' / ' . number_format($rating_maximum, 2, $caption_digits, '') . '</span>';
                                } else {
                                    $output .= '<span class="label ' . $caption_class . '" style="' . $caption_background . '">' . number_format($rating_maximum, 2, $caption_digits, '') . ' / ' . $rating_value . '</span>';
                                }
                                $output .= '</span>';
                            }
                            $output .= '<span class="ts-rating-container' . ($rating_rtl == "false" ? "" : "-rtl") . ' ts-rating-glyph-holder ' . $rating_class . '" style="color: ' . ($rating_rtl == "false" ? $color_empty : $color_rated) . ';">';
                            $output .= '<span class="ts-rating-stars ' . $rating_class . '" style="color: ' . ($rating_rtl == "false" ? $color_rated : $color_empty) . '; width: ' . $rating_width . '%;"></span>';
                            $output .= '</span>';
                            if ($caption_show == "true" && $caption_position == "right") {
                                $output .= '<span class="ts-rating-caption" style="margin-left: 10px;">';
                                if ($rating_rtl == "false") {
                                    $output .= '<span class="label ' . $caption_class . '" style="' . $caption_background . '">' . $rating_value . ' / ' . number_format($rating_maximum, 2, $caption_digits, '') . '</span>';
                                } else {
                                    $output .= '<span class="label ' . $caption_class . '" style="' . $caption_background . '">' . number_format($rating_maximum, 2, $caption_digits, '') . ' / ' . $rating_value . '</span>';
                                }
                                $output .= '</span>';
                            }
                            $output .= '</span>';
                            $output .= '</span>';
                        }
                        // Add to Cart Icon
                        if ($ticker_cart == "true") {
                            //$output .= '<a class="ts-newsticker-product-purchase" href="?add-to-cart=' . $product_id . '" rel="nofollow" data-id="' . $product_id . '" data-sku="' . $product_sku . '"><i style="" class="ts-newsticker-product-cart ts-woocommerce-product-cart ts-ecommerce-cart4"></i></a>';
                            $output .= $cart_link;
                        }
                        // Product In-Stock or Unavailable
                        if ($ticker_stock == "true") {
                            $output .= '<span class="ts-woocommerce-product-status" style="margin-left: 10px;">';
                            if ($stock == 'false') {
                                $output .= '<span class="ts-woocommerce-product-stock" style="position: inherit;"><span class="ts-woocommerce-product-outofstock">' . __('Out of Stock', 'woocommerce') . '</span></span>';
                            } else {
                                if ($stock == 'true') {
                                    $output .= '<span class="ts-woocommerce-product-stock" style="position: inherit;"><span class="ts-woocommerce-product-instock">' . __('In Stock', 'woocommerce') . '</span></span>';
                                }
                            }
                            $output .= '</span>';
                        }
                        $output .= '</li>';
                    }
                }
                $output .= '</ul>';
                if ($ticker_side == "right" && $ticker_title == "true") {
                    $output .= '<div id="ts-newsticker-header-' . $woo_random . '" class="header ' . $ticker_border_radius . '" style="background: ' . $ticker_background . '; color: ' . $ticker_color . '; right: 0;">';
                    if ($ticker_icon != '' && $ticker_icon != 'transparent' && $ticker_symbol == "true") {
                        $output .= '<i class="ts-font-icon ' . $ticker_icon . '" style="color: ' . $ticker_paint . '"></i>';
                    }
                    $output .= '<span>' . $ticker_header . '</span>';
                    $output .= '</div>';
                }
                $output .= '</div>';
                $output .= '</div>';
            } else {
                echo __("No products could be found.", "ts_visual_composer_extend");
            }
            $output .= '</div>';
            wp_reset_postdata();
            wp_reset_query();
            echo $output;
            $myvariable = ob_get_clean();
            return $myvariable;
        }
 /**
  * Add a product line item to the order. This is the only line item type with
  * it's own method because it saves looking up order amounts (costs are added up for you).
  * @param  \WC_Product $product
  * @param  int $qty
  * @param  array $args
  * @return int order item ID
  * @throws WC_Data_Exception
  */
 public function add_product($product, $qty = 1, $args = array())
 {
     if ($product) {
         $default_args = array('name' => $product->get_name(), 'tax_class' => $product->get_tax_class(), 'product_id' => $product->is_type('variation') ? $product->get_parent_id() : $product->get_id(), 'variation_id' => $product->is_type('variation') ? $product->get_id() : 0, 'variation' => $product->is_type('variation') ? $product->get_attributes() : array(), 'subtotal' => wc_get_price_excluding_tax($product, array('qty' => $qty)), 'total' => wc_get_price_excluding_tax($product, array('qty' => $qty)), 'quantity' => $qty);
     } else {
         $default_args = array('quantity' => $qty);
     }
     $args = wp_parse_args($args, $default_args);
     // BW compatibility with old args
     if (isset($args['totals'])) {
         foreach ($args['totals'] as $key => $value) {
             if ('tax' === $key) {
                 $args['total_tax'] = $value;
             } elseif ('tax_data' === $key) {
                 $args['taxes'] = $value;
             } else {
                 $args[$key] = $value;
             }
         }
     }
     $item = new WC_Order_Item_Product();
     $item->set_props($args);
     $item->set_backorder_meta();
     $item->set_order_id($this->get_id());
     $item->save();
     $this->add_item($item);
     wc_do_deprecated_action('woocommerce_order_add_product', array($this->get_id(), $item->get_id(), $product, $qty, $args), '2.7', 'Use woocommerce_new_order_item action instead.');
     return $item->get_id();
 }
Example #12
0
 /**
  * Returns modified tour attributes where each element contains information about attribute label,
  * value and icon class.
  *
  * @param  WC_Product  $product               product for that attributes should be retrived.
  * @param  boolean     $onlyAllowedInSettings if attributes should be filtered with values allowed in theme options.
  * @return array
  */
 public static function get_tour_details_attributes($product, $onlyAllowedInSettings = true)
 {
     $result = array();
     $list = $product->get_attributes();
     $allowedList = adventure_tours_get_option('tours_page_top_attributes');
     if (!$list || $onlyAllowedInSettings && !$allowedList) {
         return $result;
     }
     foreach ($list as $name => $attribute) {
         $attrib_name = $attribute['name'];
         if (empty($attribute['is_visible']) || $attribute['is_taxonomy'] && !taxonomy_exists($attrib_name)) {
             continue;
         }
         if (false === $onlyAllowedInSettings && in_array($attrib_name, $allowedList)) {
             continue;
         }
         if ($attribute['is_taxonomy']) {
             $values = wc_get_product_terms($product->id, $attrib_name, array('fields' => 'names'));
             $text = apply_filters('woocommerce_attribute', wptexturize(implode(', ', $values)), $attribute, $values);
         } else {
             // Convert pipes to commas and display values
             $values = array_map('trim', explode(WC_DELIMITER, $attribute['value']));
             $text = apply_filters('woocommerce_attribute', wptexturize(implode(', ', $values)), $attribute, $values);
         }
         $result[$attrib_name] = array('name' => $attrib_name, 'label' => wc_attribute_label($attrib_name), 'values' => $values, 'text' => $text, 'icon_class' => self::get_product_attribute_icon_class($attribute));
     }
     // We need reorder items according order in settings.
     if ($onlyAllowedInSettings && $result) {
         $orderedList = array();
         foreach ($allowedList as $attribKey) {
             if (!empty($result[$attribKey])) {
                 $orderedList[$attribKey] = $result[$attribKey];
             }
         }
         return $orderedList;
     }
     return $result;
 }
 function TS_VCSC_WooCommerce_Rating_Basic_Function($atts, $content = null)
 {
     global $VISUAL_COMPOSER_EXTENSIONS;
     global $product;
     global $woocommerce;
     ob_start();
     if ($VISUAL_COMPOSER_EXTENSIONS->TS_VCSC_LoadFrontEndForcable == "false") {
         wp_enqueue_style('ts-extend-simptip');
         wp_enqueue_style('ts-font-ecommerce');
         wp_enqueue_style('ts-visual-composer-extend-front');
         wp_enqueue_script('ts-visual-composer-extend-front');
     }
     extract(shortcode_atts(array('best_rated' => 'false', 'id' => '', 'rating_maximum' => 5, 'rating_size' => 24, 'rating_quarter' => 'true', 'rating_title' => 'true', 'rating_auto' => 'true', 'rating_position' => 'top', 'rating_rtl' => 'false', 'rating_symbol' => 'other', 'rating_icon' => '', 'color_rated' => '#FFD800', 'color_empty' => '#e3e3e3', 'caption_show' => 'true', 'caption_position' => 'left', 'caption_digits' => '.', 'caption_danger' => '#d9534f', 'caption_warning' => '#f0ad4e', 'caption_info' => '#5bc0de', 'caption_primary' => '#428bca', 'caption_success' => '#5cb85c', 'title_size' => 24, 'title_truncate' => 'true', 'use_name' => 'true', 'custom_title' => '', 'show_cart' => 'true', 'cart_color' => '#cccccc', 'show_link' => 'true', 'link_color' => '#cccccc', 'tooltip_css' => 'false', 'tooltip_content' => '', 'tooltip_position' => 'ts-simptip-position-top', 'tooltip_style' => '', 'margin_top' => 20, 'margin_bottom' => 20, 'el_id' => '', 'el_class' => '', 'css' => ''), $atts));
     // Final Query Arguments
     add_filter('posts_clauses', array(WC()->query, 'order_by_rating_post_clauses'));
     $meta_query = WC()->query->get_meta_query();
     $args = array('post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'posts_per_page' => -1, 'orderby' => 'date', 'order' => 'desc', 'paged' => 1, 'meta_query' => $meta_query);
     $loop = new WP_Query($args);
     if ($loop->have_posts()) {
         $best_rating = 0;
         while ($loop->have_posts()) {
             $loop->the_post();
             $product_id = get_the_ID();
             $product = new WC_Product($product_id);
             if ($product_id == $id) {
                 $product_title = get_the_title($product_id);
                 $post = get_post($product_id);
                 $product = new WC_Product($product_id);
                 $attachment_ids = $product->get_gallery_attachment_ids();
                 $price = $product->get_price_html();
                 $product_sku = $product->get_sku();
                 $attributes = $product->get_attributes();
                 $stock = $product->is_in_stock() ? 'true' : 'false';
                 $onsale = $product->is_on_sale() ? 'true' : 'false';
                 $link = get_permalink();
                 // Rating Settings
                 $rating_html = $product->get_rating_html();
                 $rating = $product->get_average_rating();
                 if ($rating == '') {
                     $rating = 0;
                 }
                 if ($rating_quarter == "true") {
                     $rating_value = floor($rating * 4) / 4;
                 } else {
                     $rating_value = $rating;
                 }
                 $rating_value = number_format($rating_value, 2, $caption_digits, '');
                 break;
             }
         }
     }
     wp_reset_postdata();
     wp_reset_query();
     if ($rating_title == "true") {
         if ($use_name == "true") {
             $rating_title = $product_title;
         } else {
             $rating_title = $custom_title;
         }
     } else {
         $rating_title = '';
     }
     if ($rating_rtl == "false") {
         $rating_width = $rating_value / $rating_maximum * 100;
     } else {
         $rating_width = 100 - $rating_value / $rating_maximum * 100;
     }
     if ($rating_symbol == "other") {
         if ($rating_icon == "ts-ecommerce-starfull1") {
             $rating_class = 'ts-rating-stars-star1';
         } else {
             if ($rating_icon == "ts-ecommerce-starfull2") {
                 $rating_class = 'ts-rating-stars-star2';
             } else {
                 if ($rating_icon == "ts-ecommerce-starfull3") {
                     $rating_class = 'ts-rating-stars-star3';
                 } else {
                     if ($rating_icon == "ts-ecommerce-starfull4") {
                         $rating_class = 'ts-rating-stars-star4';
                     } else {
                         if ($rating_icon == "ts-ecommerce-heartfull") {
                             $rating_class = 'ts-rating-stars-heart1';
                         } else {
                             if ($rating_icon == "ts-ecommerce-heart") {
                                 $rating_class = 'ts-rating-stars-heart2';
                             } else {
                                 if ($rating_icon == "ts-ecommerce-thumbsup") {
                                     $rating_class = 'ts-rating-stars-thumb';
                                 } else {
                                     if ($rating_icon == "ts-ecommerce-ribbon4") {
                                         $rating_class = 'ts-rating-stars-ribbon';
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     } else {
         $rating_class = 'ts-rating-stars-smile';
     }
     if ($rating_value >= 0 && $rating_value <= 1) {
         $caption_class = 'ts-label-danger';
         $caption_background = 'background-color: ' . $caption_danger . ';';
     } else {
         if ($rating_value > 1 && $rating_value <= 2) {
             $caption_class = 'ts-label-warning';
             $caption_background = 'background-color: ' . $caption_warning . ';';
         } else {
             if ($rating_value > 2 && $rating_value <= 3) {
                 $caption_class = 'ts-label-info';
                 $caption_background = 'background-color: ' . $caption_info . ';';
             } else {
                 if ($rating_value > 3 && $rating_value <= 4) {
                     $caption_class = 'ts-label-primary';
                     $caption_background = 'background-color: ' . $caption_primary . ';';
                 } else {
                     if ($rating_value > 4 && $rating_value <= 5) {
                         $caption_class = 'ts-label-success';
                         $caption_background = 'background-color: ' . $caption_success . ';';
                     }
                 }
             }
         }
     }
     // Line Height Adjustment
     if ($show_cart == "true" || $show_link == "true") {
         if ($title_size > 24) {
             $line_height = $title_size;
         } else {
             $line_height = 24;
         }
     } else {
         $line_height = $title_size;
     }
     // Tooltip
     if ($tooltip_css == "true") {
         if (strlen($tooltip_content) != 0) {
             $rating_tooltipclasses = " ts-simptip-multiline " . $tooltip_style . " " . $tooltip_position;
             $rating_tooltipcontent = ' data-tstooltip="' . $tooltip_content . '"';
         } else {
             $rating_tooltipclasses = "";
             $rating_tooltipcontent = "";
         }
     } else {
         $rating_tooltipclasses = "";
         if (strlen($tooltip_content) != 0) {
             $rating_tooltipcontent = ' title="' . $tooltip_content . '"';
         } else {
             $rating_tooltipcontent = "";
         }
     }
     if (function_exists('vc_shortcode_custom_css_class')) {
         $css_class = apply_filters(VC_SHORTCODE_CUSTOM_CSS_FILTER_TAG, ' ' . vc_shortcode_custom_css_class($css, ' '), 'TS_VCSC_WooCommerce_Rating_Basic', $atts);
     } else {
         $css_class = '';
     }
     $output = '';
     $output .= '<div class="ts-rating-stars-frame ' . $el_class . ' ' . $css_class . '" data-auto="' . $rating_auto . '" data-size="' . $rating_size . '" data-width="' . $rating_size * 5 . '" data-rating="' . $rating_value . '" style="margin-top: ' . $margin_top . 'px; margin-bottom: ' . $margin_bottom . 'px;">';
     if ($rating_position == 'top' && $rating_title != '') {
         $output .= '<div class="ts-rating-title ts-rating-title-top ' . ($title_truncate == "true" ? " ts-truncated" : "") . '" style="font-size: ' . $title_size . 'px; line-height: ' . $line_height . 'px; vertical-align: middle;">';
         if ($show_cart == "true") {
             $output .= '<a style="position: inherit; margin-right: 10px;" class="ts-woocommerce-product-purchase" href="?add-to-cart=' . $product_id . '" rel="nofollow" data-id="' . $product_id . '" data-sku="' . $product_sku . '"><i style="color: ' . $cart_color . '" class="ts-woocommerce-product-icon ts-woocommerce-product-cart ts-ecommerce-cart4"></i></a>';
         }
         if ($show_link == "true") {
             $output .= '<a style="position: inherit; margin-right: 10px;" href="' . $link . '" class="ts-woocommerce-product-link"><i style="color: ' . $link_color . '" class="ts-woocommerce-product-icon ts-woocommerce-product-view ts-ecommerce-forward"></i></a>';
         }
         $output .= $rating_title;
         $output .= '</div>';
     }
     if ($rating_tooltipcontent != '') {
         $output .= '<div class="ts-rating-tooltip ' . $rating_tooltipclasses . '" ' . $rating_tooltipcontent . '>';
     }
     $output .= '<div class="ts-star-rating' . ($rating_rtl == "false" ? "" : "-rtl") . ' ts-rating-active " style="font-size: ' . $rating_size . 'px; line-height: ' . ($rating_size + 5) . 'px;">';
     if ($caption_show == "true" && $caption_position == "left") {
         $output .= '<div class="ts-rating-caption" style="margin-right: 10px;">';
         if ($rating_rtl == "false") {
             $output .= '<span class="label ' . $caption_class . '" style="' . $caption_background . '">' . $rating_value . ' / ' . number_format($rating_maximum, 2, $caption_digits, '') . '</span>';
         } else {
             $output .= '<span class="label ' . $caption_class . '" style="' . $caption_background . '">' . number_format($rating_maximum, 2, $caption_digits, '') . ' / ' . $rating_value . '</span>';
         }
         $output .= '</div>';
     }
     $output .= '<div class="ts-rating-container' . ($rating_rtl == "false" ? "" : "-rtl") . ' ts-rating-glyph-holder ' . $rating_class . '" style="color: ' . ($rating_rtl == "false" ? $color_empty : $color_rated) . ';">';
     $output .= '<div class="ts-rating-stars ' . $rating_class . '" style="color: ' . ($rating_rtl == "false" ? $color_rated : $color_empty) . '; width: ' . $rating_width . '%;"></div>';
     $output .= '</div>';
     if ($caption_show == "true" && $caption_position == "right") {
         $output .= '<div class="ts-rating-caption" style="margin-left: 10px;">';
         if ($rating_rtl == "false") {
             $output .= '<span class="label ' . $caption_class . '" style="' . $caption_background . '">' . $rating_value . ' / ' . number_format($rating_maximum, 2, $caption_digits, '') . '</span>';
         } else {
             $output .= '<span class="label ' . $caption_class . '" style="' . $caption_background . '">' . number_format($rating_maximum, 2, $caption_digits, '') . ' / ' . $rating_value . '</span>';
         }
         $output .= '</div>';
     }
     $output .= '</div>';
     if ($rating_tooltipcontent != '') {
         $output .= '</div>';
     }
     if ($rating_position == 'bottom' && $rating_title != '') {
         $output .= '<div class="ts-rating-title ts-rating-title-bottom ' . ($title_truncate == "true" ? " ts-truncated" : "") . '" style="font-size: ' . $title_size . 'px; line-height: ' . $line_height . 'px; vertical-align: middle;">';
         if ($show_cart == "true") {
             $output .= '<a style="position: inherit; margin-left: 10px;" class="ts-woocommerce-product-purchase" href="?add-to-cart=' . $product_id . '" rel="nofollow" data-id="' . $product_id . '" data-sku="' . $product_sku . '"><i style="color: ' . $cart_color . '" class="ts-woocommerce-product-icon ts-woocommerce-product-cart ts-ecommerce-cart4"></i></a>';
         }
         if ($show_link == "true") {
             $output .= '<a style="position: inherit; margin-left: 10px;" href="' . $link . '" class="ts-woocommerce-product-link"><i style="color: ' . $link_color . '" class="ts-woocommerce-product-icon ts-woocommerce-product-view ts-ecommerce-forward"></i></a>';
         }
         $output .= $rating_title;
         $output .= '</div>';
     }
     $output .= '</div>';
     echo $output;
     $myvariable = ob_get_clean();
     return $myvariable;
 }
function WooComposer_Loop_style04($atts, $element)
{
    global $woocommerce;
    $product_style = $display_elements = $quick_view_style = $img_animate = $text_align = $color_heading = $color_categories = $color_price = '';
    $color_rating = $color_rating_bg = $color_quick_bg = $color_quick = $color_cart_bg = $color_cart = $color_product_desc = $advanced_opts = '';
    $color_product_desc_bg = $size_title = $size_cat = $size_price = $color_on_sale = $color_on_sale_bg = $label_on_sale = $product_animation = '';
    $disp_type = $category = $output = $product_style = $border_style = $border_color = $border_size = $border_radius = $lazy_images = $pagination = '';
    $sale_price = $shortcode = $on_sale_alignment = $on_sale_style = $product_img_disp = '';
    extract(shortcode_atts(array("disp_type" => "", "category" => "", "shortcode" => "", "product_style" => "style01", "display_elements" => "", "quick_view_style" => "expandable", "label_on_sale" => "Sale!", "text_align" => "left", "img_animate" => "rotate-clock", "pagination" => "", "color_heading" => "", "color_categories" => "", "color_price" => "", "color_rating" => "", "color_rating_bg" => "", "color_quick_bg" => "", "color_quick" => "", "color_cart_bg" => "", "color_on_sale_bg" => "", "color_on_sale" => "", "color_cart" => "", "color_product_desc" => "", "color_product_desc_bg" => "", "size_title" => "", "size_cat" => "", "size_price" => "", "border_style" => "", "border_color" => "", "border_size" => "", "border_radius" => "", "product_animation" => "", "lazy_images" => "", "advanced_opts" => "", "sale_price" => "", "on_sale_style" => "wcmp-sale-circle", "on_sale_alignment" => "wcmp-sale-right", "product_img_disp" => "single"), $atts));
    $output = $heading_style = $cat_style = $price_style = $cart_style = $cart_bg_style = $view_style = $view_bg_style = $rating_style = '';
    $desc_style = $label_style = $on_sale = $class = $style = $border = $desc_style = $sale_price_size = '';
    $image_size = apply_filters('single_product_large_thumbnail_size', 'shop_single');
    $img_animate = 'wcmp-img-' . $img_animate;
    if ($sale_price !== '') {
        $sale_price_size = 'font-size:' . $sale_price . 'px;';
    }
    if ($border_style !== '') {
        $border .= 'border:' . $border_size . 'px ' . $border_style . ' ' . $border_color . ';';
        $border .= 'border-radius:' . $border_radius . 'px;';
    }
    if ($color_product_desc_bg !== '') {
        $desc_style .= 'background:' . $color_product_desc_bg . ';';
    }
    if ($color_product_desc !== '') {
        $desc_style .= 'color:' . $color_product_desc . ';';
    }
    $columns = 3;
    $display_type = $disp_type;
    if ($color_heading !== "") {
        $heading_style = 'color:' . $color_heading . ';';
    }
    if ($size_title !== "") {
        $heading_style .= 'font-size:' . $size_title . 'px;';
    }
    if ($color_categories !== "") {
        $cat_style = 'color:' . $color_categories . ';';
    }
    if ($size_cat !== "") {
        $cat_style .= 'font-size:' . $size_cat . 'px;';
    }
    if ($color_price !== "") {
        $price_style = 'color:' . $color_price . ';';
    }
    if ($size_price !== "") {
        $price_style .= 'font-size:' . $size_price . 'px;';
    }
    if ($color_rating !== "") {
        $rating_style .= 'color:' . $color_rating . ';';
    }
    if ($color_rating_bg !== "") {
        $rating_style .= 'background:' . $color_rating_bg . ';';
    }
    if ($color_quick_bg !== "") {
        $view_bg_style = 'background:' . $color_quick_bg . ';';
    }
    if ($color_quick !== "") {
        $view_style = 'color:' . $color_quick . ';';
    }
    if ($color_cart_bg !== "") {
        $cart_bg_style = 'background:' . $color_cart_bg . ';';
    }
    if ($color_cart !== "") {
        $cart_style = 'color:' . $color_cart . ';';
    }
    if ($color_on_sale_bg !== "") {
        $label_style = 'background:' . $color_on_sale_bg . ';';
    }
    if ($color_on_sale !== "") {
        $label_style .= 'color:' . $color_on_sale . ';';
    }
    $elemets = explode(",", $display_elements);
    if ($element == "grid") {
        $paged = get_query_var('paged') ? get_query_var('paged') : 1;
    } else {
        $paged = 1;
    }
    $post_count = '12';
    /* $output .= do_shortcode($content); */
    if ($shortcode !== '') {
        $new_shortcode = rawurldecode(base64_decode(strip_tags($shortcode)));
    }
    $pattern = get_shortcode_regex();
    $shortcode_str = $short_atts = '';
    preg_match_all("/" . $pattern . "/", $new_shortcode, $matches);
    $shortcode_str = str_replace('"', '', str_replace(" ", "&", trim($matches[3][0])));
    $short_atts = parse_str($shortcode_str);
    //explode("&",$shortcode_str);
    if (isset($matches[2][0])) {
        $display_type = $matches[2][0];
    } else {
        $display_type = '';
    }
    if (!isset($columns)) {
        $columns = '4';
    }
    if (isset($per_page)) {
        $post_count = $per_page;
    }
    if (isset($number)) {
        $post_count = $number;
    }
    if (!isset($order)) {
        $order = 'asc';
    }
    if (!isset($orderby)) {
        $orderby = 'date';
    }
    if (!isset($category)) {
        $category = '';
    }
    if (!isset($ids)) {
        $ids = '';
    }
    if ($ids) {
        $ids = explode(',', $ids);
        $ids = array_map('trim', $ids);
    }
    $col = $columns;
    if ($columns == "2") {
        $columns = 6;
    } elseif ($columns == "3") {
        $columns = 4;
    } elseif ($columns == "4") {
        $columns = 3;
    }
    $meta_query = '';
    if ($display_type == "recent_products") {
        $meta_query = WC()->query->get_meta_query();
    }
    if ($display_type == "featured_products") {
        $meta_query = array(array('key' => '_visibility', 'value' => array('catalog', 'visible'), 'compare' => 'IN'), array('key' => '_featured', 'value' => 'yes'));
    }
    if ($display_type == "top_rated_products") {
        add_filter('posts_clauses', array(WC()->query, 'order_by_rating_post_clauses'));
        $meta_query = WC()->query->get_meta_query();
    }
    $args = array('post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'posts_per_page' => $post_count, 'orderby' => $orderby, 'order' => $order, 'paged' => $paged, 'meta_query' => $meta_query);
    if ($display_type == "sale_products") {
        $product_ids_on_sale = woocommerce_get_product_ids_on_sale();
        $meta_query = array();
        $meta_query[] = $woocommerce->query->visibility_meta_query();
        $meta_query[] = $woocommerce->query->stock_status_meta_query();
        $args['meta_query'] = $meta_query;
        $args['post__in'] = $product_ids_on_sale;
    }
    if ($display_type == "best_selling_products") {
        $args['meta_key'] = 'total_sales';
        $args['orderby'] = 'meta_value_num';
        $args['meta_query'] = array(array('key' => '_visibility', 'value' => array('catalog', 'visible'), 'compare' => 'IN'));
    }
    if ($display_type == "product_category") {
        $args['tax_query'] = array(array('taxonomy' => 'product_cat', 'terms' => array(esc_attr($category)), 'field' => 'slug', 'operator' => 'IN'));
    }
    if ($display_type == "product_categories") {
        $args['tax_query'] = array(array('taxonomy' => 'product_cat', 'terms' => $ids, 'field' => 'term_id', 'operator' => 'IN'));
    }
    $test = '';
    if (vc_is_inline()) {
        $test = "wcmp_vc_inline";
    }
    if ($product_animation == '') {
        $product_animation = 'no-animation';
    } else {
        $style .= 'opacity:1;';
    }
    if ($element == "grid") {
        $class = 'vc_span' . $columns . ' ';
    }
    $output .= '<div class="woocomposer ' . $test . '" data-columns="' . $col . '">';
    $query = new WP_Query($args);
    if ($query->have_posts()) {
        while ($query->have_posts()) {
            $query->the_post();
            $product_id = get_the_ID();
            $uid = uniqid();
            $output .= '<div id="product-' . $uid . '" style="' . $style . '" class="' . $class . ' wpb_column column_container wooproduct" data-animation="animated ' . $product_animation . '">';
            if ($element == 'carousel') {
                $output .= '<div class="wcmp-carousel-item">';
            }
            $product_title = get_the_title($product_id);
            $post = get_post($product_id);
            $product_desc = get_post($product_id)->post_excerpt;
            $product_img = wp_get_attachment_image_src(get_post_thumbnail_id($product_id), $image_size);
            $product = new WC_Product($product_id);
            $attachment_ids = $product->get_gallery_attachment_ids();
            $price = $product->get_price_html();
            $rating = $product->get_rating_html();
            $attributes = $product->get_attributes();
            $stock = $product->is_in_stock() ? 'InStock' : 'OutOfStock';
            if ($product->is_on_sale()) {
                $on_sale = apply_filters('woocommerce_sale_flash', $label_on_sale, $post, $product);
            } else {
                $on_sale = '';
            }
            if ($quick_view_style == "expandable") {
                $quick_view_class = 'quick-view-loop';
            } else {
                $quick_view_class = 'quick-view-loop-popup';
            }
            $cat_count = sizeof(get_the_terms($product_id, 'product_cat'));
            $tag_count = sizeof(get_the_terms($product_id, 'product_tag'));
            $categories = $product->get_categories(', ', '<span class="posted_in">' . _n('', '', $cat_count, 'woocommerce') . ' ', '.</span>');
            $tags = $product->get_tags(', ', '<span class="tagged_as">' . _n('', '', $tag_count, 'woocommerce') . ' ', '.</span>');
            $output .= "\n" . '<div class="wcmp-product woocommerce wcmp-' . $product_style . ' ' . $img_animate . '" style="' . $border . ' ' . $desc_style . '">';
            $output .= "\n\t" . '<div class="wcmp-product-image">';
            if (empty($attachment_ids) && count($attachment_ids) > 1 && $product_img_disp == "carousel") {
                $uniqid = uniqid();
                $output .= '<div class="wcmp-single-image-carousel carousel-in-loop">';
                $product_img = wp_get_attachment_image_src(get_post_thumbnail_id($product_id), $image_size);
                if ($lazy_images == "enable") {
                    $src = plugins_url('../assets/img/loader.gif', __FILE__);
                } else {
                    $src = $product_img[0];
                }
                $output .= '<div><div class="wcmp-image"><img class="wcmp-img" src="' . $src . '" data-src="' . $product_img[0] . '"/></div></div>';
                foreach ($attachment_ids as $attachment_id) {
                    $product_img = wp_get_attachment_image_src($attachment_id, $image_size);
                    if ($lazy_images == "enable") {
                        $src = plugins_url('../assets/img/loader.gif', __FILE__);
                    } else {
                        $src = $product_img[0];
                    }
                    $output .= '<div><div class="wcmp-image"><img class="wcmp-img" src="' . $src . '" data-src="' . $product_img[0] . '"/></div></div>';
                }
                $output .= '</div>';
            } else {
                $product_img = wp_get_attachment_image_src(get_post_thumbnail_id($product_id), $image_size);
                if ($lazy_images == "enable") {
                    $src = plugins_url('../assets/img/loader.gif', __FILE__);
                } else {
                    $src = $product_img[0];
                }
                $output .= '<a href="' . get_permalink($product_id) . '"><img class="wcmp-img" src="' . $src . '" data-src="' . $product_img[0] . '"/></a>';
            }
            if ($stock == 'OutOfStock') {
                $output .= "\n" . '<span class="wcmp-out-stock">' . __('Out Of Stock!', 'woocomposer') . '</span>';
            }
            if ($on_sale !== '') {
                $output .= "\n" . '<div class="wcmp-onsale ' . $on_sale_alignment . ' ' . $on_sale_style . '"><span class="onsale" style="' . $label_style . ' ' . $sale_price_size . '">' . $on_sale . '</span></div>';
            }
            $output .= '<div class="wcmp-add-to-cart" style="' . $cart_bg_style . '"><a style="' . $cart_style . '" title="Add to Cart" href="?add-to-cart=' . $product_id . '" rel="nofollow" data-product_id="' . $product_id . '" data-product_sku="" class="add_to_cart_button product_type_simple"><i class="wooicon-cart4"></i></a></div>';
            if (in_array("quick", $elemets)) {
                $output .= '<div class="wcmp-quick-view ' . $quick_view_class . '" style="' . $view_bg_style . '"><a style="' . $view_style . '" title="Quick View" href="' . get_permalink($product_id) . '"><i class="wooicon-plus32"></i></a></div>';
            }
            if (in_array("reviews", $elemets)) {
                $output .= "\n" . '<div class="wcmp-star-ratings" style="' . $rating_style . '">' . $rating . '</div>';
            }
            $output .= '</div>';
            $output .= "\n\t" . '<div class="wcmp-product-desc">';
            $output .= '<a href="' . get_permalink($product_id) . '">';
            $output .= "\n\t\t" . '<h2 style="' . $heading_style . '">' . $product_title . '</h2>';
            $output .= '</a>';
            if (in_array("category", $elemets)) {
                $output .= '<h5 style="' . $cat_style . '">';
                if ($categories !== '') {
                    $output .= $categories;
                    $output .= $tags;
                }
                $output .= '</h5>';
            }
            $output .= "\n\t\t" . '<div class="wcmp-price"><span class="price" style="' . $price_style . '">' . $price . '</span></div>';
            if (in_array("description", $elemets)) {
                $output .= "\n\t\t" . '<div class="wcmp-product-content" style="' . $desc_style . '">' . $product_desc . '</div>';
            }
            $output .= "\n\t" . '</div>';
            $output .= "\n\t" . '</div>';
            if (in_array("quick", $elemets)) {
                $output .= '<div class="wcmp-quick-view-wrapper woocommerce" data-columns="' . $col . '">';
                if ($quick_view_style !== "expandable") {
                    $output .= '<div class="wcmp-quick-view-wrapper woocommerce product">';
                    $output .= '<div class="wcmp-close-single"><i class="wooicon-cross2"></i></div>';
                }
                $product_img = wp_get_attachment_image_src(get_post_thumbnail_id($product_id), $image_size);
                if ($lazy_images == "enable") {
                    $src = plugins_url('../assets/img/loader.gif', __FILE__);
                } else {
                    $src = $product_img[0];
                }
                $output .= '<div class="wcmp-single-image wcmp-quickview-img images"><img class="wcmp-img" src="' . $src . '" data-src="' . $product_img[0] . '"/></div>';
                if ($quick_view_style !== "expandable") {
                    $output .= '<div class="wcmp-product-content-single">';
                } else {
                    $output .= '<div class="wcmp-product-content">';
                }
                ob_start();
                do_action('woocommerce_single_product_summary');
                $output .= ob_get_clean();
                $output .= '</div>';
                $output .= '<div class="clear"></div>';
                if ($quick_view_style !== "expandable") {
                    $output .= '</div>';
                }
                $output .= '</div>';
            }
            $output .= "\n" . '</div>';
            if ($element == 'carousel') {
                $output .= "\n\t" . '</div>';
            }
        }
    }
    if ($pagination == "enable") {
        $output .= '<div class="wcmp-paginate">';
        $output .= woocomposer_pagination($query->max_num_pages);
        $output .= '</div>';
    }
    $output .= '</div>';
    if ($display_type == "top_rated_products") {
        remove_filter('posts_clauses', array(WC()->query, 'order_by_rating_post_clauses'));
    }
    wp_reset_postdata();
    return $output;
}
 function TS_VCSC_WooCommerce_Slider_Basic_Function($atts, $content = null)
 {
     global $VISUAL_COMPOSER_EXTENSIONS;
     global $product;
     global $woocommerce;
     ob_start();
     wp_enqueue_script('ts-extend-hammer');
     wp_enqueue_script('ts-extend-nacho');
     wp_enqueue_style('ts-extend-nacho');
     if ($VISUAL_COMPOSER_EXTENSIONS->TS_VCSC_LoadFrontEndWaypoints == "true") {
         if (wp_script_is('waypoints', $list = 'registered')) {
             wp_enqueue_script('waypoints');
         } else {
             wp_enqueue_script('ts-extend-waypoints');
         }
     }
     wp_enqueue_style('ts-extend-owlcarousel2');
     wp_enqueue_script('ts-extend-owlcarousel2');
     wp_enqueue_style('ts-font-ecommerce');
     wp_enqueue_style('ts-extend-animations');
     wp_enqueue_style('ts-visual-composer-extend-front');
     wp_enqueue_script('ts-visual-composer-extend-front');
     extract(shortcode_atts(array('selection' => 'recent_products', 'category' => '', 'ids' => '', 'orderby' => 'date', 'order' => 'desc', 'products_total' => 12, 'exclude_outofstock' => 'false', 'show_image' => 'true', 'link_page' => 'false', 'link_target' => '_parent', 'show_rating' => 'true', 'show_stock' => 'true', 'show_price' => 'true', 'show_link' => 'true', 'show_cart' => 'true', 'show_info' => 'true', 'show_content' => 'excerpt', 'cutoff_characters' => 400, 'products_slide' => 4, 'breakpoints_custom' => 'false', 'breakpoints_items' => '1,2,3,4,5,6,7,8', 'auto_height' => 'false', 'page_rtl' => 'false', 'auto_play' => 'false', 'show_bar' => 'false', 'bar_color' => '#dd3333', 'show_speed' => 5000, 'stop_hover' => 'true', 'show_navigation' => 'true', 'show_dots' => 'true', 'items_loop' => 'false', 'animation_in' => 'ts-viewport-css-flipInX', 'animation_out' => 'ts-viewport-css-slideOutDown', 'animation_mobile' => 'false', 'lightbox_group_name' => 'nachogroup', 'lightbox_size' => 'full', 'lightbox_effect' => 'random', 'lightbox_speed' => 5000, 'lightbox_social' => 'true', 'lightbox_backlight_choice' => 'predefined', 'lightbox_backlight_color' => '#0084E2', 'lightbox_backlight_custom' => '#000000', 'image_position' => 'ts-imagefloat-center', 'hover_type' => 'ts-imagehover-style1', 'hover_active' => 'false', 'overlay_trigger' => 'ts-trigger-hover', 'rating_maximum' => 5, 'rating_value' => 0, 'rating_quarter' => 'true', 'rating_dynamic' => '', 'rating_size' => 16, 'rating_auto' => 'false', 'rating_rtl' => 'false', 'rating_symbol' => 'other', 'rating_icon' => 'ts-ecommerce-starfull1', 'color_rated' => '#FFD800', 'color_empty' => '#e3e3e3', 'caption_show' => 'false', 'caption_position' => 'left', 'caption_digits' => '.', 'caption_danger' => '#d9534f', 'caption_warning' => '#f0ad4e', 'caption_info' => '#5bc0de', 'caption_primary' => '#428bca', 'caption_success' => '#5cb85c', 'margin_top' => 0, 'margin_bottom' => 0, 'el_id' => '', 'el_class' => '', 'css' => ''), $atts));
     $woo_random = mt_rand(999999, 9999999);
     if (!empty($el_id)) {
         $woo_slider_id = $el_id;
     } else {
         $woo_slider_id = 'ts-vcsc-woocommerce-slider-' . $woo_random;
     }
     $output = '';
     // Backlight Color
     if ($lightbox_backlight_choice == "predefined") {
         $lightbox_backlight_selection = $lightbox_backlight_color;
     } else {
         $lightbox_backlight_selection = $lightbox_backlight_custom;
     }
     // Check for Front End Editor
     if ($VISUAL_COMPOSER_EXTENSIONS->TS_VCSC_VCFrontEditMode == "true") {
         $slider_class = 'owl-carousel2-edit';
         $slider_message = '<div class="ts-composer-frontedit-message">' . __('The slider is currently viewed in front-end edit mode; slider features are disabled for performance and compatibility reasons.', "ts_visual_composer_extend") . '</div>';
         $product_style = 'width: ' . 100 / $products_slide . '%; height: 100%; float: left; margin: 0; padding: 0;';
         $frontend_edit = 'true';
         $description_style = 'display: none; padding: 15px;';
     } else {
         $slider_class = 'ts-owlslider-parent owl-carousel2';
         $slider_message = '';
         $product_style = '';
         $frontend_edit = 'false';
         $description_style = 'display: none; padding: 15px;';
     }
     $meta_query = '';
     // Recent Products
     if ($selection == "recent_products") {
         $meta_query = WC()->query->get_meta_query();
     }
     // Featured Products
     if ($selection == "featured_products") {
         $meta_query = array(array('key' => '_visibility', 'value' => array('catalog', 'visible'), 'compare' => 'IN'), array('key' => '_featured', 'value' => 'yes'));
     }
     // Top Rated Products
     if ($selection == "top_rated_products") {
         add_filter('posts_clauses', array(WC()->query, 'order_by_rating_post_clauses'));
         $meta_query = WC()->query->get_meta_query();
     }
     // Final Query Arguments
     $args = array('post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'posts_per_page' => $frontend_edit == "true" ? $products_slide : $products_total, 'orderby' => $orderby, 'order' => $order, 'paged' => 1, 'meta_query' => $meta_query);
     // Products on Sale
     if ($selection == "sale_products") {
         $product_ids_on_sale = woocommerce_get_product_ids_on_sale();
         $meta_query = array();
         $meta_query[] = $woocommerce->query->visibility_meta_query();
         $meta_query[] = $woocommerce->query->stock_status_meta_query();
         $args['meta_query'] = $meta_query;
         $args['post__in'] = $product_ids_on_sale;
     }
     // Best Selling Products
     if ($selection == "best_selling_products") {
         $args['meta_key'] = 'total_sales';
         $args['orderby'] = 'meta_value_num';
         $args['meta_query'] = array(array('key' => '_visibility', 'value' => array('catalog', 'visible'), 'compare' => 'IN'));
     }
     // Products in Single Category
     if ($selection == "product_category") {
         $args['tax_query'] = array(array('taxonomy' => 'product_cat', 'terms' => array(esc_attr($category)), 'field' => 'slug', 'operator' => 'IN'));
     }
     // Products in Multiple Categories
     if ($selection == "product_categories") {
         $args['tax_query'] = array(array('taxonomy' => 'product_cat', 'terms' => explode(",", $ids), 'field' => 'term_id', 'operator' => 'IN'));
     }
     // Start WordPress Query
     $loop = new WP_Query($args);
     if (function_exists('vc_shortcode_custom_css_class')) {
         $css_class = apply_filters(VC_SHORTCODE_CUSTOM_CSS_FILTER_TAG, $slider_class . ' ' . $el_class . ' ' . vc_shortcode_custom_css_class($css, ' '), 'TS_VCSC_WooCommerce_Slider_Basic', $atts);
     } else {
         $css_class = $slider_class . ' ' . $el_class;
     }
     $output .= '<div id="' . $woo_slider_id . '-container" class="ts-woocommerce-slider-container">';
     // Add Progressbar
     if ($auto_play == "true" && $show_bar == "true" && $frontend_edit == "false") {
         $output .= '<div id="ts-owlslider-progressbar-' . $woo_random . '" class="ts-owlslider-progressbar-holder" style=""><div class="ts-owlslider-progressbar" style="background: ' . $bar_color . '; height: 100%; width: 0%;"></div></div>';
     }
     // Add Navigation Controls
     if ($frontend_edit == "false") {
         $output .= '<div id="ts-owlslider-controls-' . $woo_random . '" class="ts-owlslider-controls" style="' . ($auto_play == "true" || $show_navigation == "true" ? "display: block;" : "display: none;") . '">';
         $output .= '<div id="ts-owlslider-controls-next-' . $woo_random . '" style="' . ($show_navigation == "true" ? "display: block;" : "display: none;") . '" class="ts-owlslider-controls-next"><span class="ts-ecommerce-arrowright5"></span></div>';
         $output .= '<div id="ts-owlslider-controls-prev-' . $woo_random . '" style="' . ($show_navigation == "true" ? "display: block;" : "display: none;") . '" class="ts-owlslider-controls-prev"><span class="ts-ecommerce-arrowleft5"></span></div>';
         if ($auto_play == "true") {
             $output .= '<div id="ts-owlslider-controls-play-' . $woo_random . '" class="ts-owlslider-controls-play active"><span class="ts-ecommerce-pause"></span></div>';
         }
         $output .= '</div>';
     }
     // Front-Edit Message
     if ($frontend_edit == "true") {
         $output .= $slider_message;
     }
     // Add Slider
     $output .= '<div id="' . $woo_slider_id . '" class="' . $css_class . '" style="margin-top: ' . $margin_top . 'px; margin-bottom: ' . $margin_bottom . 'px;" data-id="' . $woo_random . '" data-items="' . $products_slide . '" data-breakpointscustom="' . $breakpoints_custom . '" data-breakpointitems="' . $breakpoints_items . '" data-rtl="' . $page_rtl . '" data-loop="' . $items_loop . '" data-navigation="' . $show_navigation . '" data-dots="' . $show_dots . '" data-mobile="' . $animation_mobile . '" data-animationin="' . $animation_in . '" data-animationout="' . $animation_out . '" data-height="' . $auto_height . '" data-play="' . $auto_play . '" data-bar="' . $show_bar . '" data-color="' . $bar_color . '" data-speed="' . $show_speed . '" data-hover="' . $stop_hover . '">';
     if ($loop->have_posts()) {
         while ($loop->have_posts()) {
             $loop->the_post();
             $product_id = get_the_ID();
             $product_title = get_the_title($product_id);
             $post = get_post($product_id);
             $product = new WC_Product($product_id);
             $attachment_ids = $product->get_gallery_attachment_ids();
             $price = $product->get_price_html();
             $product_sku = $product->get_sku();
             $attributes = $product->get_attributes();
             $stock = $product->is_in_stock() ? 'true' : 'false';
             $onsale = $product->is_on_sale() ? 'true' : 'false';
             // Rating Settings
             $rating_html = $product->get_rating_html();
             $rating = $product->get_average_rating();
             if ($rating == '') {
                 $rating = 0;
             }
             if ($rating_quarter == "true") {
                 $rating_value = floor($rating * 4) / 4;
             } else {
                 $rating_value = $rating;
             }
             $rating_value = number_format($rating_value, 2, $caption_digits, '');
             if ($rating_rtl == "false") {
                 $rating_width = $rating_value / $rating_maximum * 100;
             } else {
                 $rating_width = 100 - $rating_value / $rating_maximum * 100;
             }
             if ($rating_symbol == "other") {
                 if ($rating_icon == "ts-ecommerce-starfull1") {
                     $rating_class = 'ts-rating-stars-star1';
                 } else {
                     if ($rating_icon == "ts-ecommerce-starfull2") {
                         $rating_class = 'ts-rating-stars-star2';
                     } else {
                         if ($rating_icon == "ts-ecommerce-starfull3") {
                             $rating_class = 'ts-rating-stars-star3';
                         } else {
                             if ($rating_icon == "ts-ecommerce-starfull4") {
                                 $rating_class = 'ts-rating-stars-star4';
                             } else {
                                 if ($rating_icon == "ts-ecommerce-heartfull") {
                                     $rating_class = 'ts-rating-stars-heart1';
                                 } else {
                                     if ($rating_icon == "ts-ecommerce-heart") {
                                         $rating_class = 'ts-rating-stars-heart2';
                                     } else {
                                         if ($rating_icon == "ts-ecommerce-thumbsup") {
                                             $rating_class = 'ts-rating-stars-thumb';
                                         } else {
                                             if ($rating_icon == "ts-ecommerce-ribbon4") {
                                                 $rating_class = 'ts-rating-stars-ribbon';
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             } else {
                 $rating_class = 'ts-rating-stars-smile';
             }
             if ($rating_value >= 0 && $rating_value <= 1) {
                 $caption_class = 'ts-label-danger';
                 $caption_background = 'background-color: ' . $caption_danger . ';';
             } else {
                 if ($rating_value > 1 && $rating_value <= 2) {
                     $caption_class = 'ts-label-warning';
                     $caption_background = 'background-color: ' . $caption_warning . ';';
                 } else {
                     if ($rating_value > 2 && $rating_value <= 3) {
                         $caption_class = 'ts-label-info';
                         $caption_background = 'background-color: ' . $caption_info . ';';
                     } else {
                         if ($rating_value > 3 && $rating_value <= 4) {
                             $caption_class = 'ts-label-primary';
                             $caption_background = 'background-color: ' . $caption_primary . ';';
                         } else {
                             if ($rating_value > 4 && $rating_value <= 5) {
                                 $caption_class = 'ts-label-success';
                                 $caption_background = 'background-color: ' . $caption_success . ';';
                             }
                         }
                     }
                 }
             }
             if (has_post_thumbnail($loop->post->ID)) {
                 $featured = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full');
                 $thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id(), 'thumbnail');
                 $featured = $featured[0];
                 $thumbnail = $thumbnail[0];
             } else {
                 $featured = woocommerce_placeholder_img_src();
                 $thumbnail = $featured;
             }
             $title = get_the_title();
             if ($exclude_outofstock == "true" && $stock == "true" || $exclude_outofstock == "false") {
                 $output .= '<div class="ts-woocommerce-product-slide" style="' . $product_style . '" data-hash="' . $product_id . '">';
                 $output .= '<div id="ts-woocommerce-product-' . $product_id . '" class="ts-image-hover-frame ' . $image_position . ' ts-trigger-hover-adjust" style="width: 100%;">';
                 $output .= '<div id="ts-woocommerce-product-' . $product_id . '-counter" class="ts-fluid-wrapper " style="width: 100%; height: auto;">';
                 $output .= '<div id="ts-woocommerce-product-' . $product_id . '-mask" class="ts-imagehover ' . $hover_type . ' ts-trigger-hover" data-trigger="ts-trigger-hover" data-closer="" style="width: 100%; height: auto;">';
                 // Product Thumbnail
                 $output .= '<div class="ts-woocommerce-product-preview">';
                 $output .= '<img class="ts-woocommerce-product-image" src="' . $featured . '" alt="" />';
                 $output .= '</div>';
                 // Sale Ribbon
                 if ($onsale == "true") {
                     $output .= '<div class="ts-woocommerce-product-ribbon"></div>';
                     $output .= '<i style="" class="ts-woocommerce-product-icon ts-woocommerce-product-sale ts-ecommerce-tagsale"></i>';
                 }
                 $output .= '<div class="ts-woocommerce-product-main">';
                 $output .= '<div class="mask" style="width: 100%; display: block;">';
                 $output .= '<div id="ts-woocommerce-product-' . $product_id . '-maskcontent" class="maskcontent" style="margin: 0; padding: 0;">';
                 // Product Thubmnail
                 if ($show_image == "true") {
                     if ($link_page == "false") {
                         $output .= '<div class="ts-woocommerce-link-wrapper"><a id="" class="nch-lightbox-media no-ajaxy" data-title="' . $title . '" rel="" href="' . $featured . '" target="' . $link_target . '">';
                         $output .= '<div class="ts-woocommerce-product-thumbnail" style="background-image: url(' . $thumbnail . ');"></div>';
                         $output .= '</a></div>';
                     } else {
                         $output .= '<div class="ts-woocommerce-link-wrapper"><a id="" class="" data-title="' . $title . '" rel="" href="' . get_permalink() . '" target="' . $link_target . '">';
                         $output .= '<div class="ts-woocommerce-product-thumbnail" style="background-image: url(' . $thumbnail . ');"></div>';
                         $output .= '</a></div>';
                     }
                 }
                 // Product Page Link
                 if ($show_link == "true") {
                     $output .= '<div class="ts-woocommerce-link-wrapper"><a href="' . get_permalink() . '" class="ts-woocommerce-product-link" target="' . $link_target . '"><i style="" class="ts-woocommerce-product-icon ts-woocommerce-product-view ts-ecommerce-forward"></i></a></div>';
                 }
                 // Product Rating
                 if ($show_rating == "true") {
                     $output .= '<div class="ts-rating-stars-frame" data-auto="' . $rating_auto . '" data-size="' . $rating_size . '" data-width="' . $rating_size * 5 . '" data-rating="' . $rating_value . '" style="margin: 10px 0 0 10px; float: left;">';
                     $output .= '<div class="ts-star-rating' . ($rating_rtl == "false" ? "" : "-rtl") . ' ts-rating-active " style="font-size: ' . $rating_size . 'px; line-height: ' . ($rating_size + 5) . 'px;">';
                     if ($caption_show == "true" && $caption_position == "left") {
                         $output .= '<div class="ts-rating-caption" style="margin-right: 10px;">';
                         if ($rating_rtl == "false") {
                             $output .= '<span class="label ' . $caption_class . '" style="' . $caption_background . '">' . $rating_value . ' / ' . number_format($rating_maximum, 2, $caption_digits, '') . '</span>';
                         } else {
                             $output .= '<span class="label ' . $caption_class . '" style="' . $caption_background . '">' . number_format($rating_maximum, 2, $caption_digits, '') . ' / ' . $rating_value . '</span>';
                         }
                         $output .= '</div>';
                     }
                     $output .= '<div class="ts-rating-container' . ($rating_rtl == "false" ? "" : "-rtl") . ' ts-rating-glyph-holder ' . $rating_class . '" style="color: ' . ($rating_rtl == "false" ? $color_empty : $color_rated) . ';">';
                     $output .= '<div class="ts-rating-stars ' . $rating_class . '" style="color: ' . ($rating_rtl == "false" ? $color_rated : $color_empty) . '; width: ' . $rating_width . '%;"></div>';
                     $output .= '</div>';
                     if ($caption_show == "true" && $caption_position == "right") {
                         $output .= '<div class="ts-rating-caption" style="margin-left: 10px;">';
                         if ($rating_rtl == "false") {
                             $output .= '<span class="label ' . $caption_class . '" style="' . $caption_background . '">' . $rating_value . ' / ' . number_format($rating_maximum, 2, $caption_digits, '') . '</span>';
                         } else {
                             $output .= '<span class="label ' . $caption_class . '" style="' . $caption_background . '">' . number_format($rating_maximum, 2, $caption_digits, '') . ' / ' . $rating_value . '</span>';
                         }
                         $output .= '</div>';
                     }
                     $output .= '</div>';
                     $output .= '</div>';
                 }
                 // Product Price
                 if ($show_price == "true") {
                     $output .= '<div class="ts-woocommerce-product-price">';
                     $output .= '<i style="" class="ts-woocommerce-product-icon ts-woocommerce-product-cost ts-ecommerce-pricetag3"></i>';
                     if ($product->price > 0) {
                         if ($product->price && isset($product->regular_price)) {
                             $from = $product->regular_price;
                             $to = $product->price;
                             if ($from != $to) {
                                 $output .= '<div class="ts-woocommerce-product-regular"><del>' . (is_numeric($from) ? woocommerce_price($from) : $from) . '</del> | </div><div class="ts-woocommerce-product-special">' . (is_numeric($to) ? woocommerce_price($to) : $to) . '</div>';
                             } else {
                                 $output .= '<div class="ts-woocommerce-product-current">' . (is_numeric($to) ? woocommerce_price($to) : $to) . '</div>';
                             }
                         } else {
                             $to = $product->price;
                             $output .= '<div class="ts-woocommerce-product-current">' . (is_numeric($to) ? woocommerce_price($to) : $to) . '</div>';
                         }
                     } else {
                         $to = $product->price;
                         $output .= '<div class="ts-woocommerce-product-current">' . (is_numeric($to) ? woocommerce_price($to) : $to) . '</div>';
                     }
                     $output .= '</div>';
                 }
                 $output .= '<div class="ts-woocommerce-product-line"></div>';
                 // Add to Cart Button (Icon)
                 if ($show_cart == "true") {
                     $output .= '<div class="ts-woocommerce-link-wrapper"><a class="ts-woocommerce-product-purchase" href="?add-to-cart=' . $product_id . '" rel="nofollow" data-id="' . $product_id . '" data-sku="' . $product_sku . '"><i style="" class="ts-woocommerce-product-icon ts-woocommerce-product-cart ts-ecommerce-cart4"></i></a></div>';
                 }
                 // View Description Button
                 if ($show_info == "true") {
                     $output .= '<div id="ts-vcsc-modal-' . $product_id . '-trigger" style="" class="ts-vcsc-modal-' . $product_id . '-parent nch-holder ts-vcsc-font-icon ts-font-icons ts-shortcode ts-icon-align-center" style="">';
                     $output .= '<a href="#ts-vcsc-modal-' . $product_id . '" class="nch-lightbox-modal" data-title="" data-open="false" data-delay="0" data-type="html" rel="" data-effect="' . $lightbox_effect . '" data-share="0" data-duration="' . $lightbox_speed . '" data-color="' . $lightbox_backlight_selection . '">';
                     $output .= '<span class="">';
                     $output .= '<i class="ts-font-icon ts-woocommerce-product-icon ts-woocommerce-product-info ts-ecommerce-information1" style=""></i>';
                     $output .= '</span>';
                     $output .= '</a>';
                     $output .= '</div>';
                 }
                 // Product In-Stock or Unavailable
                 if ($show_stock == "true") {
                     $output .= '<div class="ts-woocommerce-product-status">';
                     if ($stock == 'false') {
                         $output .= '<div class="ts-woocommerce-product-stock"><span class="ts-woocommerce-product-outofstock">' . __('Out of Stock', 'woocommerce') . '</span></div>';
                     } else {
                         if ($stock == 'true') {
                             $output .= '<div class="ts-woocommerce-product-stock"><span class="ts-woocommerce-product-instock">' . __('In Stock', 'woocommerce') . '</span></div>';
                         }
                     }
                     $output .= '</div>';
                 }
                 $output .= '</div>';
                 $output .= '</div>';
                 $output .= '</div>';
                 $output .= '</div>';
                 $output .= '</div>';
                 $output .= '</div>';
                 // Product Title
                 $output .= '<h2 class="ts-woocommerce-product-title">';
                 $output .= $title;
                 $output .= '</h2>';
                 // Product Description
                 if ($show_info == "true") {
                     $output .= '<div id="ts-vcsc-modal-' . $product_id . '" class="ts-modal-content nch-hide-if-javascript" style="' . $description_style . '">';
                     $output .= '<div class="ts-modal-white-header"></div>';
                     $output .= '<div class="ts-modal-white-frame">';
                     $output .= '<div class="ts-modal-white-inner">';
                     $output .= '<h2 style="border-bottom: 1px solid #eeeeee; padding-bottom: 10px; line-height: 32px; font-size: 24px; text-align: left;">' . $title . '</h2>';
                     $output .= '<div class="ts-woocommerce-lightbox-frame" style="width: 100%; height: 32px; margin: 10px auto; padding: 0;">';
                     $output .= '<a style="position: inherit; margin-left: 10px; float: right;" class="ts-woocommerce-product-purchase" href="?add-to-cart=' . $product_id . '" rel="nofollow" data-id="' . $product_id . '" data-sku="' . $product_sku . '"><i style="color: #000000;" class="ts-woocommerce-product-icon ts-woocommerce-product-cart ts-ecommerce-cart4"></i></a>';
                     $output .= '<a href="' . get_permalink() . '" target="_parent" style="position: inherit; margin-left: 10px; float: right;" class="ts-woocommerce-product-link"><i style="color: #000000;" class="ts-woocommerce-product-icon ts-woocommerce-product-view ts-ecommerce-forward"></i></a>';
                     $output .= '<div class="ts-rating-stars-frame" data-auto="' . $rating_auto . '" data-size="' . $rating_size . '" data-width="' . $rating_size * 5 . '" data-rating="' . $rating_value . '" style="margin: 0; float: right;">';
                     $output .= '<div class="ts-star-rating' . ($rating_rtl == "false" ? "" : "-rtl") . ' ts-rating-active " style="font-size: ' . $rating_size . 'px; line-height: ' . ($rating_size + 5) . 'px;">';
                     if ($caption_show == "true" && $caption_position == "left") {
                         $output .= '<div class="ts-rating-caption" style="margin-right: 10px;">';
                         if ($rating_rtl == "false") {
                             $output .= '<span class="label ' . $caption_class . '" style="' . $caption_background . '">' . $rating_value . ' / ' . number_format($rating_maximum, 2, $caption_digits, '') . '</span>';
                         } else {
                             $output .= '<span class="label ' . $caption_class . '" style="' . $caption_background . '">' . number_format($rating_maximum, 2, $caption_digits, '') . ' / ' . $rating_value . '</span>';
                         }
                         $output .= '</div>';
                     }
                     $output .= '<div class="ts-rating-container' . ($rating_rtl == "false" ? "" : "-rtl") . ' ts-rating-glyph-holder ' . $rating_class . '" style="color: ' . ($rating_rtl == "false" ? $color_empty : $color_rated) . ';">';
                     $output .= '<div class="ts-rating-stars ' . $rating_class . '" style="color: ' . ($rating_rtl == "false" ? $color_rated : $color_empty) . '; width: ' . $rating_width . '%;"></div>';
                     $output .= '</div>';
                     if ($caption_show == "true" && $caption_position == "right") {
                         $output .= '<div class="ts-rating-caption" style="margin-left: 10px;">';
                         if ($rating_rtl == "false") {
                             $output .= '<span class="label ' . $caption_class . '" style="' . $caption_background . '">' . $rating_value . ' / ' . number_format($rating_maximum, 2, $caption_digits, '') . '</span>';
                         } else {
                             $output .= '<span class="label ' . $caption_class . '" style="' . $caption_background . '">' . number_format($rating_maximum, 2, $caption_digits, '') . ' / ' . $rating_value . '</span>';
                         }
                         $output .= '</div>';
                     }
                     $output .= '</div>';
                     $output .= '</div>';
                     $output .= '<div class="ts-woocommerce-product-price" style="position: inherit; margin-right: 10px; float: left; width: auto; margin-top: 0;">';
                     $output .= '<i style="color: #000000; margin: 0 10px 0 0;" class="ts-woocommerce-product-icon ts-woocommerce-product-cost ts-ecommerce-pricetag3"></i>';
                     if ($product->price > 0) {
                         if ($product->price && isset($product->regular_price)) {
                             $from = $product->regular_price;
                             $to = $product->price;
                             if ($from != $to) {
                                 $output .= '<div class="ts-woocommerce-product-regular"><del style="color: #7F0000;">' . (is_numeric($from) ? woocommerce_price($from) : $from) . '</del> | </div><div class="ts-woocommerce-product-special">' . (is_numeric($to) ? woocommerce_price($to) : $to) . '</div>';
                             } else {
                                 $output .= '<div class="ts-woocommerce-product-current">' . (is_numeric($to) ? woocommerce_price($to) : $to) . '</div>';
                             }
                         } else {
                             $to = $product->price;
                             $output .= '<div class="ts-woocommerce-product-current">' . (is_numeric($to) ? woocommerce_price($to) : $to) . '</div>';
                         }
                     } else {
                         $to = $product->price;
                         $output .= '<div class="ts-woocommerce-product-current">' . (is_numeric($to) ? woocommerce_price($to) : $to) . '</div>';
                     }
                     $output .= '</div>';
                     $output .= '</div>';
                     $output .= '<div class="ts-woocommerce-product-seperator" style="border-bottom: 1px solid #eeeeee; margin: 10px auto 20px auto; width: 100%;"></div>';
                     $output .= '<img style="width: 100%; max-width: 250px; height: auto; margin: 10px auto;" class="ts-woocommerce-product-image" src="' . $featured . '" alt="" />';
                     $output .= '<div class="ts-woocommerce-product-seperator" style="border-bottom: 1px solid #eeeeee; margin: 20px auto 10px auto; width: 100%;"></div>';
                     $output .= '<div style="margin-top: 20px; text-align: justify;">';
                     if ($show_content == "excerpt") {
                         $output .= get_the_excerpt();
                     } else {
                         if ($show_content == "cutcharacters") {
                             $content = apply_filters('the_content', get_the_content());
                             $excerpt = TS_VCSC_TruncateHTML($content, $cutoff_characters, '...', false, true);
                             $output .= $excerpt;
                         } else {
                             if ($show_content == "complete") {
                                 $output .= get_the_content();
                             }
                         }
                     }
                     $output .= '</div>';
                     $output .= '</div>';
                     $output .= '</div>';
                     $output .= '</div>';
                 }
                 $output .= '</div>';
             }
         }
     } else {
         echo __("No products could be found.", "ts_visual_composer_extend");
     }
     $output .= '</div>';
     $output .= '</div>';
     wp_reset_postdata();
     wp_reset_query();
     echo $output;
     $myvariable = ob_get_clean();
     return $myvariable;
 }
Example #16
0
 private function update_product($body, $sku)
 {
     // hämta postid från sku
     $product = $this->get_product_by_sku($sku);
     // deleta alla attachments
     $okdelete = $this->delete_product_and_attachments($product->id, false);
     $args = array('ID' => $product->id, 'post_title' => $body['Item']['Description'], 'post_content' => $body['Item']['Content'], 'post_status' => 'publish', 'post_date' => date('Y-m-d H:i:s'), 'post_author' => 1, 'post_type' => 'product', 'post_name' => $sku, 'post_category' => array(0));
     // uppdatera posten
     $post_id = wp_update_post($args, true);
     $this->update_post_meta_product($product->sku, null, $product->id);
     if ($body['Item']['GrossPrice']) {
         $price = $body['Item']['GrossPrice'];
     }
     $this->setProductPrice($price > 0 ? $price : 666, $post_id);
     if (is_wp_error($post_id)) {
         $errors = $post_id->get_error_messages();
         foreach ($errors as $error) {
             echo $error;
         }
     }
     // inserta alla attachments och attribut och bilder
     $this->insert_attachment_product($body, $product->id, $product->sku);
     // sätt kategorin
     // om kategorin är satt i requesten
     if ($body['Item']['Category']) {
         $term = get_term_by('slug', $body['Item']['Category'], 'product_cat');
         // om kategorin/termen finns
         if ($term != false) {
             $ok = wp_set_object_terms($post_id, $term->term_id, 'product_cat');
         } else {
             $ok = wp_set_object_terms($post_id, 3377, 'product_cat');
         }
     }
     $post = new WC_Product($product->id);
     return array('post' => new WC_Product($post_id), 'attributes' => $post->get_attributes(), 'image' => $post->get_image(), 'Update' => true);
     return $post;
 }
/**
 * Outputs a list of product attributes for a product.
 * @since  2.7.0
 * @param  WC_Product $product
 */
function wc_display_product_attributes($product)
{
    wc_get_template('single-product/product-attributes.php', array('product' => $product, 'attributes' => array_filter($product->get_attributes(), 'wc_attributes_array_filter_visible'), 'display_dimensions' => apply_filters('wc_product_enable_dimensions_display', $product->has_weight() || $product->has_dimensions())));
}
 /**
  * Save variations.
  *
  * @throws WC_REST_Exception REST API exceptions.
  * @param WC_Product      $product          Product instance.
  * @param WP_REST_Request $request          Request data.
  * @param bool            $single_variation True if saving only a single variation.
  * @return bool
  */
 protected function save_variations_data($product, $request, $single_variation = false)
 {
     global $wpdb;
     if ($single_variation) {
         $variations = array($request);
     } else {
         $variations = $request['variations'];
     }
     foreach ($variations as $menu_order => $data) {
         $variation_id = isset($data['id']) ? absint($data['id']) : 0;
         $variation = new WC_Product_Variation($variation_id);
         // Create initial name and status.
         if (!$variation->get_slug()) {
             /* translators: 1: variation id 2: product name */
             $variation->set_name(sprintf(__('Variation #%1$s of %2$s', 'woocommerce'), $variation->get_id(), $product->get_name()));
             $variation->set_status(isset($data['visible']) && false === $data['visible'] ? 'private' : 'publish');
         }
         // Parent ID.
         $variation->set_parent_id($product->get_id());
         // Menu order.
         $variation->set_menu_order($menu_order);
         // Status.
         if (isset($data['visible'])) {
             $variation->set_status(false === $data['visible'] ? 'private' : 'publish');
         }
         // SKU.
         if (isset($data['sku'])) {
             $variation->set_sku(wc_clean($data['sku']));
         }
         // Thumbnail.
         if (isset($data['image']) && is_array($data['image'])) {
             $image = $data['image'];
             $image = current($image);
             if (is_array($image)) {
                 $image['position'] = 0;
             }
             $variation = $this->save_product_images($variation, array($image));
         }
         // Virtual variation.
         if (isset($data['virtual'])) {
             $variation->set_virtual($data['virtual']);
         }
         // Downloadable variation.
         if (isset($data['downloadable'])) {
             $variation->set_downloadable($data['downloadable']);
         }
         // Downloads.
         if ($variation->get_downloadable()) {
             // Downloadable files.
             if (isset($data['downloads']) && is_array($data['downloads'])) {
                 $variation = $this->save_downloadable_files($variation, $data['downloads']);
             }
             // Download limit.
             if (isset($data['download_limit'])) {
                 $variation->set_download_limit($data['download_limit']);
             }
             // Download expiry.
             if (isset($data['download_expiry'])) {
                 $variation->set_download_expiry($data['download_expiry']);
             }
         }
         // Shipping data.
         $variation = $this->save_product_shipping_data($variation, $data);
         // Stock handling.
         if (isset($data['manage_stock'])) {
             $variation->set_manage_stock($data['manage_stock']);
         }
         if (isset($data['in_stock'])) {
             $variation->set_stock_status(true === $data['in_stock'] ? 'instock' : 'outofstock');
         }
         if (isset($data['backorders'])) {
             $variation->set_backorders($data['backorders']);
         }
         if ($variation->get_manage_stock()) {
             if (isset($data['stock_quantity'])) {
                 $variation->set_stock_quantity($data['stock_quantity']);
             } elseif (isset($data['inventory_delta'])) {
                 $stock_quantity = wc_stock_amount($variation->get_stock_amount());
                 $stock_quantity += wc_stock_amount($data['inventory_delta']);
                 $variation->set_stock_quantity($stock_quantity);
             }
         } else {
             $variation->set_backorders('no');
             $variation->set_stock_quantity('');
         }
         // Regular Price.
         if (isset($data['regular_price'])) {
             $variation->set_regular_price($data['regular_price']);
         }
         // Sale Price.
         if (isset($data['sale_price'])) {
             $variation->set_sale_price($data['sale_price']);
         }
         if (isset($data['date_on_sale_from'])) {
             $variation->set_date_on_sale_from($data['date_on_sale_from']);
         }
         if (isset($data['date_on_sale_to'])) {
             $variation->set_date_on_sale_to($data['date_on_sale_to']);
         }
         // Tax class.
         if (isset($data['tax_class'])) {
             $variation->set_tax_class($data['tax_class']);
         }
         // Description.
         if (isset($data['description'])) {
             $variation->set_description(wp_kses_post($data['description']));
         }
         // Update taxonomies.
         if (isset($data['attributes'])) {
             $attributes = array();
             $parent_attributes = $product->get_attributes();
             foreach ($data['attributes'] as $attribute) {
                 $attribute_id = 0;
                 $attribute_name = '';
                 // Check ID for global attributes or name for product attributes.
                 if (!empty($attribute['id'])) {
                     $attribute_id = absint($attribute['id']);
                     $attribute_name = wc_attribute_taxonomy_name_by_id($attribute_id);
                 } elseif (!empty($attribute['name'])) {
                     $attribute_name = sanitize_title($attribute['name']);
                 }
                 if (!$attribute_id && !$attribute_name) {
                     continue;
                 }
                 if (!isset($parent_attributes[$attribute_name]) || !$parent_attributes[$attribute_name]->get_variation()) {
                     continue;
                 }
                 $attribute_key = sanitize_title($parent_attributes[$attribute_name]->get_name());
                 $attribute_value = isset($attribute['option']) ? wc_clean(stripslashes($attribute['option'])) : '';
                 if ($parent_attributes[$attribute_name]->is_taxonomy()) {
                     // If dealing with a taxonomy, we need to get the slug from the name posted to the API.
                     $term = get_term_by('name', $attribute_value, $attribute_name);
                     if ($term && !is_wp_error($term)) {
                         $attribute_value = $term->slug;
                     } else {
                         $attribute_value = sanitize_title($attribute_value);
                     }
                 }
                 $attributes[$attribute_key] = $attribute_value;
             }
             $variation->set_attributes($attributes);
         }
         $variation->save();
         do_action('woocommerce_rest_save_product_variation', $variation->get_id(), $menu_order, $data);
     }
     return true;
 }
 /**
  * Add woovsi field to media uploader
  *
  * @param $form_fields array, fields to include in attachment form
  * @param $post object, attachment record in database
  * @return $form_fields, modified form fields
  */
 function woo_svi_field($form_fields, $post)
 {
     if (isset($_POST['post_id']) && $_POST['post_id'] != '0') {
         $wc = new WC_Product($_POST['post_id']);
         $att = $wc->get_attributes();
         //var_dump( $att );
         if (!empty($att)) {
             $current = get_post_meta($post->ID, 'woosvi_slug', true);
             $html = "<select name='attachments[{$post->ID}][woosvi-slug]' id='attachments[{$post->ID}][woosvi-slug]'>";
             $variations = false;
             $html .= "<option value='' " . selected($current, '', false) . ">none</option>";
             foreach ($att as $key => $attribute) {
                 if ($attribute['is_taxonomy']) {
                     $terms = wp_get_post_terms($_POST['post_id'], $key, 'all');
                     if (!empty($terms)) {
                         $variations = true;
                         foreach ($terms as $term) {
                             $html .= "<option value='" . $term->slug . "' " . selected($current, $term->slug, false) . ">" . $term->name . "</option>";
                         }
                     }
                 } else {
                     $values = str_replace(" ", "", $attribute['value']);
                     $terms = explode('|', $values);
                     if (!empty($terms)) {
                         $variations = true;
                         foreach ($terms as $term) {
                             $html .= "<option value='" . strtolower($term) . "' " . selected($current, strtolower($term), false) . ">" . $term . "</option>";
                         }
                     }
                 }
             }
             $html .= '</select>';
             if ($variations) {
                 $form_fields['woosvi-slug'] = array('label' => 'Variation', 'input' => 'html', 'html' => $html, 'application' => 'image', 'exclusions' => array('audio', 'video'), 'helps' => 'Choose the variation');
             } else {
                 $form_fields['woosvi-slug'] = array('label' => 'Variation', 'input' => 'html', 'html' => 'This product doesn\'t seem to be using any variations.', 'application' => 'image', 'exclusions' => array('audio', 'video'), 'helps' => 'Add variations to the product and Save');
             }
         }
     }
     return $form_fields;
 }
 /**
  * Get the attributes for a product or product variation
  *
  * @since 2.1
  * @param WC_Product|WC_Product_Variation $product
  * @return array
  */
 private function get_attributes($product)
 {
     $attributes = array();
     if ($product->is_type('variation')) {
         // variation attributes
         foreach ($product->get_variation_attributes() as $attribute_name => $attribute) {
             // taxonomy-based attributes are prefixed with `pa_`, otherwise simply `attribute_`
             $attributes[] = array('name' => ucwords(str_replace('attribute_', '', str_replace('pa_', '', $attribute_name))), 'option' => $attribute);
         }
     } else {
         foreach ($product->get_attributes() as $attribute) {
             $attributes[] = array('name' => ucwords(str_replace('pa_', '', $attribute['name'])), 'position' => $attribute['position'], 'visible' => (bool) $attribute['is_visible'], 'variation' => (bool) $attribute['is_variation'], 'options' => $this->get_attribute_options($product->get_id(), $attribute));
         }
     }
     return $attributes;
 }
function WooComposer_Single_style03($atts)
{
    $product_id = $product_style = $display_elements = $img_animate = $text_align = $color_heading = $color_categories = $color_price = '';
    $color_rating = $color_rating_bg = $color_quick_bg = $color_quick = $color_cart_bg = $color_cart = $color_product_desc = '';
    $color_product_desc_bg = $size_title = $size_cat = $size_price = $color_on_sale = $color_on_sale_bg = $label_on_sale = $border_style = '';
    $border_color = $border_size = $border_radius = $sale_price = $on_sale_alignment = $on_sale_style = $product_img_disp = '';
    extract(shortcode_atts(array("product_id" => "", "product_style" => "style01", "display_elements" => "", "label_on_sale" => "Sale!", "text_align" => "left", "img_animate" => "rotate-clock", "color_heading" => "", "color_categories" => "", "color_price" => "", "color_rating" => "", "color_rating_bg" => "", "color_quick_bg" => "", "color_quick" => "", "color_cart_bg" => "", "color_on_sale_bg" => "", "color_on_sale" => "", "color_cart" => "", "color_product_desc" => "", "color_product_desc_bg" => "", "size_title" => "", "size_cat" => "", "size_price" => "", "border_style" => "", "border_color" => "", "border_size" => "", "border_radius" => "", "sale_price" => "", "on_sale_style" => "wcmp-sale-circle", "on_sale_alignment" => "wcmp-sale-right", "product_img_disp" => "single"), $atts));
    $output = $heading_style = $cat_style = $price_style = $cart_style = $cart_bg_style = $view_style = $view_bg_style = $rating_style = '';
    $desc_style = $label_style = $border = $desc_style = $sale_price_size = '';
    $image_size = apply_filters('single_product_large_thumbnail_size', 'shop_single');
    if ($sale_price !== '') {
        $sale_price_size = 'font-size:' . $sale_price . 'px;';
    }
    $img_animate = 'wcmp-img-' . $img_animate;
    if ($border_style !== '') {
        $border .= 'border:' . $border_size . 'px ' . $border_style . ' ' . $border_color . ';';
        $border .= 'border-radius:' . $border_radius . 'px;';
    }
    if ($color_product_desc_bg !== '') {
        $desc_style .= 'background:' . $color_product_desc_bg . ';';
    }
    if ($color_product_desc !== '') {
        $desc_style .= 'color:' . $color_product_desc . ';';
    }
    if ($color_heading !== "") {
        $heading_style = 'color:' . $color_heading . ';';
    }
    if ($size_title !== "") {
        $heading_style .= 'font-size:' . $size_title . 'px;';
    }
    if ($color_categories !== "") {
        $cat_style = 'color:' . $color_categories . ';';
    }
    if ($size_cat !== "") {
        $cat_style .= 'font-size:' . $size_cat . 'px;';
    }
    if ($color_price !== "") {
        $price_style = 'color:' . $color_price . ';';
    }
    if ($size_price !== "") {
        $price_style .= 'font-size:' . $size_price . 'px;';
    }
    if ($color_rating !== "") {
        $rating_style .= 'color:' . $color_rating . ';';
    }
    if ($color_rating_bg !== "") {
        $rating_style .= 'background:' . $color_rating_bg . ';';
    }
    if ($color_quick_bg !== "") {
        $view_bg_style = 'background:' . $color_quick_bg . ';';
    }
    if ($color_quick !== "") {
        $view_style = 'color:' . $color_quick . ';';
    }
    if ($color_cart_bg !== "") {
        $cart_bg_style = 'background:' . $color_cart_bg . ';';
    }
    if ($color_cart !== "") {
        $cart_style = 'color:' . $color_cart . ';';
    }
    if ($color_on_sale_bg !== "") {
        $label_style = 'background:' . $color_on_sale_bg . ';';
    }
    if ($color_on_sale !== "") {
        $label_style .= 'color:' . $color_on_sale . ';';
    }
    $elemets = explode(",", $display_elements);
    $product_title = get_the_title($product_id);
    $post = get_post($product_id);
    $product_desc = get_post($product_id)->post_excerpt;
    $product_img = wp_get_attachment_image_src(get_post_thumbnail_id($product_id), $image_size);
    $product = new WC_Product($product_id);
    $attachment_ids = $product->get_gallery_attachment_ids();
    $price = $product->get_price_html();
    $rating = $product->get_rating_html();
    $attributes = $product->get_attributes();
    $stock = $product->is_in_stock() ? 'InStock' : 'OutOfStock';
    if ($product->is_on_sale()) {
        $on_sale = apply_filters('woocommerce_sale_flash', $label_on_sale, $post, $product);
    } else {
        $on_sale = '';
    }
    $cat_count = sizeof(get_the_terms($product_id, 'product_cat'));
    $tag_count = sizeof(get_the_terms($product_id, 'product_tag'));
    $categories = $product->get_categories(', ', '<span class="posted_in">' . _n('', '', $cat_count, 'woocommerce') . ' ', '.</span>');
    $tags = $product->get_tags(', ', '<span class="tagged_as">' . _n('', '', $tag_count, 'woocommerce') . ' ', '.</span>');
    $output .= "\n" . '<div class="wcmp-product woocommerce wcmp-' . $product_style . ' ' . $img_animate . '" style="' . $border . ' ' . $desc_style . '">';
    $output .= "\n\t" . '<div class="wcmp-product-image">';
    if (!empty($attachment_ids) && count($attachment_ids) > 1 && $product_img_disp == "carousel") {
        $uniqid = uniqid();
        $output .= '<div class="wcmp-single-image-carousel">';
        $product_img = wp_get_attachment_image_src(get_post_thumbnail_id($product_id), $image_size);
        $src = $product_img[0];
        $output .= '<div><div class="wcmp-image"><img class="wcmp-img" src="' . $src . '" data-src="' . $product_img[0] . '"/></div></div>';
        foreach ($attachment_ids as $attachment_id) {
            $product_img = wp_get_attachment_image_src($attachment_id, $image_size);
            $output .= '<div><div class="wcmp-image"><img class="wcmp-img" src="' . $src . '" data-src="' . $product_img[0] . '"/></div></div>';
        }
        $output .= '</div>';
    } else {
        $product_img = wp_get_attachment_image_src(get_post_thumbnail_id($product_id), $image_size);
        $src = $product_img[0];
        $output .= '<a href="' . get_permalink($product_id) . '"><img class="wcmp-img" src="' . $src . '" data-src="' . $product_img[0] . '"/></a>';
    }
    if ($on_sale !== '') {
        $output .= "\n" . '<div class="wcmp-onsale ' . $on_sale_alignment . ' ' . $on_sale_style . '"><span class="onsale" style="' . $label_style . ' ' . $sale_price_size . '">' . $on_sale . '</span></div>';
    }
    if ($stock == 'OutOfStock') {
        $output .= "\n" . '<span class="wcmp-out-stock">' . __('Out Of Stock!', 'woocomposer') . '</span>';
    }
    $output .= '</div>';
    $output .= "\n\t" . '<div class="wcmp-product-desc">';
    $output .= '<a href="' . get_permalink($product_id) . '">';
    $output .= "\n\t\t" . '<h2 style="' . $heading_style . '">' . $product_title . '</h2>';
    $output .= '</a>';
    if (in_array("category", $elemets)) {
        $output .= '<h5 style="' . $cat_style . '">';
        if ($categories !== '') {
            $output .= $categories;
            $output .= $tags;
        }
        $output .= '</h5>';
    }
    $output .= "\n\t\t" . '<div class="wcmp-price"><span class="price" style="' . $price_style . '">' . $price . '</span></div>';
    $output .= '<div class="wcmp-style3-cart-block">';
    /*Class Start wcmp-style3-cart-block*/
    $output .= '<div class="wcmp-add-to-cart" style="' . $cart_bg_style . '"><a style="' . $cart_style . '" title="Add to Cart" href="?add-to-cart=' . $product_id . '" rel="nofollow" data-product_id="' . $product_id . '" data-product_sku="" class="button add_to_cart_button product_type_simple">Add to Cart</a></div>';
    if (in_array("reviews", $elemets)) {
        $output .= "\n" . '<div class="wcmp-star-ratings" style="' . $rating_style . '">' . $rating . '</div>';
    }
    if (in_array("quick", $elemets)) {
        $output .= '<div class="wcmp-quick-view quick-view-single" style="' . $view_bg_style . '"><a style="' . $view_style . '" title="Quick View" href="' . get_permalink($product_id) . '"><i class="wooicon-plus32"></i></a></div>';
    }
    $output .= '</div>';
    /*Class End wcmp-style3-cart-block*/
    if (in_array("description", $elemets)) {
        $output .= "\n\t\t" . '<div class="wcmp-product-content" style="' . $desc_style . '">' . $product_desc . '</div>';
    }
    if (in_array("quick", $elemets)) {
        $query = new WP_Query(array('post_type' => 'product', 'post__in' => array($product_id)));
        if ($query->have_posts()) {
            while ($query->have_posts()) {
                $query->the_post();
                $output .= '<div class="wcmp-quick-view-wrapper">';
                $output .= '<div class="wcmp-quick-view-wrapper woocommerce">';
                $output .= '<div class="wcmp-close-single"><i class="wooicon-cross2"></i></div>';
                if (!empty($attachment_ids) && count($attachment_ids) > 1) {
                    $uniqid = uniqid();
                    $output .= '<div class="wcmp-image-carousel wcmp-carousel-' . $uniqid . '" data-class="wcmp-carousel-' . $uniqid . '">';
                    foreach ($attachment_ids as $attachment_id) {
                        $product_img = wp_get_attachment_image_src($attachment_id, $image_size);
                        $output .= '<div><div class="wcmp-image"><img src="' . $product_img[0] . '"/></div></div>';
                    }
                    $output .= '</div>';
                } else {
                    $product_img = wp_get_attachment_image_src(get_post_thumbnail_id($product_id), $image_size);
                    $output .= '<div class="wcmp-single-image"><img src="' . $product_img[0] . '"/></div>';
                }
                $output .= '<div class="wcmp-product-content-single">';
                ob_start();
                do_action('woocommerce_single_product_summary');
                $output .= ob_get_clean();
                $output .= '</div>';
                $output .= '<div class="clear"></div>';
                $output .= '</div>';
                $output .= '</div>';
            }
        }
    }
    $output .= "\n\t" . '</div>';
    $output .= "\n\t" . '</div>';
    return $output;
}
 /**
  * Get the attributes for a product or product variation
  *
  * @since 2.1
  * @param WC_Product|WC_Product_Variation $product
  * @return array
  */
 private function get_attributes($product)
 {
     $attributes = array();
     if ($product->is_type('variation')) {
         // variation attributes
         foreach ($product->get_variation_attributes() as $attribute_name => $attribute) {
             // taxonomy-based attributes are prefixed with `pa_`, otherwise simply `attribute_`
             $attributes[] = array('name' => wc_attribute_label(str_replace('attribute_', '', $attribute_name)), 'slug' => str_replace('attribute_', '', str_replace('pa_', '', $attribute_name)), 'option' => $attribute);
         }
     } else {
         foreach ($product->get_attributes() as $attribute) {
             // taxonomy-based attributes are comma-separated, others are pipe (|) separated
             if ($attribute['is_taxonomy']) {
                 $options = explode(',', $product->get_attribute($attribute['name']));
             } else {
                 $options = explode('|', $product->get_attribute($attribute['name']));
             }
             $attributes[] = array('name' => wc_attribute_label($attribute['name']), 'slug' => str_replace('pa_', '', $attribute['name']), 'position' => (int) $attribute['position'], 'visible' => (bool) $attribute['is_visible'], 'variation' => (bool) $attribute['is_variation'], 'options' => array_map('trim', $options));
         }
     }
     return $attributes;
 }
Example #23
0
/**
 * Build a Google Shopping Content Product from a WC Product
 * @param WC_Product $wc_product
 * @return Google_Service_ShoppingContent_Product
 */
function woogle_build_product($wc_product)
{
    // Create Google Shopping Content Product
    require_once plugin_dir_path(woogle_get_plugin_file()) . 'vendor/google-api-php-client/src/Google/Service/ShoppingContent.php';
    $product = new Google_Service_ShoppingContent_Product();
    // Custom Attributes
    $product_custom_attributes = array();
    // Product identifiers
    $sku = $wc_product->get_sku();
    if (empty($sku)) {
        if ($wc_product->is_type('variation')) {
            $product->setOfferId($wc_product->variation_id);
        } else {
            $product->setOfferId($wc_product->id);
        }
    } else {
        $product->setOfferId($sku);
    }
    if ($wc_product->is_type('variation')) {
        $product->setItemGroupId($wc_product->parent->id);
    }
    $woocommerce_id_attribute = new Google_Service_ShoppingContent_ProductCustomAttribute();
    $woocommerce_id_attribute->setName('woocommerce_id');
    $woocommerce_id_attribute->setValue($wc_product->id);
    $woocommerce_id_attribute->setType('int');
    $product_custom_attributes[] = $woocommerce_id_attribute;
    // Title
    $woogle_title = get_post_meta($wc_product->id, '_woogle_title', true);
    if (!empty($woogle_title)) {
        $product->setTitle(html_entity_decode(strip_tags($woogle_title)));
    } else {
        $product->setTitle(html_entity_decode(strip_tags($wc_product->get_title())));
    }
    // Description
    $woogle_description = get_post_meta($wc_product->id, '_woogle_description', true);
    if (!empty($woogle_description)) {
        $product->setDescription(html_entity_decode(strip_tags($woogle_description)));
    } else {
        $product->setDescription(html_entity_decode(strip_tags($wc_product->post->post_content)));
    }
    $product->setLink($wc_product->get_permalink());
    $image = $wc_product->get_image();
    $post_thumbnail_id = get_post_thumbnail_id($wc_product->id);
    if ($post_thumbnail_id) {
        $image_src = wp_get_attachment_image_src($post_thumbnail_id);
        $product->setImageLink(@$image_src[0]);
    }
    $product->setContentLanguage(substr(get_locale(), 0, 2));
    $product->setTargetCountry(WC()->countries->get_base_country());
    $product->setChannel('online');
    $product->setAvailability($wc_product->is_in_stock() ? 'in stock' : 'out of stock');
    // Condition
    $condition = get_post_meta($wc_product->id, '_woogle_condition', true);
    if (!empty($condition)) {
        $product->setCondition($condition);
    } else {
        $product->setcondition('new');
    }
    // Category
    $category = get_post_meta($wc_product->id, '_woogle_category', true);
    if (!empty($category)) {
        $product->setGoogleProductCategory($category);
    }
    // Brand
    $brand = get_post_meta($wc_product->id, '_woogle_brand', true);
    if (!empty($brand)) {
        $product->setBrand($brand);
    }
    // GTIN
    $gtin = get_post_meta($wc_product->id, '_woogle_gtin', true);
    if (!empty($gtin)) {
        $product->setGtin($gtin);
    }
    // MPN
    $mpn = get_post_meta($wc_product->id, '_woogle_mpn', true);
    if (!empty($mpn)) {
        $product->setMpn($mpn);
    }
    if (empty($gtin) && empty($mpn)) {
        $product->setIdentifierExists(false);
    }
    // Price
    $price = new Google_Service_ShoppingContent_Price();
    $price->setValue($wc_product->get_regular_price());
    $price->setCurrency(get_woocommerce_currency());
    $product->setPrice($price);
    // Sale price
    $wc_sale_price = $wc_product->get_sale_price();
    if (!empty($wc_sale_price)) {
        $sale_price = new Google_Service_ShoppingContent_Price();
        $sale_price->setValue($wc_sale_price);
        $sale_price->setCurrency(get_woocommerce_currency());
        $product->setSalePrice($sale_price);
        $post_id = $wc_product->is_type('variation') ? $wc_product->variation_id : $wc_product->id;
        $sale_price_dates_from = get_post_meta($post_id, '_sale_price_dates_from', true);
        $sale_price_dates_to = get_post_meta($post_id, '_sale_price_dates_to', true);
        if (!empty($sale_price_dates_from) && !empty($sale_price_dates_to)) {
            $effective_date_start = date('c', intval($sale_price_dates_from));
            $effective_date_end = date('c', intval($sale_price_dates_to));
            $product->setSalePriceEffectiveDate("{$effective_date_start}/{$effective_date_end}");
        }
    }
    // Shipping fields
    // Shipping weight
    $wc_product_weight = $wc_product->get_weight();
    if (!empty($wc_product_weight)) {
        $shipping_weight = new Google_Service_ShoppingContent_ProductShippingWeight();
        $shipping_weight->setValue($wc_product_weight);
        $shipping_weight->setUnit(get_option('woocommerce_weight_unit', 'kg'));
        $product->setShippingWeight($shipping_weight);
    }
    // Shipping dimensions
    $wc_dimension_unit = get_option('woocommerce_dimension_unit', 'cm');
    $wc_product_length = $wc_product->get_length();
    if (!empty($wc_product_length)) {
        $dimension = new Google_Service_ShoppingContent_ProductShippingDimension();
        $dimension->setValue($wc_product_length);
        $dimension->setUnit($wc_dimension_unit);
        $product->setShippingLength($dimension);
    }
    $wc_product_width = $wc_product->get_width();
    if (!empty($wc_product_width)) {
        $dimension = new Google_Service_ShoppingContent_ProductShippingDimension();
        $dimension->setValue($wc_product_width);
        $dimension->setUnit($wc_dimension_unit);
        $product->setShippingWidth($dimension);
    }
    $wc_product_height = $wc_product->get_height();
    if (!empty($wc_product_height)) {
        $dimension = new Google_Service_ShoppingContent_ProductShippingDimension();
        $dimension->setValue($wc_product_height);
        $dimension->setUnit($wc_dimension_unit);
        $product->setShippingHeight($dimension);
    }
    // Attributes
    $color = null;
    $material = null;
    $pattern = null;
    $size = null;
    $age_group = null;
    $gender = null;
    $adult = null;
    if ($wc_product->is_type('variation')) {
        // Variable product
        $wc_variation_attributes = $wc_product->get_variation_attributes();
        foreach ($wc_variation_attributes as $name => $value) {
            if (!empty($value)) {
                $attribute = new Google_Service_ShoppingContent_ProductCustomAttribute();
                $attribute->setName($name);
                $attribute->setValue($value);
                $attribute->setType('text');
                $product_custom_attributes[] = $attribute;
                // Google attributes
                if (empty($color)) {
                    $color = woogle_maybe_get_attribute('color', $name, $value);
                }
                if (empty($material)) {
                    $material = woogle_maybe_get_attribute('material', $name, $value);
                }
                if (empty($pattern)) {
                    $pattern = woogle_maybe_get_attribute('pattern', $name, $value);
                }
                if (empty($size)) {
                    $size = woogle_maybe_get_attribute('size', $name, $value);
                }
                if (empty($age_group)) {
                    $age_group = woogle_maybe_get_attribute('age-group', $name, $value);
                }
                if (empty($gender)) {
                    $gender = woogle_maybe_get_attribute('gender', $name, $value);
                }
                if (empty($adult)) {
                    $adult = woogle_maybe_get_attribute('adult', $name, $value);
                }
            }
        }
    } else {
        // Simple product
        $wc_attributes = $wc_product->get_attributes();
        foreach ($wc_attributes as $name => $wc_attribute) {
            if ($wc_attribute['is_taxonomy']) {
                $term_values = array();
                $terms = wp_get_post_terms($wc_product->id, $name);
                foreach ($terms as $term) {
                    $term_values[] = $term->slug;
                }
                if (!empty($term_values)) {
                    $value = implode(',', $term_values);
                    $attribute = new Google_Service_ShoppingContent_ProductCustomAttribute();
                    $attribute->setName($name);
                    $attribute->setValue($value);
                    $attribute->setType('text');
                    $product_custom_attributes[] = $attribute;
                    // Google attributes
                    if (empty($color)) {
                        $color = woogle_maybe_get_attribute('color', $name, $value);
                    }
                    if (empty($material)) {
                        $material = woogle_maybe_get_attribute('material', $name, $value);
                    }
                    if (empty($pattern)) {
                        $pattern = woogle_maybe_get_attribute('pattern', $name, $value);
                    }
                    if (empty($size)) {
                        $size = woogle_maybe_get_attribute('size', $name, $value);
                    }
                    if (empty($age_group)) {
                        $age_group = woogle_maybe_get_attribute('age-group', $name, $value);
                    }
                    if (empty($gender)) {
                        $gender = woogle_maybe_get_attribute('gender', $name, $value);
                    }
                    if (empty($adult)) {
                        $adult = woogle_maybe_get_attribute('adult', $name, $value);
                    }
                }
            }
        }
    }
    /*
     * Physical properties
     */
    // Color
    if (empty($color)) {
        $color = get_post_meta($wc_product->id, '_woogle_color', true);
    }
    if (!empty($color)) {
        $product->setColor($color);
    }
    // Material
    if (empty($material)) {
        $material = get_post_meta($wc_product->id, '_woogle_material', true);
    }
    if (!empty($material)) {
        $product->setMaterial($material);
    }
    // Pattern
    if (empty($pattern)) {
        $pattern = get_post_meta($wc_product->id, '_woogle_pattern', true);
    }
    if (!empty($pattern)) {
        $product->setPattern($pattern);
    }
    // Size
    if (empty($size)) {
        $size = get_post_meta($wc_product->id, '_woogle_size', true);
    }
    if (!empty($size)) {
        $product->setSizes(explode(', ', $size));
        $product->setSizeSystem(WC()->countries->get_base_country());
    }
    /*
     * Target consumer
     */
    // Age Group
    if (empty($age_group)) {
        $age_group = get_post_meta($wc_product->id, '_woogle_age_group', true);
    }
    if (!empty($age_group)) {
        $product->setAgeGroup($age_group);
    }
    // Gender
    if (empty($gender)) {
        $gender = get_post_meta($wc_product->id, '_woogle_gender', true);
    }
    if (!empty($gender)) {
        $product->setGender($gender);
    }
    // Gender
    if (empty($adult)) {
        $adult = get_post_meta($wc_product->id, '_woogle_adult', true);
    }
    if (!empty($adult) && $adult != 'no') {
        $product->setAdult(true);
    }
    $product->setCustomAttributes($product_custom_attributes);
    return $product;
}