/** * Gte woocommerce data for product * * @param $value * @param $data * * @return string */ function vc_gitem_template_attribute_woocommerce_product($value, $data) { $label = ''; /** * @var null|Wp_Post $post ; * @var string $data ; */ extract(array_merge(array('post' => null, 'data' => ''), $data)); require_once WC()->plugin_path() . '/includes/abstracts/abstract-wc-product.php'; $product = new WC_Product($post); if (preg_match('/_labeled$/', $data)) { $data = preg_replace('/_labeled$/', '', $data); $label = apply_filters('vc_gitem_template_attribute_woocommerce_product_' . $data . '_label', Vc_Vendor_Woocommerce::getProductFieldLabel($data) . ': '); } $price_format = get_woocommerce_price_format(); switch ($data) { case 'id': $value = (int) $product->is_type('variation') ? $product->get_variation_id() : $product->id; break; case 'sku': $value = $product->get_sku(); break; case 'price': $value = sprintf($price_format, wc_format_decimal($product->get_price(), 2), get_woocommerce_currency()); break; case 'regular_price': $value = sprintf($price_format, wc_format_decimal($product->get_regular_price(), 2), get_woocommerce_currency()); break; case 'sale_price': $value = sprintf(get_woocommerce_price_format(), $product->get_sale_price() ? wc_format_decimal($product->get_sale_price(), 2) : '', get_woocommerce_currency()); break; case 'price_html': $value = $product->get_price_html(); break; case 'reviews_count': $value = count(get_comments(array('post_id' => $post->ID, 'approve' => 'approve'))); break; case 'short_description': $value = apply_filters('woocommerce_short_description', $product->get_post_data()->post_excerpt); break; case 'dimensions': $units = get_option('woocommerce_dimension_unit'); $value = $product->length . $units . 'x' . $product->width . $units . 'x' . $product->height . $units; break; case 'raiting_count': $value = $product->get_rating_count(); break; case 'weight': $value = $product->get_weight() ? wc_format_decimal($product->get_weight(), 2) : ''; break; case 'on_sale': $value = $product->is_on_sale() ? 'yes' : 'no'; // @todo change break; default: $value = $product->{$data}; } return strlen($value) > 0 ? $label . apply_filters('vc_gitem_template_attribute_woocommerce_product_' . $data . '_value', $value) : ''; }
/** * Get standard product data that applies to every product type * * @since 2.1 * @param WC_Product $product * @return array */ private function get_product_data($product) { return array('title' => $product->get_name(), 'id' => $product->get_id(), 'created_at' => $this->server->format_datetime($product->get_date_created(), false, true), 'updated_at' => $this->server->format_datetime($product->get_date_modified(), false, true), 'type' => $product->get_type(), 'status' => $product->get_status(), 'downloadable' => $product->is_downloadable(), 'virtual' => $product->is_virtual(), 'permalink' => $product->get_permalink(), 'sku' => $product->get_sku(), 'price' => wc_format_decimal($product->get_price(), 2), 'regular_price' => wc_format_decimal($product->get_regular_price(), 2), 'sale_price' => $product->get_sale_price() ? wc_format_decimal($product->get_sale_price(), 2) : null, 'price_html' => $product->get_price_html(), 'taxable' => $product->is_taxable(), 'tax_status' => $product->get_tax_status(), 'tax_class' => $product->get_tax_class(), 'managing_stock' => $product->managing_stock(), 'stock_quantity' => $product->get_stock_quantity(), 'in_stock' => $product->is_in_stock(), 'backorders_allowed' => $product->backorders_allowed(), 'backordered' => $product->is_on_backorder(), 'sold_individually' => $product->is_sold_individually(), 'purchaseable' => $product->is_purchasable(), 'featured' => $product->is_featured(), 'visible' => $product->is_visible(), 'catalog_visibility' => $product->get_catalog_visibility(), 'on_sale' => $product->is_on_sale(), 'weight' => $product->get_weight() ? wc_format_decimal($product->get_weight(), 2) : null, 'dimensions' => array('length' => $product->get_length(), 'width' => $product->get_width(), 'height' => $product->get_height(), 'unit' => get_option('woocommerce_dimension_unit')), 'shipping_required' => $product->needs_shipping(), 'shipping_taxable' => $product->is_shipping_taxable(), 'shipping_class' => $product->get_shipping_class(), 'shipping_class_id' => 0 !== $product->get_shipping_class_id() ? $product->get_shipping_class_id() : null, 'description' => apply_filters('the_content', $product->get_description()), 'short_description' => apply_filters('woocommerce_short_description', $product->get_short_description()), 'reviews_allowed' => $product->get_reviews_allowed(), 'average_rating' => wc_format_decimal($product->get_average_rating(), 2), 'rating_count' => $product->get_rating_count(), 'related_ids' => array_map('absint', array_values(wc_get_related_products($product->get_id()))), 'upsell_ids' => array_map('absint', $product->get_upsell_ids()), 'cross_sell_ids' => array_map('absint', $product->get_cross_sell_ids()), 'categories' => wc_get_object_terms($product->get_id(), 'product_cat', 'name'), 'tags' => wc_get_object_terms($product->get_id(), 'product_tag', 'name'), 'images' => $this->get_images($product), 'featured_src' => wp_get_attachment_url(get_post_thumbnail_id($product->get_id())), 'attributes' => $this->get_attributes($product), 'downloads' => $this->get_downloads($product), 'download_limit' => $product->get_download_limit(), 'download_expiry' => $product->get_download_expiry(), 'download_type' => 'standard', 'purchase_note' => apply_filters('the_content', $product->get_purchase_note()), 'total_sales' => $product->get_total_sales(), 'variations' => array(), 'parent' => array()); }
protected function get_name(WC_Product $product) { if ($product->get_sku()) { $identifier = $product->get_sku(); } else { $identifier = '#' . (isset($product->variation_id) ? $product->variation_id : $product->id); } return sprintf('%s - %s', $identifier, $product->get_title()); }
/** * @param array $items * * @return array */ public static function get_articles($items) { $articles = array(); foreach ($items as $item => $values) { $product = new WC_Product($values['product_id']); $tax_rate = 100 * ($values['line_tax'] / $values['line_total']); $articles[] = array('id' => $values['product_id'], 'sku' => $product->get_sku(), 'name' => $values['name'], 'description' => $product->get_post_data()->post_content, 'url' => $product->get_permalink(), 'image_url' => wp_get_attachment_url(get_post_thumbnail_id($values['product_id'])), 'quantity' => (int) $values['qty'], 'price' => Aplazame_Filters::decimals($values['line_total']) / (int) $values['qty'], 'tax_rate' => Aplazame_Filters::decimals($tax_rate)); } return $articles; }
/** * Build the line items hash * @param array $items */ function build_line_items($items) { $line_items = array(); foreach ($items as $item) { $productmeta = new WC_Product($item['product_id']); $sku = $productmeta->get_sku(); $line_items = array_merge($line_items, array(array('name' => $item['name'], 'unit_price' => floatval($item['line_total']) * 100, 'description' => $item['name'], 'quantity' => $item['qty'], 'sku' => $sku, 'type' => $item['type']))); } return $line_items; }
function export_products() { $api_key = get_option('pixelshop_key'); $path = apply_filters('pixelshop/get_info', 'path'); include_once $path . 'core/api.php'; if (isset($_POST['nonce']) && wp_verify_nonce($_POST['nonce'], 'export_products') && $api_key !== false) { $api = new API($api_key); $args = array('post_type' => 'product', 'orderby' => $orderby, 'post_status' => 'publish', 'posts_per_page' => -1); $the_query = new WP_Query($args); $products = []; $i = 0; while ($the_query->have_posts()) { $i++; $the_query->the_post(); $product = new WC_Product($the_query->post->ID); $thumb = wp_get_attachment_image_src(get_post_thumbnail_id($the_query->post->ID), array(250, 250)); $products[$i] = ["sync_id" => $the_query->post->ID, "link" => get_permalink($the_query->post->ID), "title" => get_the_title(), "description" => get_the_excerpt(), "price" => $product->get_price(), "sku" => $product->get_sku(), "thumb" => $thumb[0], "tags" => '']; if (!isset($product->get_tags()->errors)) { $tags = wp_get_object_terms($the_query->post->ID, 'product_tag'); $tags_list = ''; foreach ($tags as $tag) { $tags_list .= $tag->name . ', '; } $products[$i]["tags"] = substr($tags_list, 0, -2); } } $export = $api->export->products($products); if (isset($export['error'])) { add_action('admin_notices', array($this, 'api_key_invalid')); } else { add_option('pixelshop_message', $export, '', 'yes'); $time = 60 * 60 * 24; if (get_option('pxs_last_export') === false) { add_option('pxs_last_export', time() + $time, '', 'no'); } else { update_option('pxs_last_export', time() + $time); } } } }
/** * Get the order data format for a single column for all line items, compatible with the legacy (pre 3.0) CSV Export format * * Note this code was adapted from the old code to maintain compatibility as close as possible, so it should * not be modified unless absolutely necessary * * @since 3.0 * @param array $order_data an array of order data for the given order * @param WC_Order $order the WC_Order object * @return array modified order data */ private function get_legacy_single_column_line_item($order_data, WC_Order $order) { $line_items = array(); foreach ($order->get_items() as $_ => $item) { $product = $order->get_product_from_item($item); if (!is_object($product)) { $product = new WC_Product(0); } $line_item = $item['name']; if ($product->get_sku()) { $line_item .= ' (' . $product->get_sku() . ')'; } $line_item .= ' x' . $item['qty']; $item_meta = new WC_Order_Item_Meta($item); $variation = $item_meta->display(true, true); if ($variation) { $line_item .= ' - ' . str_replace(array("\r", "\r\n", "\n"), '', $variation); } $line_items[] = str_replace(array('“', '”'), '', $line_item); } $order_data['order_items'] = implode('; ', $line_items); // convert country codes to full name if (isset(WC()->countries->countries[$order->billing_country])) { $order_data['billing_country'] = WC()->countries->countries[$order->billing_country]; } if (isset(WC()->countries->countries[$order->shipping_country])) { $order_data['shipping_country'] = WC()->countries->countries[$order->shipping_country]; } // set order ID to order number $order_data['order_id'] = ltrim($order->get_order_number(), _x('#', 'hash before the order number', 'woocommerce-customer-order-csv-export')); return $order_data; }
$first = isset($ourOrder->billing_first_name) ? $ourOrder->billing_first_name : '1'; $last = isset($ourOrder->billing_last_name) ? $ourOrder->billing_last_name : '1'; $customerEmail = isset($ourOrder->billing_email) ? $ourOrder->billing_email : '1'; $orderTotal = isset($ourOrder->order_total) ? $ourOrder->order_total : '1'; $orderDate = isset($ourOrder->order_date) ? $ourOrder->order_date : '1'; $items = $ourOrder->get_items(); //$discounts = isset($ourOrder->get_total_discount()) ? $ourOrder->get_total_discount() : '1'; $authProfile = isset($ourOrder->wc_authorize_net_cim_customer_profile_id) ? $ourOrder->wc_authorize_net_cim_customer_profile_id : '1'; /* * The below foreach will pull the items array apart and process each item, finding its SKU and adding them to a comma separated list. */ foreach ($items as $item) { $id = ''; $id = isset($item['item_meta']['_variation_id']) ? $item['item_meta']['_variation_id'][0] : $item['item_meta']['_product_id'][0]; $item = new WC_Product($id); $skus[] = $item->get_sku(); } var_dump($skus); $orderItems = implode($skus, ","); $params = array('order_Id' => $orderID->ID, 'user_id' => $customerUser, 'subscription_id' => $subscriptionID, 'name' => $first . " " . $last, 'date' => date('Y-m-d', strtotime($orderDate)), 'email' => $customerEmail, 'products' => $orderItems, 'order_total' => $orderTotal, 'auth_profile' => $authProfile, 'address' => $ourOrder->get_formatted_shipping_address()); $wpdb->insert($wpdb->prefix . 'orders_archived', $params); /* * This is the scary part of the plugin. While active, the below few lines will delete the original orders from the many * tables found in both wordpress and woocommerce after saving the important information to the archived orders table. */ //if ($_GET['delete']) { if ($_POST['delete']) { wp_delete_post($orderID->ID); $wpdb->delete($wpdb->prefix . 'woocommerce_order_items', array("order_item_id" => $orderID->ID)); $wpdb->delete($wpdb->prefix . 'woocommerce_order_itemmeta', array("order_item_id" => $orderID->ID)); }
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; }
public function wa_wps_display_slider() { global $wpdb, $post; $display_image = $this->options['settings']['display_image']; $word_limit = $this->options['settings']['word_limit']; $number_of_posts_to_display = $this->options['settings']['number_of_posts_to_display']; $posts_order = $this->options['settings']['posts_order']; $posts_orderby = $this->options['settings']['posts_orderby']; $category = $this->options['settings']['category']; $display_pagination = $this->options['settings']['display_pagination']; $display_excerpt = $this->options['settings']['display_excerpt']; $display_title = $this->options['settings']['display_title']; $display_read_more = $this->options['settings']['display_read_more']; $read_more_text = $this->options['settings']['read_more_text']; $display_controls = $this->options['settings']['display_controls']; $auto_scroll = $this->options['settings']['auto_scroll']; $fx = $this->options['settings']['fx']; $item_width = $this->options['settings']['item_width']; $item_height = $this->options['settings']['item_height']; $align_items = $this->options['settings']['item_align']; $infinite = $this->options['settings']['infinite']; $excerpt_type = $this->options['settings']['excerpt_type']; $touch_swipe = $this->options['settings']['touch_swipe']; $arrows_colour = $this->options['settings']['arrows_colour']; $arrows_bg_colour = $this->options['settings']['arrows_bg_colour']; $arrows_hover_colour = $this->options['settings']['arrows_hover_colour']; $size_of_direction_arrows = $this->options['settings']['size_of_direction_arrows']; $css_transition = $this->options['settings']['css_transition']; $timeout = $this->options['settings']['timeout']; $direction = $this->options['settings']['direction']; $custom_css = $this->options['settings']['custom_css']; $image_size = $this->options['settings']['image_size']; $display_price = $this->options['settings']['display_price']; $display_add_to_cart = $this->options['settings']['display_add_to_cart']; ?> <style> <?php if (!empty($custom_css)) { echo $custom_css; } ?> .wps_foo_content img { max-width: <?php echo $item_width; ?> ; } .wps_image_carousel .wps_prev, .wps_image_carousel .wps_next{ background: <?php echo $arrows_bg_colour; ?> ; color: <?php echo $arrows_colour; ?> ; font-size: <?php echo $size_of_direction_arrows; ?> px; line-height: <?php echo $size_of_direction_arrows + 7; ?> px; width: <?php echo $size_of_direction_arrows + 10; ?> px; height: <?php echo $size_of_direction_arrows + 10; ?> px; margin-top: -<?php echo $size_of_direction_arrows; ?> px; } .wps_image_carousel.wps_prev:hover, .wps_image_carousel .wps_next:hover { color: <?php echo $arrows_hover_colour; ?> ; } #wa_wps_pager a { background: <?php echo $arrows_hover_colour; ?> ; } </style> <?php $slider_gallery = ''; $slider_gallery .= '<div class="wps_image_carousel">'; $slider_gallery .= '<div id="wa_chpc_slider" style="height:' . $item_height . 'px; overflow: hidden;">'; if ($posts_order == "rand") { $posts_orderby = "rand"; } $args_custom = array('posts_per_page' => $number_of_posts_to_display, 'post_type' => 'product', 'order' => $posts_order, 'orderby' => $posts_orderby, 'post_status' => 'publish', 'tax_query' => array(array('taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => $category))); $myposts = get_posts($args_custom); foreach ($myposts as $post) { $post_title = $post->post_title; $post_link = get_permalink($post->ID); $post_content = strip_shortcodes($post->post_content); $text_type = $this->get_text_type($post, $excerpt_type); //woocommerce get data if (function_exists('get_product')) { $_product = get_product($post->ID); } else { $_product = new WC_Product($post->ID); } $slider_gallery .= '<div class="wps_foo_content" style="width:' . $item_width . 'px; height:' . $item_height . 'px;">'; if ($display_image) { $slider_gallery .= '<span class="wps_img"><a href="' . $post_link . '">' . $this->get_post_image($post->ID, $image_size) . '</a></span>'; } //Post title, Post Description, Post read more if ($display_title) { $slider_gallery .= '<br/><span class="wps_title"><a style=" text-decoration:none;" href="' . $post_link . '">' . $post_title . '</a></span><br/>'; } if ($display_excerpt) { $slider_gallery .= '<p><span class="wps_foo_con">' . $this->wa_wps_clean($text_type, $word_limit) . '</span></p>'; } if ($display_read_more) { $slider_gallery .= '<br/><span class="wps_more"><a href="' . $post_link . '">' . $read_more_text . '</a></span>'; } //display price if ($display_price) { $slider_gallery .= '<div class="wa_wps_price">' . $_product->get_price_html() . '</div>'; } //display add to cart if ($display_add_to_cart) { $slider_gallery .= '<div class="wa_wps_add_to_cart"><a rel="nofollow" data-product_id="' . $post->ID . '" data-product_sku="' . $_product->get_sku() . '" class="wa_wps_button add_to_cart_button product_type_simple" href="' . do_shortcode('[add_to_cart_url id="' . $post->ID . '"]') . '">Add to cart</a></div>'; } $slider_gallery .= '</div>'; } $slider_gallery .= '</div>'; $slider_gallery .= '<div class="wps_clearfix"></div>'; if ($display_controls) { $slider_gallery .= '<a class="wps_prev" id="wa_chpc_slider_prev" href="#"><span>‹</span></a>'; $slider_gallery .= '<a class="wps_next" id="wa_chpc_slider_next" href="#"><span>›</span></a>'; } if ($display_pagination) { $slider_gallery .= '<div class="wps_pagination" id="wa_wps_pager"></div>'; } $slider_gallery .= '</div>'; wp_reset_postdata(); return $slider_gallery; }
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; }
/** * Ajax callback to search for products. * @param string $query Search Query. * @since 1.2.0 * @return json Search Results. */ public function get_products_callback() { check_ajax_referer('projects_ajax_get_products', 'security'); $term = urldecode(stripslashes(strip_tags($_GET['term']))); if (!empty($term)) { header('Content-Type: application/json; charset=utf-8'); $query_args = array('post_type' => 'product', 'orderby' => 'title', 's' => $term, 'suppress_filters' => false); $products = get_posts($query_args); $found_products = array(); if ($products) { foreach ($products as $product) { $_product = new WC_Product($product->ID); if ($_product->get_sku()) { $identifier = $_product->get_sku(); } else { $identifier = '#' . $_product->id; } $found_products[] = array('id' => $product->ID, 'title' => $product->post_title, 'identifier' => $identifier); } } echo json_encode($found_products); } die; }
function woocommerce_custom_product_columns($column) { global $post, $woocommerce; $product = new WC_Product($post->ID); switch ($column) { case "thumb": $product->get_image(); break; case "name": $edit_link = get_edit_post_link($post->ID); $title = _draft_or_post_title(); $post_type_object = get_post_type_object($post->post_type); $can_edit_post = current_user_can($post_type_object->cap->edit_post, $post->ID); echo '<strong><a class="row-title" href="' . $edit_link . '">' . $title . '</a>'; _post_states($post); echo '</strong>'; if ($post->post_parent > 0) { echo ' ← <a href="' . get_edit_post_link($post->post_parent) . '">' . get_the_title($post->post_parent) . '</a>'; } // Excerpt view if (isset($_GET['mode']) && $_GET['mode'] == 'excerpt') { echo apply_filters('the_excerpt', $post->post_excerpt); } // Get actions $actions = array(); $actions['id'] = 'ID: ' . $post->ID; if ($can_edit_post && 'trash' != $post->post_status) { $actions['inline hide-if-no-js'] = '<a href="#" class="editinline" title="' . esc_attr(__('Edit this item inline', 'woocommerce')) . '">' . __('Quick Edit', 'woocommerce') . '</a>'; } if (current_user_can($post_type_object->cap->delete_post, $post->ID)) { if ('trash' == $post->post_status) { $actions['untrash'] = "<a title='" . esc_attr(__('Restore this item from the Trash', 'woocommerce')) . "' href='" . wp_nonce_url(admin_url(sprintf($post_type_object->_edit_link . '&action=untrash', $post->ID)), 'untrash-' . $post->post_type . '_' . $post->ID) . "'>" . __('Restore', 'woocommerce') . "</a>"; } elseif (EMPTY_TRASH_DAYS) { $actions['trash'] = "<a class='submitdelete' title='" . esc_attr(__('Move this item to the Trash', 'woocommerce')) . "' href='" . get_delete_post_link($post->ID) . "'>" . __('Trash', 'woocommerce') . "</a>"; } if ('trash' == $post->post_status || !EMPTY_TRASH_DAYS) { $actions['delete'] = "<a class='submitdelete' title='" . esc_attr(__('Delete this item permanently', 'woocommerce')) . "' href='" . get_delete_post_link($post->ID, '', true) . "'>" . __('Delete Permanently', 'woocommerce') . "</a>"; } } if ($post_type_object->public) { if (in_array($post->post_status, array('pending', 'draft'))) { if ($can_edit_post) { $actions['view'] = '<a href="' . esc_url(add_query_arg('preview', 'true', get_permalink($post->ID))) . '" title="' . esc_attr(sprintf(__('Preview “%s”', 'woocommerce'), $title)) . '" rel="permalink">' . __('Preview', 'woocommerce') . '</a>'; } } elseif ('trash' != $post->post_status) { $actions['view'] = '<a href="' . get_permalink($post->ID) . '" title="' . esc_attr(sprintf(__('View “%s”', 'woocommerce'), $title)) . '" rel="permalink">' . __('View', 'woocommerce') . '</a>'; } } $actions = apply_filters('post_row_actions', $actions, $post); echo '<div class="row-actions">'; $i = 0; $action_count = sizeof($actions); foreach ($actions as $action => $link) { ++$i; $i == $action_count ? $sep = '' : ($sep = ' | '); echo "<span class='{$action}'>{$link}{$sep}</span>"; } echo '</div>'; get_inline_data($post); /* Custom inline data for woocommerce */ echo ' <div class="hidden" id="woocommerce_inline_' . $post->ID . '"> <div class="sku">' . $product->sku . '</div> <div class="regular_price">' . $product->regular_price . '</div> <div class="sale_price">' . $product->sale_price . '</div> <div class="weight">' . $product->weight . '</div> <div class="length">' . $product->length . '</div> <div class="width">' . $product->width . '</div> <div class="height">' . $product->height . '</div> <div class="visibility">' . $product->visibility . '</div> <div class="stock_status">' . $product->stock_status . '</div> <div class="stock">' . $product->stock . '</div> <div class="manage_stock">' . $product->manage_stock . '</div> <div class="featured">' . $product->featured . '</div> <div class="product_type">' . $product->product_type . '</div> <div class="product_is_virtual">' . $product->virtual . '</div> </div> '; break; case "sku": if ($product->get_sku()) { echo $product->get_sku(); } else { echo '<span class="na">–</span>'; } break; case "product_type": if ($product->product_type == 'grouped') { echo '<span class="product-type tips ' . $product->product_type . '" tip="' . __('Grouped', 'woocommerce') . '"></span>'; } elseif ($product->product_type == 'external') { echo '<span class="product-type tips ' . $product->product_type . '" tip="' . __('External/Affiliate', 'woocommerce') . '"></span>'; } elseif ($product->product_type == 'simple') { if ($product->is_virtual()) { echo '<span class="product-type tips virtual" tip="' . __('Virtual', 'woocommerce') . '"></span>'; } elseif ($product->is_downloadable()) { echo '<span class="product-type tips downloadable" tip="' . __('Downloadable', 'woocommerce') . '"></span>'; } else { echo '<span class="product-type tips ' . $product->product_type . '" tip="' . __('Simple', 'woocommerce') . '"></span>'; } } elseif ($product->product_type == 'variable') { echo '<span class="product-type tips ' . $product->product_type . '" tip="' . __('Variable', 'woocommerce') . '"></span>'; } else { // Assuming that we have other types in future echo '<span class="product-type tips ' . $product->product_type . '" tip="' . ucwords($product->product_type) . '"></span>'; } break; case "price": if ($product->get_price_html()) { echo $product->get_price_html(); } else { echo '<span class="na">–</span>'; } break; case "product_cat": if (!($terms = get_the_term_list($post->ID, 'product_cat', '', ', ', ''))) { echo '<span class="na">–</span>'; } else { echo $terms; } break; case "product_tags": if (!($terms = get_the_term_list($post->ID, 'product_tag', '', ', ', ''))) { echo '<span class="na">–</span>'; } else { echo $terms; } break; case "featured": $url = wp_nonce_url(admin_url('admin-ajax.php?action=woocommerce-feature-product&product_id=' . $post->ID), 'woocommerce-feature-product'); echo '<a href="' . $url . '" title="' . __('Change', 'woocommerce') . '">'; if ($product->is_featured()) { echo '<a href="' . $url . '"><img src="' . $woocommerce->plugin_url() . '/assets/images/featured.png" alt="yes" />'; } else { echo '<img src="' . $woocommerce->plugin_url() . '/assets/images/featured-off.png" alt="no" />'; } echo '</a>'; break; case "is_in_stock": if ($product->is_in_stock()) { echo '<mark class="instock">' . __('In stock', 'woocommerce') . '</mark>'; } else { echo '<mark class="outofstock">' . __('Out of stock', 'woocommerce') . '</mark>'; } if ($product->managing_stock()) { echo ' × ' . $product->get_total_stock(); } break; } }
/** * Get the order data for a single CSV row * * Note items are keyed according to the column header keys above so these can be modified using * the provider filter without needing to worry about the array order * * @since 3.0 * @param int $order_id the WC_Order ID * @return array order data in the format key => content */ private function get_orders_csv_row($order_id) { $order = wc_get_order($order_id); $line_items = $shipping_items = $fee_items = $tax_items = $coupon_items = array(); // get line items foreach ($order->get_items() as $item_id => $item) { $product = $order->get_product_from_item($item); if (!is_object($product)) { $product = new WC_Product(0); } $item_meta = new WC_Order_Item_Meta(SV_WC_Plugin_Compatibility::is_wc_version_gte_2_4() ? $item : $item['item_meta']); $meta = $item_meta->display(true, true); if ($meta) { // remove newlines $meta = str_replace(array("\r", "\r\n", "\n"), '', $meta); // switch reserved chars (:;|) to = $meta = str_replace(array(': ', ':', ';', '|'), '=', $meta); } $line_item = array('name' => html_entity_decode($product->get_title() ? $product->get_title() : $item['name'], ENT_NOQUOTES, 'UTF-8'), 'sku' => $product->get_sku(), 'quantity' => $item['qty'], 'total' => wc_format_decimal($order->get_line_total($item), 2), 'refunded' => wc_format_decimal($order->get_total_refunded_for_item($item_id), 2), 'meta' => html_entity_decode($meta, ENT_NOQUOTES, 'UTF-8')); // add line item tax $line_tax_data = isset($item['line_tax_data']) ? $item['line_tax_data'] : array(); $tax_data = maybe_unserialize($line_tax_data); $line_item['tax'] = isset($tax_data['total']) ? wc_format_decimal(wc_round_tax_total(array_sum((array) $tax_data['total'])), 2) : ''; /** * CSV Order Export Line Item. * * Filter the individual line item entry for the default export * * @since 3.0.6 * @param array $line_item { * line item data in key => value format * the keys are for convenience and not used for exporting. Make * sure to prefix the values with the desired line item entry name * } * * @param array $item WC order item data * @param WC_Product $product the product * @param WC_Order $order the order * @param \WC_Customer_Order_CSV_Export_Generator $this, generator instance */ $line_item = apply_filters('wc_customer_order_csv_export_order_line_item', $line_item, $item, $product, $order, $this); if ('default_one_row_per_item' !== $this->order_format && is_array($line_item)) { foreach ($line_item as $name => $value) { $line_item[$name] = $name . ':' . $value; } $line_item = implode('|', $line_item); } if ($line_item) { $line_items[] = $line_item; } } foreach ($order->get_shipping_methods() as $_ => $shipping_item) { $shipping_items[] = implode('|', array('method:' . $shipping_item['name'], 'total:' . wc_format_decimal($shipping_item['cost'], 2))); } // get fee items & total $fee_total = 0; $fee_tax_total = 0; foreach ($order->get_fees() as $fee_id => $fee) { $fee_items[] = implode('|', array('name:' . $fee['name'], 'total:' . wc_format_decimal($fee['line_total'], 2), 'tax:' . wc_format_decimal($fee['line_tax'], 2))); $fee_total += $fee['line_total']; $fee_tax_total += $fee['line_tax']; } // get tax items foreach ($order->get_tax_totals() as $tax_code => $tax) { $tax_items[] = implode('|', array('code:' . $tax_code, 'total:' . wc_format_decimal($tax->amount, 2))); } // add coupons foreach ($order->get_items('coupon') as $_ => $coupon_item) { $coupon = new WC_Coupon($coupon_item['name']); $coupon_post = get_post($coupon->id); $coupon_items[] = implode('|', array('code:' . $coupon_item['name'], 'description:' . (is_object($coupon_post) ? $coupon_post->post_excerpt : ''), 'amount:' . wc_format_decimal($coupon_item['discount_amount'], 2))); } $order_data = array('order_id' => $order->id, 'order_number' => $order->get_order_number(), 'order_date' => $order->order_date, 'status' => $order->get_status(), 'shipping_total' => $order->get_total_shipping(), 'shipping_tax_total' => wc_format_decimal($order->get_shipping_tax(), 2), 'fee_total' => wc_format_decimal($fee_total, 2), 'fee_tax_total' => wc_format_decimal($fee_tax_total, 2), 'tax_total' => wc_format_decimal($order->get_total_tax(), 2), 'cart_discount' => SV_WC_Plugin_Compatibility::is_wc_version_gte_2_3() ? wc_format_decimal($order->get_total_discount(), 2) : wc_format_decimal($order->get_cart_discount(), 2), 'order_discount' => SV_WC_Plugin_Compatibility::is_wc_version_gte_2_3() ? wc_format_decimal($order->get_total_discount(), 2) : wc_format_decimal($order->get_order_discount(), 2), 'discount_total' => wc_format_decimal($order->get_total_discount(), 2), 'order_total' => wc_format_decimal($order->get_total(), 2), 'refunded_total' => wc_format_decimal($order->get_total_refunded(), 2), 'order_currency' => $order->get_order_currency(), 'payment_method' => $order->payment_method, 'shipping_method' => $order->get_shipping_method(), 'customer_id' => $order->get_user_id(), 'billing_first_name' => $order->billing_first_name, 'billing_last_name' => $order->billing_last_name, 'billing_company' => $order->billing_company, 'billing_email' => $order->billing_email, 'billing_phone' => $order->billing_phone, 'billing_address_1' => $order->billing_address_1, 'billing_address_2' => $order->billing_address_2, 'billing_postcode' => $order->billing_postcode, 'billing_city' => $order->billing_city, 'billing_state' => $order->billing_state, 'billing_country' => $order->billing_country, 'shipping_first_name' => $order->shipping_first_name, 'shipping_last_name' => $order->shipping_last_name, 'shipping_company' => $order->shipping_company, 'shipping_address_1' => $order->shipping_address_1, 'shipping_address_2' => $order->shipping_address_2, 'shipping_postcode' => $order->shipping_postcode, 'shipping_city' => $order->shipping_city, 'shipping_state' => $order->shipping_state, 'shipping_country' => $order->shipping_country, 'customer_note' => $order->customer_note, 'shipping_items' => implode(';', $shipping_items), 'fee_items' => implode(';', $fee_items), 'tax_items' => implode(';', $tax_items), 'coupon_items' => implode(';', $coupon_items), 'order_notes' => implode('|', $this->get_order_notes($order)), 'download_permissions' => $order->download_permissions_granted ? $order->download_permissions_granted : 0); if ('default_one_row_per_item' === $this->order_format) { $new_order_data = array(); foreach ($line_items as $item) { $order_data['item_name'] = $item['name']; $order_data['item_sku'] = $item['sku']; $order_data['item_quantity'] = $item['quantity']; $order_data['item_tax'] = $item['tax']; $order_data['item_total'] = $item['total']; $order_data['item_refunded'] = $item['refunded']; $order_data['item_meta'] = $item['meta']; /** * CSV Order Export Row for One Row per Item. * * Filter the individual row data for the order export * * @since 3.3.0 * @param array $order_data { * order data in key => value format * to modify the row data, ensure the key matches any of the header keys and set your own value * } * @param array $item * @param \WC_Order $order WC Order object * @param \WC_Customer_Order_CSV_Export_Generator $this, generator instance */ $new_order_data[] = apply_filters('wc_customer_order_csv_export_order_row_one_row_per_item', $order_data, $item, $order, $this); } $order_data = $new_order_data; } else { $order_data['line_items'] = implode(';', $line_items); } /** * CSV Order Export Row. * * Filter the individual row data for the order export * * @since 3.0 * @param array $order_data { * order data in key => value format * to modify the row data, ensure the key matches any of the header keys and set your own value * } * @param \WC_Order $order WC Order object * @param \WC_Customer_Order_CSV_Export_Generator $this, generator instance */ return apply_filters('wc_customer_order_csv_export_order_row', $order_data, $order, $this); }
function custom_add_tax($instance) { if (is_admin() && !defined('DOING_AJAX')) { return; } global $woocommerce; $fee = 0; foreach ($woocommerce->cart->get_cart() as $cart_item_key => $values) { $product = new WC_Product($values['product_id']); $sku = $product->get_sku(); $qty = $values['quantity']; include_once TEMPLATEPATH . "/portal/api/Api.php"; include_once TEMPLATEPATH . "/portal/api/Setting.php"; include_once TEMPLATEPATH . "/portal/api/RequestParams.php"; include_once TEMPLATEPATH . "/portal/api/BQ_Base.php"; include_once TEMPLATEPATH . "/portal/api/BQ_CustomerManualInvoiceQuoteRequest.php"; $Api = new Api(); $requestParams = new requestParams(); $BQ = new BQ_CustomerManualInvoiceQuoteRequest(); // $BQ->set_billingProfileId('3'); $BQ->set_customerId(WC()->session->get('customerId')); $skus = array($sku); $BQ->set_Skus($skus); $requestParams->id = Setting::CLEC_ID; $requestParams->firstName = Setting::CLEC_FIRSTNAME; $requestParams->lastName = Setting::CLEC_LASTNAME; $requestParams->details = $BQ; $request = $Api->buildRequest($requestParams); $Api->callAPI(Setting::URL, $request); $BQ->set_response($Api->response); // echo '<pre>' . var_export( $BQ->get_response(), true ) . '</pre>'; // echo '<pre>' . var_export( $BQ->get_tax_total(), true ) . '</pre>'; $fee += $BQ->get_tax_total(); } // echo '<pre>' . var_export( $woocommerce->cart->get_cart(), true ) . '</pre>'; // echo '<pre>' . var_export( $instance, true ) . '</pre>'; $woocommerce->cart->add_fee('Sales Tax', $fee, true, 'standard'); return $instance; }
function pricemania_xml_feed_aktualizace() { $args = array('nopaging' => true, 'post_type' => 'product', 'post_status' => 'publish', 'meta_key' => '_visibility', 'meta_value' => 'hidden', 'meta_compare' => '!=', 'fields' => 'ids'); $products = get_posts($args); $global_dodaci_doba = get_option('wc_ceske_sluzby_xml_feed_heureka_dodaci_doba'); $podpora_ean = get_option('wc_ceske_sluzby_xml_feed_heureka_podpora_ean'); $postovne = get_option('wc_ceske_sluzby_xml_feed_pricemania_postovne'); $xmlWriter = new XMLWriter(); $xmlWriter->openMemory(); $xmlWriter->setIndent(true); $xmlWriter->startDocument('1.0', 'utf-8'); $xmlWriter->startElement('products'); $i = 0; unlink(WP_CONTENT_DIR . '/pricemania.xml'); foreach ($products as $product_id) { $ean = ""; $dodaci_doba = ""; $description = ""; $skladem = false; $strom_kategorie = ""; $i = $i + 1; $produkt = new WC_Product($product_id); $sku = $produkt->get_sku(); if (!empty($podpora_ean) && $podpora_ean == "SKU") { $ean = $sku; } $skladem = $produkt->is_in_stock(); if ($skladem && isset($global_dodaci_doba)) { $dodaci_doba = $global_dodaci_doba; } if (!empty($produkt->post->post_excerpt)) { $description = $produkt->post->post_excerpt; } else { $description = $produkt->post->post_content; } $kategorie = get_the_terms($product_id, 'product_cat'); if ($kategorie && !is_wp_error($kategorie)) { $rodice_kategorie = get_ancestors($kategorie[0]->term_id, 'product_cat'); if (!empty($rodice_kategorie)) { foreach ($rodice_kategorie as $rodic) { $nazev_kategorie = get_term_by('ID', $rodic, 'product_cat'); $strom_kategorie = $nazev_kategorie->name . ' > ' . $strom_kategorie; } } $strom_kategorie .= $kategorie[0]->name; } $xmlWriter->startElement('product'); $xmlWriter->writeElement('id', $product_id); $xmlWriter->startElement('name'); $xmlWriter->text(wp_strip_all_tags($produkt->post->post_title)); $xmlWriter->endElement(); if (!empty($description)) { $xmlWriter->startElement('description'); $xmlWriter->text(wp_strip_all_tags($description)); $xmlWriter->endElement(); } if (!empty($strom_kategorie)) { $xmlWriter->startElement('category'); $xmlWriter->text($strom_kategorie); $xmlWriter->endElement(); } $xmlWriter->writeElement('manufacturer', ''); // https://wordpress.org/plugins/woocommerce-brand/ $xmlWriter->writeElement('url', get_permalink($product_id)); $xmlWriter->writeElement('picture', wp_get_attachment_url(get_post_thumbnail_id($product_id))); if ($dodaci_doba != "") { $xmlWriter->writeElement('availability', $dodaci_doba); } if ($postovne != "") { $xmlWriter->writeElement('shipping', $postovne); } $xmlWriter->writeElement('price', $produkt->price); if (!empty($ean)) { $xmlWriter->writeElement('ean', $ean); } $xmlWriter->endElement(); if (0 == $i % 1000) { file_put_contents(WP_CONTENT_DIR . '/pricemania.xml', $xmlWriter->flush(true), FILE_APPEND); } } $xmlWriter->endElement(); $xmlWriter->endDocument(); header('Content-type: text/xml'); file_put_contents(WP_CONTENT_DIR . '/pricemania.xml', $xmlWriter->flush(true), FILE_APPEND); }
function dhvc_woo_get_product_formatted_name(WC_Product $product) { if ($product->get_sku()) { $identifier = $product->get_sku(); } else { $identifier = '#' . $product->id; } return sprintf(__('%s – %s', DHVC_WOO), $identifier, $product->get_title()); }
?> </a> <div class="caption"> <a href="<?php the_permalink(); ?> "><span class="caption-title"><?php hhs_brand_2(); ?> </span></a> <hr> <?php $product = new WC_Product(get_the_ID()); ?> <p class="caption-description"><?php echo get_the_title() . $product->get_sku(); ?> </p> <div class="caption-price"> <?php $price = get_post_meta(get_the_ID(), '_regular_price', true); $sale = get_post_meta(get_the_ID(), '_sale_price', true); ?> <div class="price-info"> <?php echo '<p class="old-price">' . number_format($price, 0, '.', '.') . ' VNĐ</p>'; ?> <?php echo '<p class="new-price">' . number_format($sale, 0, '.', '.') . ' VNĐ</p>'; ?> </div>
protected function _formatted_name(WC_Product $product) { if ($product->get_sku()) { $identifier = $product->get_sku(); } else { $identifier = '#' . $product->id; } return sprintf(__('%s – %s', 'sitesao'), $identifier, $product->get_title()); }
public function wc_add_to_cart_message($message, $product_id) { $integration = $this->load_integration(); if (empty($integration->get_option('facebookpixel'))) { return; } $product = new WC_Product($product_id); ob_start('tracker'); ?> <img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?<?php echo http_build_query(array('id' => $integration->get_option('facebookpixel'), 'ev' => 'AddToCart', 'noscript' => 1, 'content_ids' => $product->get_sku(), 'content_name' => $product->get_title(), 'currency' => get_woocommerce_currency(), 'value' => $product->get_price(), 'content_type' => 'product')); ?> "/> <?php $_tracker = ob_get_clean(); $message .= ' ' . $_tracker; return $message; }
function CreateAmzFBAOrder($order_id) { AmzFBA_Woo_Log("DEBUG", "Order", __FUNCTION__, "Entering"); $MissingConfig = CheckForMissingConfig(); $level = "Good"; $category = "Order"; if ($MissingConfig == true) { $returnmessage = 'Failed sending order to Amazon FBA. Required configuration missing in settings.'; $order->add_order_note($returnmessage, 0); //Add to Log $level = "Bad"; $category = "Order"; $title = "Failed - Order ID:" . $order_id; AmzFBA_Woo_Log($level, $category, $title, $returnmessage); return $returnmessage; } $FBAOrderID = get_post_meta($order_id, "FBA_OrderId", TRUE); if (!empty($FBAOrderID) && $FBAOrderID != "") { $returnmessage = 'Create FBA Order: FBA Order id is already there: ' . $FBAOrderID; $order->add_order_note($returnmessage, 0); //Add to Log $level = "Bad"; $title = "Create FBA Order - Order ID:" . $order_id; AmzFBA_Woo_Log($level, $category, $title, $returnmessage); return $returnmessage; } $UserSettings = get_option('woocommerce_amazonfba_settings'); $ChosenMarketplace = $UserSettings['AmzFBA_Marketplace']; $MWSEndpointURL = GetMWSEndpointURL('FulfillmentOutboundShipment', $ChosenMarketplace); $config = array('ServiceURL' => $MWSEndpointURL, 'ProxyHost' => null, 'ProxyPort' => -1, 'MaxErrorRetry' => 3); $service = new FBAOutboundServiceMWS_Client(ACCESS_KEY_ID, SECRET_ACCESS_KEY, $config, APPLICATION_NAME, APPLICATION_VERSION); $order = new WC_Order($order_id); $dateObj = new DateTime($order->order_date, new DateTimeZone('UTC')); $order_date_converted = $dateObj->format(DateTime::ISO8601); $datetimeasINT = date("YmdHis"); $uniqueid_foramazon = "KINIVO-" . $datetimeasINT . "-" . $order_id; AmzFBA_Woo_Log($level, $category, $title, "FBA order id - " . $uniqueid_foramazon); //set Variables $shipping_name = $order->shipping_first_name . ' ' . $order->shipping_last_name; $shipping_address_line_1 = $order->shipping_address_1; $shipping_address_line_2 = $order->shipping_address_2; $shipping_city = $order->shipping_city; $shipping_state = $order->shipping_state; $shipping_postcode = $order->shipping_postcode; $shipping_country = $order->shipping_country; $shipping_speed = GetAmazonShippingSpeed($order); $UserSettings = get_option('woocommerce_amazonfba_settings'); //Gets all settings from this App $FulfillmentPolicy = $UserSettings['AmzFBA_FulfillmentPolicy']; $OrderComment = $UserSettings['AmzFBA_OrderComment']; $EmailNotificationAddress = $UserSettings['AmzFBA_EmailNotifyAddress']; ////////////////////////////// //Standard Stuff $request = new FBAOutboundServiceMWS_Model_CreateFulfillmentOrderRequest(); $request->setSellerId(SELLER_ID); $request->setSellerFulfillmentOrderId($uniqueid_foramazon); $request->setDisplayableOrderId($order_id); $request->setDisplayableOrderDateTime($order_date_converted); $request->setDisplayableOrderComment($OrderComment); // $request->setNotificationEmailList($EmailNotificationAddress); $request->setShippingSpeedCategory($shipping_speed); //Standard, Expedited, Priority $request->setFulfillmentPolicy($FulfillmentPolicy); //FillOrKill, FillAll, FillAllAvailable ////////////////////////////// //Address $requestaddress = new FBAOutboundServiceMWS_Model_Address(); $requestaddress->setName($shipping_name); $requestaddress->setLine1($shipping_address_line_1); $requestaddress->setLine2($shipping_address_line_2); $requestaddress->setLine3(''); $requestaddress->setCity($shipping_city); $requestaddress->setDistrictOrCounty($shipping_country); if ($shipping_state != '') { $requestaddress->setStateOrProvinceCode($shipping_state); } $requestaddress->setCountryCode($shipping_country); $requestaddress->setPostalCode($shipping_postcode); $requestaddress->setPhoneNumber(''); $request->setDestinationAddress($requestaddress); ////////////////////////////// //Order Item List $requestlist = new FBAOutboundServiceMWS_Model_CreateFulfillmentOrderItemList(); $request->setItems($requestlist); ////////////////////////////// //Order Items $items = $order->get_items(); $itemnumber = 0; $itemnumber_unful = 0; $UnfulfillableItems = ''; $success = 0; $unsuccess = 0; foreach ($items as $item) { //Get the SKU of the Item $Quantity = $item['qty']; if ($item['variation_id'] == '' || $item['variation_id'] == NULL || $item['variation_id'] == '0') { $IDForSKU = $item['product_id']; } else { $IDForSKU = $item['variation_id']; } $GetSKU = new WC_Product($IDForSKU); $SKU = $GetSKU->get_sku(); //Check if available for Amazon Fulfilment $fulfillable = false; if (AmzFBA_is_sku_fulfillable($SKU) == NULL || AmzFBA_is_sku_fulfillable($SKU) == '') { $UnfulfillableItems[$itemnumber_unful]['SKU'] = $SKU; $UnfulfillableItems[$itemnumber_unful]['Quantity'] = $Quantity; $unsuccess = $unsuccess + $Quantity; $itemnumber_unful++; $note = "SKU : IDForSKU = " . $IDForSKU . " SKU = " . $SKU . " is not fulfillable by Amazon. Please check product details"; $order->add_order_note($note, 0); } else { $ItemArray[$itemnumber] = new FBAOutboundServiceMWS_Model_CreateFulfillmentOrderItem(); $ItemArray[$itemnumber]->setSellerSKU($SKU); $ItemArray[$itemnumber]->setSellerFulfillmentOrderItemId($itemnumber); $ItemArray[$itemnumber]->setQuantity($Quantity); $success = $success + $Quantity; $itemnumber++; $fulfillable = true; } $level = "Neutral"; $category = "Order"; $title = "Item details for Order ID:" . $order_id; $info = "SKU details: IDForSKU = " . $IDForSKU . " SKU = " . $SKU . " Fulfillable = " . $fulfillable; AmzFBA_Woo_Log($level, $category, $title, $info); } $percentfulfilled = round($success / ($success + $unsuccess) * 100, 2); //Load Array of Items into Order if ($percentfulfilled != 0) { $requestlist->setmember($ItemArray); } //Check if we now need to fulfil them. //If 0% fulfillled if ($percentfulfilled == '0') { $returnmessage = "Order not submitted. No SKUs in WooCommerce available on Amazon FBA"; $note = "No SKUs in this order available for Amazon Fulfillment."; $order->add_order_note($note, 0); $order->update_status('on-hold'); update_post_meta($order_id, 'PercentFulfilledByAmazon', $percentfulfilled); //Add to Log $level = "Neutral"; $category = "Order"; $title = "Unfulfillable - Order ID:" . $order_id; $info = "No SKUs in this order available for Amazon Fulfillment."; AmzFBA_Woo_Log($level, $category, $title, $info); } elseif ($percentfulfilled < '100' && $percentfulfilled > '0') { $returnmessage = "Order not submitted. Only " . $percentfulfilled . "% of the Order is available on Amazon. Did not send anything to Amazon."; $note = $returnmessage; $order->add_order_note($note, 0); $order->update_status('on-hold'); //Add to Log $level = "Neutral"; $category = "Order"; $title = "Unfulfillable - Order ID:" . $order_id; $info = "Only some sku's were available for Amazon Fulfillment. Did not send anything to Amazon."; AmzFBA_Woo_Log($level, $category, $title, $info); /* $returnmessage = "Order submitted. Sent " . $percentfulfilled . "% of the Order to Amazon. For unfulfillable items, see order notes."; $note = $percentfulfilled . "% of Order sent to Amazon for Fulfillment : FBA_OrderId " . $uniqueid_foramazon; $order->add_order_note($note, 0); foreach ($UnfulfillableItems as $UnfilItem) { $theitems .= $UnfilItem['Quantity'] . " X " . $UnfilItem['SKU'] . ". "; } $note = "Unfulfillable Items : " . $theitems; $order->add_order_note($note, 0); update_post_meta($order_id, 'PercentFulfilledByAmazon', $percentfulfilled); //Add meta data of Unique ID sent to Amazon update_post_meta($order_id, 'FBA_OrderId', $uniqueid_foramazon); //Send Order to Amazon invokeCreateFulfillmentOrder($service, $request, $order_id, $percentfulfilled); */ } elseif ($percentfulfilled == '100') { $returnmessage = "Order submitted. Sent" . $percentfulfilled . "% of Order to Amazon."; $note = "100% of Order sent to Amazon for Fulfillment: FBA_OrderId " . $uniqueid_foramazon; $order->add_order_note($note, 0); update_post_meta($order_id, 'PercentFulfilledByAmazon', $percentfulfilled); //Add meta data of Unique ID sent to Amazon update_post_meta($order_id, 'FBA_OrderId', $uniqueid_foramazon); //Send Order to amazon if (!invokeCreateFulfillmentOrder($service, $request, $order_id, $percentfulfilled)) { // It seems creating FBA order failed... Putting the order on hold $note = "FBA order failed. Check logs and sellercentral for order id - " . $uniqueid_foramazon; $returnmessage = $note; $order->add_order_note($note, 0); $order->update_status('on-hold'); AmzFBA_Woo_Log("Bad", $category, "FBA order creation", "Failed - not sure what happened. Check sellercentral as well"); } } AmzFBA_Woo_Log("DEBUG", "Order", __FUNCTION__, "Exiting"); return $returnmessage; }
/** * Extracts the relevent product fields and adds them to the array * this is where the hard work of getting the data out occurs * Additionally do any formatting here.... */ private function extract_fields($p) { $data = array(); // Go thru each field foreach ($this->fieldsToExport as $name => $field) { switch ($name) { case 'id': array_push($data, $p->id); break; case 'sku': array_push($data, $p->get_sku()); break; case 'parent_id': $parent = $p->get_parent(); if ($parent == 0) { $parent = ''; } array_push($data, $parent); break; case 'parent_sku': $parent = $p->get_parent(); //if we have a parent, get the sku if (!empty($parent)) { $temp = new WC_Product($parent); array_push($data, $temp->get_sku()); } else { //no parent so blank array_push($data, ''); } break; case 'name': array_push($data, $p->get_title()); break; case 'product_type': //Woo's product type is always null - bug somewhere //array_push ( $data, $p->product_type ); $temp = wc_get_product($p->id); array_push($data, $temp->product_type); break; case 'shipping_class': array_push($data, $p->get_shipping_class()); break; case 'width': array_push($data, $p->width); break; case 'length': array_push($data, $p->length); break; case 'height': array_push($data, $p->height); break; case 'managing_stock': array_push($data, $p->managing_stock() ? "YES" : "NO"); break; case 'in_stock': array_push($data, $p->is_in_stock() ? "YES" : "NO"); break; case 'qty_in_stock': if ($p->managing_stock()) { array_push($data, $p->stock); } else { array_push($data, ''); } break; case 'downloadable': array_push($data, $p->is_downloadable() ? 'YES' : 'NO'); break; case 'tax_status': array_push($data, $p->get_tax_status()); break; case 'tax_class': array_push($data, $p->get_tax_class()); break; case 'featured': array_push($data, $p->is_featured() ? 'YES' : 'NO'); break; case 'price': $price = $p->get_regular_price(); //no price check if there is one in the basic function - woo is funky if ($price == '') { $price = $p->get_price(); } array_push($data, $price); break; case 'sale_price': array_push($data, $p->get_sale_price()); break; case 'sale_from': $from = ($date = get_post_meta($p->id, '_sale_price_dates_from', true)) ? date_i18n($this->settings['date_format'], $date) : ''; array_push($data, $from); break; case 'sale_to': $to = ($date = get_post_meta($p->id, '_sale_price_dates_to', true)) ? date_i18n($this->settings['date_format'], $date) : ''; array_push($data, $to); break; } } return $data; }
/** * Get product data. * * @param WC_Product $product Product instance. * @return array */ protected function get_product_data($product) { $data = array('id' => $product->get_id(), 'name' => $product->get_name(), 'slug' => $product->get_slug(), 'permalink' => $product->get_permalink(), 'date_created' => wc_rest_prepare_date_response($product->get_date_created()), 'date_modified' => wc_rest_prepare_date_response($product->get_date_modified()), 'type' => $product->get_type(), 'status' => $product->get_status(), 'featured' => $product->is_featured(), 'catalog_visibility' => $product->get_catalog_visibility(), 'description' => wpautop(do_shortcode($product->get_description())), 'short_description' => apply_filters('woocommerce_short_description', $product->get_short_description()), 'sku' => $product->get_sku(), 'price' => $product->get_price(), 'regular_price' => $product->get_regular_price(), 'sale_price' => $product->get_sale_price() ? $product->get_sale_price() : '', 'date_on_sale_from' => $product->get_date_on_sale_from() ? date('Y-m-d', $product->get_date_on_sale_from()) : '', 'date_on_sale_to' => $product->get_date_on_sale_to() ? date('Y-m-d', $product->get_date_on_sale_to()) : '', 'price_html' => $product->get_price_html(), 'on_sale' => $product->is_on_sale(), 'purchasable' => $product->is_purchasable(), 'total_sales' => $product->get_total_sales(), 'virtual' => $product->is_virtual(), 'downloadable' => $product->is_downloadable(), 'downloads' => $this->get_downloads($product), 'download_limit' => $product->get_download_limit(), 'download_expiry' => $product->get_download_expiry(), 'download_type' => 'standard', 'external_url' => $product->is_type('external') ? $product->get_product_url() : '', 'button_text' => $product->is_type('external') ? $product->get_button_text() : '', 'tax_status' => $product->get_tax_status(), 'tax_class' => $product->get_tax_class(), 'manage_stock' => $product->managing_stock(), 'stock_quantity' => $product->get_stock_quantity(), 'in_stock' => $product->is_in_stock(), 'backorders' => $product->get_backorders(), 'backorders_allowed' => $product->backorders_allowed(), 'backordered' => $product->is_on_backorder(), 'sold_individually' => $product->is_sold_individually(), 'weight' => $product->get_weight(), 'dimensions' => array('length' => $product->get_length(), 'width' => $product->get_width(), 'height' => $product->get_height()), 'shipping_required' => $product->needs_shipping(), 'shipping_taxable' => $product->is_shipping_taxable(), 'shipping_class' => $product->get_shipping_class(), 'shipping_class_id' => $product->get_shipping_class_id(), 'reviews_allowed' => $product->get_reviews_allowed(), 'average_rating' => wc_format_decimal($product->get_average_rating(), 2), 'rating_count' => $product->get_rating_count(), 'related_ids' => array_map('absint', array_values(wc_get_related_products($product->get_id()))), 'upsell_ids' => array_map('absint', $product->get_upsell_ids()), 'cross_sell_ids' => array_map('absint', $product->get_cross_sell_ids()), 'parent_id' => $product->get_parent_id(), 'purchase_note' => wpautop(do_shortcode(wp_kses_post($product->get_purchase_note()))), 'categories' => $this->get_taxonomy_terms($product), 'tags' => $this->get_taxonomy_terms($product, 'tag'), 'images' => $this->get_images($product), 'attributes' => $this->get_attributes($product), 'default_attributes' => $this->get_default_attributes($product), 'variations' => array(), 'grouped_products' => array(), 'menu_order' => $product->get_menu_order()); return $data; }
function orderpost($orderId) { global $wpdb; $testMode = get_option('linksync_test'); $LAIDKey = get_option('linksync_laid'); $apicall = new linksync_class($LAIDKey, $testMode); //Checking for already sent Order $sentOrderIds = get_option('linksync_sent_order_id'); if (isset($sentOrderIds)) { if (!empty($sentOrderIds)) { $order_id_array = unserialize($sentOrderIds); } else { $order_id_array = array(); } if (!in_array($orderId, $order_id_array)) { $order = new WC_Order($orderId); if ($order->post_status == get_option('order_status_wc_to_vend')) { update_option('linksync_sent_order_id', serialize(array_merge($order_id_array, array($orderId)))); $order_no = $order->get_order_number(); if (strpos($order_no, '#') !== false) { $order_no = str_replace('#', '', $order_no); } $get_total = $order->get_total(); $get_user = $order->get_user(); $comments = $order->post->post_excerpt; $primary_email_address = $get_user->data->user_email; $currency = $order->get_order_currency(); $shipping_method = $order->get_shipping_method(); $order_total = $order->get_order_item_totals(); $transaction_id = $order->get_transaction_id(); $taxes_included = false; $total_discount = $order->get_total_discount(); $total_quantity = 0; $registerDb = get_option('wc_to_vend_register'); $vend_uid = get_option('wc_to_vend_user'); $total_tax = $order->get_total_tax(); // Geting Payment object details if (isset($order_total['payment_method']['value']) && !empty($order_total['payment_method']['value'])) { $wc_payment = get_option('wc_to_vend_payment'); if (isset($wc_payment) && !empty($wc_payment)) { $total_payments = explode(",", $wc_payment); foreach ($total_payments as $mapped_payment) { $exploded_mapped_payment = explode("|", $mapped_payment); if (isset($exploded_mapped_payment[1]) && !empty($exploded_mapped_payment[1]) && isset($exploded_mapped_payment[0]) && !empty($exploded_mapped_payment[0])) { if ($exploded_mapped_payment[1] == $order_total['payment_method']['value']) { $vend_payment_data = explode("%%", $exploded_mapped_payment[0]); if (isset($vend_payment_data[0])) { $payment_method = $vend_payment_data[0]; } if (isset($vend_payment_data[1])) { $payment_method_id = $vend_payment_data[1]; } break; } } } } $payment = array("retailer_payment_type_id" => isset($payment_method_id) ? $payment_method_id : null, "amount" => isset($get_total) ? $get_total : 0, "method" => isset($payment_method) ? $payment_method : null, "transactionNumber" => isset($transaction_id) ? $transaction_id : null); } $export_user_details = get_option('wc_to_vend_export'); if (isset($export_user_details) && !empty($export_user_details)) { if ($export_user_details == 'customer') { //woocommerce filter $billingAddress_filter = apply_filters('woocommerce_order_formatted_billing_address', array('firstName' => $order->billing_first_name, 'lastName' => $order->billing_last_name, 'phone' => $order->billing_phone, 'street1' => $order->billing_address_1, 'street2' => $order->billing_address_2, 'city' => $order->billing_city, 'state' => $order->billing_state, 'postalCode' => $order->billing_postcode, 'country' => $order->billing_country, 'company' => $order->billing_company, 'email_address' => $order->billing_email), $order); $billingAddress = array('firstName' => $billingAddress_filter['firstName'], 'lastName' => $billingAddress_filter['lastName'], 'phone' => $billingAddress_filter['phone'], 'street1' => $billingAddress_filter['street1'], 'street2' => $billingAddress_filter['street2'], 'city' => $billingAddress_filter['city'], 'state' => $billingAddress_filter['state'], 'postalCode' => $billingAddress_filter['postalCode'], 'country' => $billingAddress_filter['country'], 'company' => $billingAddress_filter['company'], 'email_address' => $billingAddress_filter['email_address']); $deliveryAddress_filter = apply_filters('woocommerce_order_formatted_shipping_address', array('firstName' => $order->shipping_first_name, 'lastName' => $order->shipping_last_name, 'phone' => $order->shipping_phone, 'street1' => $order->shipping_address_1, 'street2' => $order->shipping_address_2, 'city' => $order->shipping_city, 'state' => $order->shipping_state, 'postalCode' => $order->shipping_postcode, 'country' => $order->shipping_country, 'company' => $order->shipping_company), $order); $deliveryAddress = array('firstName' => $deliveryAddress_filter['firstName'], 'lastName' => $deliveryAddress_filter['lastName'], 'phone' => $deliveryAddress_filter['phone'], 'street1' => $deliveryAddress_filter['street1'], 'street2' => $deliveryAddress_filter['street2'], 'city' => $deliveryAddress_filter['city'], 'state' => $deliveryAddress_filter['state'], 'postalCode' => $deliveryAddress_filter['postalCode'], 'country' => $deliveryAddress_filter['country'], 'company' => $deliveryAddress_filter['company']); $primary_email = isset($primary_email_address) ? $primary_email_address : $billingAddress['email_address']; unset($billingAddress['email_address']); } } $vend_user_detail = get_option('wc_to_vend_user'); if (isset($vend_user_detail) && !empty($vend_user_detail)) { $user = explode('|', $vend_user_detail); $vend_uid = isset($user[0]) ? $user[0] : null; $vend_username = isset($user[1]) ? $user[1] : null; } //Ordered product(s) $items = $order->get_items(); $taxes = $order->get_taxes(); foreach ($items as $item) { foreach ($taxes as $tax_label) { $sql = mysql_query("SELECT tax_rate_id FROM `" . $wpdb->prefix . "woocommerce_tax_rates` WHERE tax_rate_name='" . $tax_label['label'] . "' AND tax_rate_class='" . $item['item_meta']['_tax_class'][0] . "'"); if (mysql_num_rows($sql) != 0) { $tax_classes = linksync_tax_classes($tax_label['label'], $item['item_meta']['_tax_class'][0]); if ($tax_classes['result'] == 'success') { $vend_taxes = explode('/', $tax_classes['tax_classes']); } } } $taxId = isset($vend_taxes[0]) ? $vend_taxes[0] : null; $taxName = isset($vend_taxes[1]) ? $vend_taxes[1] : null; $taxRate = isset($vend_taxes[2]) ? $vend_taxes[2] : null; if (isset($item['variation_id']) && !empty($item['variation_id'])) { $product_id = $item['variation_id']; } else { $product_id = $item['product_id']; } $pro_object = new WC_Product($product_id); $itemtotal = (double) $item['item_meta']['_line_subtotal'][0]; if (isset($item['line_subtotal']) && !empty($item['line_subtotal'])) { $product_amount = (double) ($item['line_subtotal'] / $item['qty']); } $discount = (double) $item['item_meta']['_line_subtotal'][0] - (double) $item['item_meta']['_line_total'][0]; if (isset($discount) && !empty($discount)) { $discount = (double) ($discount / $item['qty']); } #---------Changes--------# //Product Amount = product org amount - discount amount $product_total_amount = (double) $product_amount - (double) $discount; $product_sku = $pro_object->get_sku(); if (isset($product_total_amount) && isset($taxRate) && !empty($product_total_amount) && !empty($taxRate)) { $taxValue = $product_total_amount * $taxRate; } $products[] = array('sku' => $product_sku, 'title' => $item['name'], 'price' => $product_total_amount, 'quantity' => $item['qty'], 'discountAmount' => isset($discount) ? $discount : 0, 'taxName' => isset($taxName) ? $taxName : null, 'taxId' => isset($taxId) ? $taxId : null, 'taxRate' => isset($taxRate) ? $taxRate : null, 'taxValue' => isset($taxValue) ? $taxValue : null, 'discountTitle' => isset($discountTitle) ? $discountTitle : 'sale'); $total_quantity += $item['qty']; unset($taxId); unset($taxName); unset($taxRate); unset($taxValue); } #---------Discount-----# // if (isset($total_discount) && !empty($total_discount)) { // $taxes_Discount = $apicall->linksync_getTaxes(); // if (isset($taxes_Discount) && !empty($taxes_Discount)) { // if (!isset($taxes_Discount['errorCode'])) { // if (isset($taxes_Discount['taxes'])) { // foreach ($taxes_Discount['taxes'] as $select_tax) { // if ($select_tax['name'] == 'GST') { // $discountTaxName = $select_tax['name']; // $discountTaxId = $select_tax['id']; // $discountTaxRate = $select_tax['rate']; // } // } // } // } // } // if (isset($total_discount)) { // if (isset($discountTaxRate) && !empty($discountTaxRate)) { // $taxValue_discount = $discountTaxRate * $total_discount; // } // } // $products[] = array( // "price" => isset($total_discount) ? $total_discount : null, // "quantity" => 1, // "sku" => "vend-discount", // 'taxName' => isset($discountTaxName) ? $discountTaxName : null, // 'taxId' => isset($discountTaxId) ? $discountTaxId : null, // 'taxRate' => isset($discountTaxRate) ? $discountTaxRate : null, // 'taxValue' => isset($taxValue_discount) ? $taxValue_discount : null // ); // $products[] = array( // "price" => isset($total_discount) ? $total_discount : null, // "quantity" => 1, // "sku" => "vend-discount", // 'taxName' => null, // 'taxId' => null, // 'taxRate' => null, // 'taxValue' => null // ); // } #----------Shipping------------# foreach ($taxes as $tax_label) { if (isset($tax_label['shipping_tax_amount']) && !empty($tax_label['shipping_tax_amount'])) { $tax_classes = linksync_tax_classes($tax_label['label'], $item['item_meta']['_tax_class'][0]); if ($tax_classes['result'] == 'success') { $vend_taxes = explode('/', $tax_classes['tax_classes']); $taxId_shipping = isset($vend_taxes[0]) ? $vend_taxes[0] : null; $taxName_shipping = isset($vend_taxes[1]) ? $vend_taxes[1] : null; $taxRate_shipping = isset($vend_taxes[2]) ? $vend_taxes[2] : null; } } } if (isset($shipping_method) && !empty($shipping_method)) { $shipping_cost = $order->get_total_shipping(); $shipping_with_tax = $order->get_shipping_tax(); if ($shipping_with_tax > 0) { if (isset($shipping_cost) && isset($taxRate_shipping) && !empty($shipping_cost) && !empty($taxRate_shipping)) { $taxValue_shipping = $shipping_cost * $taxRate_shipping; } } $products[] = array("price" => isset($shipping_cost) ? $shipping_cost : null, "quantity" => 1, "sku" => "shipping", 'taxName' => isset($taxName_shipping) ? $taxName_shipping : null, 'taxId' => isset($taxId_shipping) ? $taxId_shipping : null, 'taxRate' => isset($taxRate_shipping) ? $taxRate_shipping : null, 'taxValue' => isset($taxValue_shipping) ? $taxValue_shipping : null); } //UTC Time date_default_timezone_set("UTC"); $order_created = date("Y-m-d H:i:s", time()); $OrderArray = array('uid' => isset($vend_uid) ? $vend_uid : null, 'created' => isset($order_created) ? $order_created : null, "orderId" => isset($order_no) ? $order_no : null, "source" => "WooCommerce", 'register_id' => isset($registerDb) ? $registerDb : null, 'user_name' => isset($vend_username) ? $vend_username : null, 'primary_email' => isset($primary_email) && !empty($primary_email) ? $primary_email : null, 'total' => isset($get_total) ? $get_total : 0, 'total_tax' => isset($total_tax) ? $total_tax : 0, 'comments' => isset($comments) ? $comments : null, 'taxes_included' => $taxes_included, 'currency' => isset($currency) ? $currency : 'USD', 'shipping_method' => isset($shipping_method) ? $shipping_method : null, 'payment' => isset($payment) && !empty($payment) ? $payment : null, 'products' => isset($products) && !empty($products) ? $products : null, 'payment_type_id' => isset($payment_method_id) ? $payment_method_id : null, 'billingAddress' => isset($billingAddress) && !empty($billingAddress) ? $billingAddress : null, 'deliveryAddress' => isset($deliveryAddress) && !empty($deliveryAddress) ? $deliveryAddress : null); $json = json_encode($OrderArray); $apicall->linksync_postOrder($json); linksync_class::add('Order Sync Woo to Vend', 'success', 'Woo Order no:' . $order_no, $LAIDKey); } } else { linksync_class::add('Order Sync Woo to Vend', 'Error', 'Already Sent Order', $LAIDKey); } } }
function widget($args, $instance) { extract($args); extract($instance); global $product; $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base); ?> <section class="section section-product"> <div class="container"> <div class="row category"> <div class="col-xs-3 category-name"> <img src="<?php echo get_template_directory_uri(); ?> /img/<?php echo !empty($icon_class) ? $icon_class : 'category-woman'; ?> .png" class="img-responsive"> <?php if (!empty($title)) { echo '<span>' . $title . '</span>'; } ?> </div> <div class="col-xs-9 type-list"> <?php //echo $cat; $args_product_cat = array('type' => 'product', 'child_of' => 1, 'parent' => $cat, 'orderby' => 'name', 'order' => 'ASC', 'hide_empty' => 1, 'hierarchical' => 1, 'exclude' => '', 'include' => '', 'number' => '', 'taxonomy' => 'product_cat', 'pad_counts' => false); $product_list_cats = get_categories($args_product_cat); // print_r($product_list_cat); ?> <?php if (!empty($product_list_cats)) { ?> <ul class="type-list-ul"> <?php foreach ($product_list_cats as $i => $product_list_cat) { if ($i > 3) { break; } else { ?> <li class="type-list-item"><a href="<?php echo get_term_link($product_list_cat, 'product_cat'); ?> " cat-term="<?php echo $product_list_cat->term_id; ?> "><?php echo $product_list_cat->name; ?> </a> </li> <?php } } ?> <?php if (count($product_list_cats) > 4) { ?> <li class="type-list-item more"> <button type="button" class="btn dropdown-toggle more-btn" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> <span class="more-title">SẢN PHẨM KHÁC</span> <span class="caret"></span> <span class="sr-only">Toggle Dropdown</span> </button> <ul class="dropdown-menu"> <?php foreach ($product_list_cats as $i => $product_list_cat) { if ($i > 3) { ?> <li><a href="<?php echo get_term_link($product_list_cat, 'product_cat'); ?> " cat-term="<?php echo $product_list_cat->term_id; ?> "><?php echo $product_list_cat->name; ?> </a> </li> <?php } } ?> </ul> </li> <?php } ?> </ul> <?php } ?> </div> </div> <?php $product_widget_cat = new WP_Query(array('post_type' => 'product', 'showposts' => 2, 'tax_query' => array(array('taxonomy' => 'product_cat', 'field' => 'term_id', 'terms' => $cat)))); ?> <?php if ($product_widget_cat->have_posts()) { ?> <div class="row sample"> <?php while ($product_widget_cat->have_posts()) { $product_widget_cat->the_post(); ?> <div class="col-xs-6 sample-item"> <div class="thumbnail"> <a href="<?php the_permalink(); ?> "> <?php product_percent_2(); ?> <span class="sale-title">SALE</span> <span class="new-title">NEW</span> <?php the_post_thumbnail(array(236, 330, 'bfi_thumb' => true), array('class' => 'img-responsive')); ?> </a> <div class="caption clearfix"> <a href="<?php the_permalink(); ?> "><span class="caption-title"><?php hhs_brand(); ?> </span></a> <hr/> <?php $product = new WC_Product(get_the_ID()); ?> <p class="caption-description"><?php echo get_the_title() . $product->get_sku(); ?> </p> <div class="caption-price"> <?php $price = get_post_meta(get_the_ID(), '_regular_price', true); $sale = get_post_meta(get_the_ID(), '_sale_price', true); ?> <div class="price-info"> <?php echo '<p class="old-price">' . number_format($price, 0, '.', '.') . ' VNĐ</p>'; ?> <?php echo '<p class="new-price">' . number_format($sale, 0, '.', '.') . ' VNĐ</p>'; ?> </div> <div class="cart"> <a href="<?php echo esc_url($product->add_to_cart_url()); ?> "><img src="<?php echo get_template_directory_uri(); ?> /img/product-cart.png"></a> </div> </div> </div> </div> </div> <?php } wp_reset_postdata(); ?> </div> <?php } ?> </div> <!-- /.row row-no-padding --> </div> </section> <!-- /.section section-product --> <?php }
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; }
protected function getMultipleProductsInfo() { $payDataOperacion = array(); ///datos de la orden separados con # $productcode_array = array(); $description_array = array(); $name_array = array(); $sku_array = array(); $totalamount_array = array(); $quantity_array = array(); $price_array = array(); global $woocommerce; foreach ($woocommerce->cart->cart_contents as $cart_key => $cart_item_array) { $product = new WC_Product($cart_item_array['product_id']); $sku = $product->get_sku(); $terms = get_the_terms($cart_item_array['product_id'], 'product_cat'); $product_cat = "default"; if ($terms && !is_wp_error($terms)) { $product_cat = $terms[0]->name; } $productcode_array[] = $product_cat; $descripcion = $cart_item_array['data']->post->post_content == null ? '' : substr($this->_sanitize_string($cart_item_array['data']->post->post_content), 0, 50); $description_array[] = $descripcion; $name_array[] = str_replace('#', '', $cart_item_array['data']->post->post_title); $sku_array[] = str_replace('#', '', empty($sku) ? $cart_item_array['product_id'] : $sku); $totalamount_array[] = number_format($cart_item_array['line_total'], 2, ".", ""); $quantity_array[] = $cart_item_array['quantity']; $price_array[] = number_format($cart_item_array['data']->price, 2, ".", ""); } $payDataOperacion['CSITPRODUCTCODE'] = join('#', $productcode_array); $payDataOperacion['CSITPRODUCTDESCRIPTION'] = join("#", $description_array); $payDataOperacion['CSITPRODUCTNAME'] = join("#", $name_array); $payDataOperacion['CSITPRODUCTSKU'] = join("#", $sku_array); $payDataOperacion['CSITTOTALAMOUNT'] = join("#", $totalamount_array); $payDataOperacion['CSITQUANTITY'] = join("#", $quantity_array); $payDataOperacion['CSITUNITPRICE'] = join("#", $price_array); return $payDataOperacion; }
/** * Print the tracking pixel to wp_head */ public function fb_tracking_pixel() { // only show the pixel if a tracking ID is defined if (!$this->fbid) { return; } ?> <!-- Facebook Pixel Code --> <script> !function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod? n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n; n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0; t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window, document,'script','//connect.facebook.net/en_US/fbevents.js'); fbq('init', '<?php echo esc_html($this->fbid); ?> '); fbq('track', 'PageView'); <?php if (is_singular('product') && $this->event_viewcontent) { global $post; $product = wc_get_product($post->ID); $params = array(); $params['content_name'] = $product->get_title(); $params['content_ids'] = array($product->get_sku() ? $product->get_sku() : $product->id); $params['content_type'] = 'product'; $params['value'] = floatval($product->get_price()); $params['currency'] = get_woocommerce_currency(); ?> fbq('track', 'ViewContent', <?php echo json_encode($params); ?> ); <?php } ?> <?php if (is_order_received_page() && $this->event_purchase) { global $wp; $params = array(); $order_id = isset($wp->query_vars['order-received']) ? $wp->query_vars['order-received'] : 0; if ($order_id) { $params['order_id'] = $order_id; $order = new WC_Order($order_id); if ($order->get_items()) { $productids = array(); foreach ($order->get_items() as $item) { $product = $order->get_product_from_item($item); $productids[] = $product->get_sku() ? $product->get_sku() : $product->id; } $params['content_ids'] = $productids; } $params['content_type'] = 'product'; $params['value'] = $order->get_total(); $params['currency'] = get_woocommerce_currency(); } ?> fbq('track', 'Purchase', <?php echo json_encode($params); ?> ); <?php } elseif (is_checkout() && $this->event_checkout) { // get $cart to params $cart = WC()->cart->get_cart(); $productids = array(); foreach ($cart as $id => $item) { $product_id = $item['variation_id'] ? $item['variation_id'] : $item['product_id']; $product = new WC_Product($product_id); $productids[] = $product->get_sku() ? $product->get_sku() : $product->id; } $params = array(); $params['num_items'] = WC()->cart->cart_contents_count; $params['value'] = WC()->cart->total; $params['currency'] = get_woocommerce_currency(); $params['content_ids'] = $productids; ?> fbq('track', 'InitiateCheckout', <?php echo json_encode($params); ?> ); <?php } ?> </script> <noscript><img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=<?php echo esc_html($this->fbid); ?> &ev=PageView&noscript=1" /></noscript> <!-- End Facebook Pixel Code --> <?php }
/** * Get standard product data that applies to every product type * * @since 2.1 * @param WC_Product $product * @return WC_Product */ private function get_product_data($product) { return array('title' => $product->get_title(), 'id' => (int) $product->is_type('variation') ? $product->get_variation_id() : $product->id, 'created_at' => $this->server->format_datetime($product->get_post_data()->post_date_gmt), 'updated_at' => $this->server->format_datetime($product->get_post_data()->post_modified_gmt), 'type' => $product->product_type, 'status' => $product->get_post_data()->post_status, 'downloadable' => $product->is_downloadable(), 'virtual' => $product->is_virtual(), 'permalink' => $product->get_permalink(), 'sku' => $product->get_sku(), 'price' => $product->get_price(), 'regular_price' => $product->get_regular_price(), 'sale_price' => $product->get_sale_price() ? $product->get_sale_price() : null, 'price_html' => $product->get_price_html(), 'taxable' => $product->is_taxable(), 'tax_status' => $product->get_tax_status(), 'tax_class' => $product->get_tax_class(), 'managing_stock' => $product->managing_stock(), 'stock_quantity' => $product->get_stock_quantity(), 'in_stock' => $product->is_in_stock(), 'backorders_allowed' => $product->backorders_allowed(), 'backordered' => $product->is_on_backorder(), 'sold_individually' => $product->is_sold_individually(), 'purchaseable' => $product->is_purchasable(), 'featured' => $product->is_featured(), 'visible' => $product->is_visible(), 'catalog_visibility' => $product->visibility, 'on_sale' => $product->is_on_sale(), 'product_url' => $product->is_type('external') ? $product->get_product_url() : '', 'button_text' => $product->is_type('external') ? $product->get_button_text() : '', 'weight' => $product->get_weight() ? $product->get_weight() : null, 'dimensions' => array('length' => $product->length, 'width' => $product->width, 'height' => $product->height, 'unit' => get_option('woocommerce_dimension_unit')), 'shipping_required' => $product->needs_shipping(), 'shipping_taxable' => $product->is_shipping_taxable(), 'shipping_class' => $product->get_shipping_class(), 'shipping_class_id' => 0 !== $product->get_shipping_class_id() ? $product->get_shipping_class_id() : null, 'description' => wpautop(do_shortcode($product->get_post_data()->post_content)), 'short_description' => apply_filters('woocommerce_short_description', $product->get_post_data()->post_excerpt), 'reviews_allowed' => 'open' === $product->get_post_data()->comment_status, 'average_rating' => wc_format_decimal($product->get_average_rating(), 2), 'rating_count' => (int) $product->get_rating_count(), 'related_ids' => array_map('absint', array_values($product->get_related())), 'upsell_ids' => array_map('absint', $product->get_upsells()), 'cross_sell_ids' => array_map('absint', $product->get_cross_sells()), 'parent_id' => $product->post->post_parent, 'categories' => wp_get_post_terms($product->id, 'product_cat', array('fields' => 'names')), 'tags' => wp_get_post_terms($product->id, 'product_tag', array('fields' => 'names')), 'images' => $this->get_images($product), 'featured_src' => (string) wp_get_attachment_url(get_post_thumbnail_id($product->is_type('variation') ? $product->variation_id : $product->id)), 'attributes' => $this->get_attributes($product), 'downloads' => $this->get_downloads($product), 'download_limit' => (int) $product->download_limit, 'download_expiry' => (int) $product->download_expiry, 'download_type' => $product->download_type, 'purchase_note' => wpautop(do_shortcode(wp_kses_post($product->purchase_note))), 'total_sales' => metadata_exists('post', $product->id, 'total_sales') ? (int) get_post_meta($product->id, 'total_sales', true) : 0, 'variations' => array(), 'parent' => array(), 'grouped_products' => array()); }
/** * Helper method to return the item description, which is composed of item * meta flattened into a comma-separated string, if available. Otherwise the * product SKU is included. * * The description is automatically truncated to the 127 char limit. * * @since 3.0.0 * @param array $item cart or order item * @param \WC_Product $product product data * @return string */ private function get_item_description($item, $product) { if (empty($item['item_meta'])) { // cart item $item_desc = WC()->cart->get_item_data($item, true); $item_desc = str_replace("\n", ', ', rtrim($item_desc)); } else { // order item $item_meta = new WC_Order_Item_Meta($item['item_meta']); $item_meta = SV_WC_Plugin_Compatibility::get_formatted_item_meta($item_meta); if (!empty($item_meta)) { $item_desc = array(); foreach ($item_meta as $meta) { $item_desc[] = sprintf('%s: %s', $meta['label'], $meta['value']); } $item_desc = implode(', ', $item_desc); } else { $item_desc = is_callable(array($product, 'get_sku')) && $product->get_sku() ? sprintf(__('SKU: %s', WC_PayPal_Express::TEXT_DOMAIN), $product->get_sku()) : null; } } return SV_WC_Helper::str_truncate($item_desc, 127); }