The WooCommerce product variation class handles product variation data.
Author: WooThemes
Inheritance: extends WC_Product
Example #1
9
 function test_varation_save_attributes()
 {
     // Create a variable product with a color attribute.
     $product = new WC_Product_Variable();
     $attribute = new WC_Product_Attribute();
     $attribute->set_id(0);
     $attribute->set_name('color');
     $attribute->set_options(explode(WC_DELIMITER, 'green | red'));
     $attribute->set_visible(true);
     $attribute->set_variation(true);
     $product->set_attributes(array($attribute));
     $product->save();
     // Create a new variation with the color 'green'.
     $variation = new WC_Product_Variation();
     $variation->set_parent_id($product->get_id());
     $variation->set_attributes(array('color' => 'green'));
     $variation->set_status('private');
     $variation->save();
     // Now update some value unrelated to attributes.
     $variation = wc_get_product($variation->get_id());
     $variation->set_status('publish');
     $variation->save();
     // Load up the updated variation and verify that the saved state is correct.
     $loaded_variation = wc_get_product($variation->get_id());
     $this->assertEquals('publish', $loaded_variation->get_status('edit'));
     $_attribute = $loaded_variation->get_attributes('edit');
     $this->assertEquals('green', $_attribute['color']);
 }
    function add_sponsorship_project_to_cart()
    {
        global $post;
        $args = array('post_type' => 'product_variation', 'post_status' => array('private', 'publish'), 'numberposts' => -1, 'orderby' => 'id', 'order' => 'asc', 'post_parent' => $post->ID);
        $levels = get_posts($args);
        do_action('woocommerce_before_add_to_cart_button');
        ?>
		<div class="sp-levels">
			<?php 
        foreach ($levels as $level) {
            $level_product = new WC_Product_Variation($level->ID);
            $level_data = get_post_custom($level->ID);
            ?>
				<form id="level-<?php 
            echo $level->ID;
            ?>
-form" enctype="multipart/form-data" method="post" class="cart" action="<?php 
            echo $level_product->add_to_cart_url();
            ?>
">
					<a class="sp-level" rel="<?php 
            echo $level->ID;
            ?>
">
						<div class="sp-level-title">
							<?php 
            echo get_the_title($level->ID);
            ?>
							<div class="sp-level-amount">
								<strong>$<?php 
            echo isset($level_data['_price'][0]) ? $level_data['_price'][0] : 0;
            ?>
</strong>
							</div>
						</div>		
						<div class="sp-level-description">
							<?php 
            echo $level->post_content;
            ?>
						</div>
					</a>
				</form>
			<?php 
        }
        ?>
		</div>
		<script>
			jQuery('.sp-level').click(function() {
				var levelId = jQuery(this).attr('rel');
				jQuery('#level-' + levelId + '-form').submit();
				return false;
			})
		</script>
		<?php 
        do_action('woocommerce_after_add_to_cart_button');
    }
function display_price_in_variation_option_name($term)
{
    global $wpdb, $product;
    $term_temp = $term;
    $term = strtolower($term);
    $term = str_replace(' ', '-', $term);
    $result = $wpdb->get_col("SELECT slug FROM {$wpdb->prefix}terms WHERE name = '{$term}'");
    $term_slug = !empty($result) ? $result[0] : $term;
    $query = "SELECT postmeta.post_id AS product_id\nFROM {$wpdb->prefix}postmeta AS postmeta\nLEFT JOIN {$wpdb->prefix}posts AS products ON ( products.ID = postmeta.post_id )\nWHERE postmeta.meta_key LIKE 'attribute_%'\nAND postmeta.meta_value = '{$term_slug}'\nAND products.post_parent = {$product->id}";
    $variation_id = $wpdb->get_col($query);
    $parent = wp_get_post_parent_id($variation_id[0]);
    if ($parent > 0) {
        $_product = new WC_Product_Variation($variation_id[0]);
        $testVariable = $_product->get_variation_attributes();
        $itemPrice = strip_tags(woocommerce_price($_product->get_price()));
        $getPrice = $_product->get_price();
        $itemPriceInt = (int) $getPrice;
        $term = $term_temp;
        //this is where you can actually customize how the price is displayed
        if ($itemPriceInt > 0) {
            return $term . ' (' . $itemPrice . ' incl. GST)';
        } else {
            return $term . ' (' . $itemPrice . ')';
        }
    }
    return $term;
}
 /**
  * Convert a WC Product or Variation into a Square ItemVariation
  * See: https://docs.connect.squareup.com/api/connect/v1/#datatype-itemvariation
  *
  * @param WC_Product|WC_Product_Variation $variation
  * @param bool                            $include_inventory
  * @return array Formatted as a Square ItemVariation
  */
 public static function format_wc_variation_for_square_api($variation, $include_inventory = false)
 {
     $formatted = array('name' => null, 'pricing_type' => null, 'price_money' => null, 'sku' => null, 'track_inventory' => null, 'inventory_alert_type' => null, 'inventory_alert_threshold' => null, 'user_data' => null);
     if ($variation instanceof WC_Product) {
         $formatted['name'] = __('Regular', 'woocommerce-square');
         $formatted['price_money'] = array('currency_code' => apply_filters('woocommerce_square_currency', get_woocommerce_currency()), 'amount' => $variation->get_display_price() * 100);
         $formatted['sku'] = $variation->get_sku();
         if ($include_inventory && $variation->managing_stock()) {
             $formatted['track_inventory'] = true;
         }
     }
     if ($variation instanceof WC_Product_Variation) {
         $formatted['name'] = implode(', ', $variation->get_variation_attributes());
     }
     return array_filter($formatted);
 }
 public function create_vars()
 {
     global $product;
     if (!is_product() || !$product->is_type('variable')) {
         return;
     }
     $att_data_hook = get_option('mp_wc_vdopp_data_hook');
     // Hook data
     $att_dom_sel = get_option('mp_wc_vdopp_dom_selector');
     // DOM Selector
     $att_data_sel = get_option('mp_wc_vdopp_data_selector');
     // Data Selector
     $att_before_size = apply_filters('mp_wc_vdopp_before_size', rtrim(get_option('mp_wc_vdopp_before_size'))) . ' ';
     $att_before_weight = apply_filters('mp_wc_vdopp_before_weight', rtrim(get_option('mp_wc_vdopp_before_weight'))) . ' ';
     $att_after_size = apply_filters('mp_wc_vdopp_after_size', ' ' . ltrim(get_option('mp_wc_vdopp_after_size')));
     $att_after_weight = apply_filters('mp_wc_vdopp_after_weight', ' ' . ltrim(get_option('mp_wc_vdopp_after_weight')));
     $children = $product->get_children($args = '', $output = OBJECT);
     $i = 0;
     foreach ($children as $value) {
         $product_variatons = new WC_Product_Variation($value);
         if ($product_variatons->exists() && $product_variatons->variation_is_visible()) {
             $variations = $product_variatons->get_variation_attributes();
             foreach ($variations as $key => $variation) {
                 $this->variations[$i][$key] = $variation;
             }
             $weight = $product_variatons->get_weight();
             if ($weight) {
                 $weight .= get_option('woocommerce_weight_unit');
             }
             $this->variations[$i]['weight'] = $weight;
             $this->variations[$i]['dimensions'] = str_replace(' ', '', $product_variatons->get_dimensions());
             $i++;
         }
     }
     $this->variations = wp_json_encode($this->variations);
     $params = array('variations' => $this->variations, 'att_data_hook' => $att_data_hook, 'att_dom_sel' => $att_dom_sel, 'att_data_sel' => $att_data_sel, 'att_before_size' => $att_before_size, 'att_before_weight' => $att_before_weight, 'att_after_size' => $att_after_size, 'att_after_weight' => $att_after_weight, 'num_variations' => count($variations));
     // enqueue the script
     wp_enqueue_script('mp_wc_variation_details');
     wp_localize_script('mp_wc_variation_details', 'mp_wc_variations', $params);
 }
 function alert_box_function()
 {
     $child_id = $_POST['child_id'];
     $display_stock_alert_form = 'false';
     if ($child_id && !empty($child_id)) {
         $child_obj = new WC_Product_Variation($child_id);
         $dc_settings = get_dc_plugin_settings();
         $stock_quantity = get_post_meta($child_id, '_stock', true);
         $manage_stock = get_post_meta($child_id, '_manage_stock', true);
         if (isset($stock_quantity) && $manage_stock == 'yes') {
             if ($stock_quantity <= 0) {
                 if ($child_obj->backorders_allowed()) {
                     if (isset($dc_settings['is_enable_backorders']) && $dc_settings['is_enable_backorders'] == 'Enable') {
                         $display_stock_alert_form = 'true';
                     }
                 } else {
                     $display_stock_alert_form = 'true';
                 }
             }
         }
     }
     echo $display_stock_alert_form;
     die;
 }
<table class="uni-wishlist-table" cellspacing="0">
	<thead>
		<tr>
			<th class="product-name">&nbsp;</th>
			<th class="product-price">&nbsp;</th>
			<th class="product-add-to-cart">&nbsp;</th>
            <th class="product-remove">&nbsp;</th>
		</tr>
	</thead>
	<tbody>
    <?php 
$i = 1;
foreach ($aUsersWishlist as $iProductId => $aWshlistItemData) {
    if ($aWshlistItemData['type'] == 'variable' && !empty($aWshlistItemData['vid'])) {
        foreach ($aWshlistItemData['vid'] as $iVariableProductId) {
            $oProduct = new WC_Product_Variation($iVariableProductId, $iProductId);
            if ($oProduct->exists()) {
                include UniWishlist()->plugin_path() . '/includes/views/item-variation-table-row.php';
            }
        }
    } else {
        $oProduct = new WC_Product($iProductId);
        if ($oProduct->exists()) {
            include UniWishlist()->plugin_path() . '/includes/views/item-table-row.php';
        }
    }
    $i++;
}
?>
    </tbody>
</table>
Example #8
0
 * @author 		WooThemes
 * @package 	WooCommerce/Templates
 * @version     1.6.4
 */
if (!defined('ABSPATH')) {
    exit;
    // Exit if accessed directly
}
global $post, $product;
$sale_percent = 0;
if ($product->is_on_sale() && $product->product_type != 'grouped') {
    if ($product->product_type == 'variable') {
        $available_variations = $product->get_available_variations();
        for ($i = 0; $i < count($available_variations); ++$i) {
            $variation_id = $available_variations[$i]['variation_id'];
            $variable_product1 = new WC_Product_Variation($variation_id);
            $regular_price = $variable_product1->get_regular_price();
            $sales_price = $variable_product1->get_sale_price();
            $price = $variable_product1->get_price();
            if ($sales_price != $regular_price && $sales_price == $price) {
                $percentage = round(($regular_price - $sales_price) / $regular_price * 100, 1);
                if ($percentage > $sale_percent) {
                    $sale_percent = $percentage;
                }
            }
        }
    } else {
        $sale_percent = round(($product->get_regular_price() - $product->get_sale_price()) / $product->get_regular_price() * 100, 1);
    }
}
?>
 /**
  *
  */
 public function filter_woocommerce_add_to_cart_validation($valid, $product_id, $quantity, $variation_id = '', $variations = '')
 {
     global $woocommerce;
     $product = wc_get_product($product_id);
     if ($product->product_type === "variable") {
         $deductornot = get_post_meta($variation_id, '_deductornot', true);
         $deductamount = get_post_meta($variation_id, '_deductamount', true);
         $getvarclass = new WC_Product_Variation($variation_id);
         //reset($array);
         $aatrs = $getvarclass->get_variation_attributes();
         foreach ($aatrs as $key => $value) {
             $slug = $value;
             $cat = str_replace('attribute_', '', $key);
         }
         $titlevaria = get_term_by('slug', $slug, $cat);
         $backorder = get_post_meta($product->post->ID, '_backorders', true);
         $string = WC_Cart::get_item_data($cart_item, $flat);
         //var_dump($string);
         if ($backorder == 'no') {
             if ($deductornot == "yes") {
                 $currentstock = $product->get_stock_quantity();
                 $reduceamount = intval($quantity) * intval($deductamount);
                 $currentavail = intval($currentstock / $deductamount);
                 if ($reduceamount > $currentstock) {
                     $valid = false;
                     wc_add_notice('' . __('You that goes over our availble stock amount.', 'woocommerce') . __('We have: ', 'woocommerce') . $currentavail . ' ' . $product->post->post_title . ' ' . $titlevaria->name . '\'s ' . __(' available.', 'woocommerce'), 'error');
                     return $valid;
                 } else {
                     $valid = true;
                     return $valid;
                 }
             } else {
                 return true;
             }
         }
     }
     return true;
 }
 /**
  * Save variations.
  *
  * @throws WC_REST_Exception REST API exceptions.
  * @param WC_Product      $product          Product instance.
  * @param WP_REST_Request $request          Request data.
  * @param bool            $single_variation True if saving only a single variation.
  * @return bool
  */
 protected function save_variations_data($product, $request, $single_variation = false)
 {
     global $wpdb;
     if ($single_variation) {
         $variations = array($request);
     } else {
         $variations = $request['variations'];
     }
     foreach ($variations as $menu_order => $data) {
         $variation_id = isset($data['id']) ? absint($data['id']) : 0;
         $variation = new WC_Product_Variation($variation_id);
         // Create initial name and status.
         if (!$variation->get_slug()) {
             /* translators: 1: variation id 2: product name */
             $variation->set_name(sprintf(__('Variation #%1$s of %2$s', 'woocommerce'), $variation->get_id(), $product->get_name()));
             $variation->set_status(isset($data['visible']) && false === $data['visible'] ? 'private' : 'publish');
         }
         // Parent ID.
         $variation->set_parent_id($product->get_id());
         // Menu order.
         $variation->set_menu_order($menu_order);
         // Status.
         if (isset($data['visible'])) {
             $variation->set_status(false === $data['visible'] ? 'private' : 'publish');
         }
         // SKU.
         if (isset($data['sku'])) {
             $variation->set_sku(wc_clean($data['sku']));
         }
         // Thumbnail.
         if (isset($data['image']) && is_array($data['image'])) {
             $image = $data['image'];
             $image = current($image);
             if (is_array($image)) {
                 $image['position'] = 0;
             }
             $variation = $this->save_product_images($variation, array($image));
         }
         // Virtual variation.
         if (isset($data['virtual'])) {
             $variation->set_virtual($data['virtual']);
         }
         // Downloadable variation.
         if (isset($data['downloadable'])) {
             $variation->set_downloadable($data['downloadable']);
         }
         // Downloads.
         if ($variation->get_downloadable()) {
             // Downloadable files.
             if (isset($data['downloads']) && is_array($data['downloads'])) {
                 $variation = $this->save_downloadable_files($variation, $data['downloads']);
             }
             // Download limit.
             if (isset($data['download_limit'])) {
                 $variation->set_download_limit($data['download_limit']);
             }
             // Download expiry.
             if (isset($data['download_expiry'])) {
                 $variation->set_download_expiry($data['download_expiry']);
             }
         }
         // Shipping data.
         $variation = $this->save_product_shipping_data($variation, $data);
         // Stock handling.
         if (isset($data['manage_stock'])) {
             $variation->set_manage_stock($data['manage_stock']);
         }
         if (isset($data['in_stock'])) {
             $variation->set_stock_status(true === $data['in_stock'] ? 'instock' : 'outofstock');
         }
         if (isset($data['backorders'])) {
             $variation->set_backorders($data['backorders']);
         }
         if ($variation->get_manage_stock()) {
             if (isset($data['stock_quantity'])) {
                 $variation->set_stock_quantity($data['stock_quantity']);
             } elseif (isset($data['inventory_delta'])) {
                 $stock_quantity = wc_stock_amount($variation->get_stock_amount());
                 $stock_quantity += wc_stock_amount($data['inventory_delta']);
                 $variation->set_stock_quantity($stock_quantity);
             }
         } else {
             $variation->set_backorders('no');
             $variation->set_stock_quantity('');
         }
         // Regular Price.
         if (isset($data['regular_price'])) {
             $variation->set_regular_price($data['regular_price']);
         }
         // Sale Price.
         if (isset($data['sale_price'])) {
             $variation->set_sale_price($data['sale_price']);
         }
         if (isset($data['date_on_sale_from'])) {
             $variation->set_date_on_sale_from($data['date_on_sale_from']);
         }
         if (isset($data['date_on_sale_to'])) {
             $variation->set_date_on_sale_to($data['date_on_sale_to']);
         }
         // Tax class.
         if (isset($data['tax_class'])) {
             $variation->set_tax_class($data['tax_class']);
         }
         // Description.
         if (isset($data['description'])) {
             $variation->set_description(wp_kses_post($data['description']));
         }
         // Update taxonomies.
         if (isset($data['attributes'])) {
             $attributes = array();
             $parent_attributes = $product->get_attributes();
             foreach ($data['attributes'] as $attribute) {
                 $attribute_id = 0;
                 $attribute_name = '';
                 // Check ID for global attributes or name for product attributes.
                 if (!empty($attribute['id'])) {
                     $attribute_id = absint($attribute['id']);
                     $attribute_name = wc_attribute_taxonomy_name_by_id($attribute_id);
                 } elseif (!empty($attribute['name'])) {
                     $attribute_name = sanitize_title($attribute['name']);
                 }
                 if (!$attribute_id && !$attribute_name) {
                     continue;
                 }
                 if (!isset($parent_attributes[$attribute_name]) || !$parent_attributes[$attribute_name]->get_variation()) {
                     continue;
                 }
                 $attribute_key = sanitize_title($parent_attributes[$attribute_name]->get_name());
                 $attribute_value = isset($attribute['option']) ? wc_clean(stripslashes($attribute['option'])) : '';
                 if ($parent_attributes[$attribute_name]->is_taxonomy()) {
                     // If dealing with a taxonomy, we need to get the slug from the name posted to the API.
                     $term = get_term_by('name', $attribute_value, $attribute_name);
                     if ($term && !is_wp_error($term)) {
                         $attribute_value = $term->slug;
                     } else {
                         $attribute_value = sanitize_title($attribute_value);
                     }
                 }
                 $attributes[$attribute_key] = $attribute_value;
             }
             $variation->set_attributes($attributes);
         }
         $variation->save();
         do_action('woocommerce_rest_save_product_variation', $variation->get_id(), $menu_order, $data);
     }
     return true;
 }
 function bulk_order_variation_search()
 {
     // Query for suggestions
     $term = $_REQUEST['term'];
     $excluded_products = array();
     $excluded_products = apply_filters('wc_bulk_order_excluded_products', $excluded_products);
     $included_products = array();
     $included_products = apply_filters('wc_bulk_order_included_products', $included_products);
     if (empty($term)) {
         die;
     }
     $products1 = array('post_type' => array('product_variation'), 'post_status' => array('publish'), 'post_parent' => $term, 'fields' => 'ids', 'post__not_in' => $excluded_products, 'post__in' => $included_products, 'suppress_filters' => false, 'no_found_rows' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'cache_results' => false);
     $products = get_posts($products1);
     // JSON encode and echo
     // Initialise suggestions array
     global $post, $woocommerce, $product;
     $suggestions = '';
     foreach ($products as $prod) {
         $post_type = get_post_type($prod);
         if ('product_variation' == $post_type) {
             $product = new WC_Product_Variation($prod);
             $parent = wc_get_product($prod);
             $id = $product->variation_id;
             $price = number_format((double) $product->price, 2, '.', '');
             $price_html = $product->get_price_html();
             if (preg_match('/<ins>(.*?)<\\/ins>/', $price_html)) {
                 preg_match('/<ins>(.*?)<\\/ins>/', $price_html, $matches);
                 $price_html = $matches[1];
             }
             $price_html = strip_tags($price_html);
             $price = $price_html;
             $price = apply_filters('wc_bulk_order_form_price', $price, $product);
             $sku = $product->get_sku();
             $title = '';
             $attributes = $product->get_variation_attributes();
             $img = apply_filters('woocommerce_placeholder_img_src', WC_Bulk_Order_Form_Compatibility::WC()->plugin_url() . '/assets/images/placeholder.png');
             foreach ($attributes as $name => $value) {
                 $name = str_ireplace("attribute_", "", $name);
                 $terms = get_the_terms($product->id, $name);
                 foreach ($terms as $term) {
                     if (strtolower($term->name) == $value) {
                         $value = $term->name;
                     }
                 }
                 $attr_name = $name;
                 $attr_value = str_replace('-', ' ', $value);
                 if ($this->options['attribute_style'] === 'true') {
                     $title .= $attr_value . ' ';
                 } else {
                     if (strstr($attr_name, 'pa_')) {
                         $atts = get_the_terms($parent->id, $attr_name);
                         $attr_name_clean = WC_Bulk_Order_Form_Compatibility::wc_attribute_label($attr_name);
                     } else {
                         $np = explode("-", str_replace("attribute_", "", $attr_name));
                         $attr_name_clean = ucwords(implode(" ", $np));
                     }
                     $attr_name_clean = str_replace("attribute_pa_", "", $attr_name_clean);
                     $attr_name_clean = str_replace("Attribute_pa_", "", $attr_name_clean);
                     $title .= ' ' . $attr_name_clean . ": " . $attr_value;
                 }
                 $title = html_entity_decode($title, ENT_COMPAT, 'UTF-8');
             }
             $parent_image = wp_get_attachment_image_src(get_post_thumbnail_id($id), 'thumbnail');
             $parent_image = $parent_image[0];
             $img = wp_get_attachment_image_src(get_post_thumbnail_id($parent->id), 'thumbnail');
             $img = $img[0];
             if (!empty($img)) {
                 $img = $img;
             } elseif (!empty($parent_image)) {
                 $img = $parent_image;
             } else {
                 $img = apply_filters('woocommerce_placeholder_img_src', WC_Bulk_Order_Form_Compatibility::WC()->plugin_url() . '/assets/images/placeholder.png');
             }
         }
         if (!empty($id)) {
             $symbol = get_woocommerce_currency_symbol();
             $symbol = html_entity_decode($symbol, ENT_COMPAT, 'UTF-8');
             $price = html_entity_decode($price, ENT_COMPAT, 'UTF-8');
             // Initialise suggestion array
             $suggestion = array();
             $variation_switch_data = isset($this->options['variation_search_format']) ? $this->options['variation_search_format'] : '1';
             switch ($variation_switch_data) {
                 case 1:
                     if (!empty($sku)) {
                         $label = $sku . ' - ' . $title . ' - ' . $price;
                     } else {
                         $label = $title . ' - ' . $price;
                     }
                     break;
                 case 2:
                     if (!empty($sku)) {
                         $label = $title . ' - ' . $price . ' - ' . $sku;
                     } else {
                         $label = $title . ' - ' . $price;
                     }
                     break;
                 case 3:
                     $label = $title . ' - ' . $price;
                     break;
                 case 4:
                     if (!empty($sku)) {
                         $label = $title . ' - ' . $sku;
                     } else {
                         $label = $title;
                     }
                     break;
                 case 5:
                     $label = $title;
                     break;
             }
             $suggestion['label'] = $label;
             $suggestion['price'] = $price;
             $suggestion['symbol'] = $symbol;
             $suggestion['id'] = $id;
             $suggestion['imgsrc'] = $img;
             $suggestion['attributes'] = $product_attributes;
             if (!empty($variation_id)) {
                 $suggestion['variation_id'] = $variation_id;
             }
             // Add suggestion to suggestions array
             $suggestions[] = $suggestion;
         }
     }
     // JSON encode and echo
     $response = $_GET["callback"] . "(" . json_encode($suggestions) . ")";
     //print_r($response);
     echo $response;
     // Don't forget to exit!
     exit;
 }
 /**
  * Maybe display pricing table or anchor to display pricing table in modal
  * 
  * @access public
  * @return void
  */
 public function product_page_pricing_table()
 {
     if ($this->opt['settings']['display_table'] == 'hide' && (!isset($this->opt['settings']['display_offers']) || $this->opt['settings']['display_offers'] == 'hide')) {
         return;
     }
     global $product;
     if (!$product) {
         return;
     }
     // Load required classes
     require_once RP_WCDPD_PLUGIN_PATH . 'includes/classes/Pricing.php';
     $selected_rule = null;
     // Iterate over pricing rules and use the first one that has this product in conditions (or does not have if condition "not in list")
     if (isset($this->opt['pricing']['sets']) && count($this->opt['pricing']['sets'])) {
         foreach ($this->opt['pricing']['sets'] as $rule_key => $rule) {
             if ($rule['method'] == 'quantity' && ($validated_rule = RP_WCDPD_Pricing::validate_rule($rule))) {
                 if ($validated_rule['selection_method'] == 'all' && $this->user_matches_rule($validated_rule)) {
                     $selected_rule = $validated_rule;
                     break;
                 }
                 if ($validated_rule['selection_method'] == 'categories_include' && count(array_intersect($this->get_product_categories($product->id), $validated_rule['categories'])) > 0 && $this->user_matches_rule($validated_rule)) {
                     $selected_rule = $validated_rule;
                     break;
                 }
                 if ($validated_rule['selection_method'] == 'categories_exclude' && count(array_intersect($this->get_product_categories($product->id), $validated_rule['categories'])) == 0 && $this->user_matches_rule($validated_rule)) {
                     $selected_rule = $validated_rule;
                     break;
                 }
                 if ($validated_rule['selection_method'] == 'products_include' && in_array($product->id, $validated_rule['products']) && $this->user_matches_rule($validated_rule)) {
                     $selected_rule = $validated_rule;
                     break;
                 }
                 if ($validated_rule['selection_method'] == 'products_exclude' && !in_array($product->id, $validated_rule['products']) && $this->user_matches_rule($validated_rule)) {
                     $selected_rule = $validated_rule;
                     break;
                 }
             }
         }
     }
     if (is_array($selected_rule)) {
         // Quantity
         if ($selected_rule['method'] == 'quantity' && in_array($this->opt['settings']['display_table'], array('modal', 'inline')) && isset($selected_rule['pricing'])) {
             if ($product->product_type == 'variable') {
                 $product_variations = $product->get_available_variations();
             }
             // For variable products only - check if prices differ for different variations
             $multiprice_variable_product = false;
             if ($product->product_type == 'variable' && !empty($product_variations)) {
                 $last_product_variation = array_slice($product_variations, -1);
                 $last_product_variation_object = new WC_Product_Variable($last_product_variation[0]['variation_id']);
                 $last_product_variation_price = $last_product_variation_object->get_price();
                 foreach ($product_variations as $variation) {
                     $variation_object = new WC_Product_Variable($variation['variation_id']);
                     if ($variation_object->get_price() != $last_product_variation_price) {
                         $multiprice_variable_product = true;
                     }
                 }
             }
             if ($multiprice_variable_product) {
                 $variation_table_data = array();
                 foreach ($product_variations as $variation) {
                     $variation_product = new WC_Product_Variation($variation['variation_id']);
                     $variation_table_data[$variation['variation_id']] = $this->pricing_table_calculate_adjusted_prices($selected_rule['pricing'], $variation_product->get_price());
                 }
                 require_once RP_WCDPD_PLUGIN_PATH . 'includes/views/frontend/table-variable.php';
             } else {
                 if ($product->product_type == 'variable' && !empty($product_variations)) {
                     $variation_product = new WC_Product_Variation($last_product_variation[0]['variation_id']);
                     $table_data = $this->pricing_table_calculate_adjusted_prices($selected_rule['pricing'], $variation_product->get_price());
                 } else {
                     $table_data = $this->pricing_table_calculate_adjusted_prices($selected_rule['pricing'], $product->get_price());
                 }
                 require_once RP_WCDPD_PLUGIN_PATH . 'includes/views/frontend/table-' . $this->opt['settings']['display_table'] . '-' . $this->opt['settings']['pricing_table_style'] . '.php';
             }
         }
     }
 }
 /**
  * Returns the sign up fee (excluding tax) by filtering the products price used in
  * @see WC_Product::get_price_excluding_tax( $qty )
  *
  * @return string
  */
 public function get_sign_up_fee_excluding_tax($qty = 1)
 {
     add_filter('woocommerce_get_price', array(&$this, 'get_sign_up_fee'), 100, 0);
     $sign_up_fee_excluding_tax = parent::get_price_excluding_tax($qty);
     remove_filter('woocommerce_get_price', array(&$this, 'get_sign_up_fee'), 100, 0);
     return $sign_up_fee_excluding_tax;
 }
Example #14
0
 protected function post_process()
 {
     $pageposts = is_array($this->results) ? $this->results : array();
     $options = $this->options;
     $searchData = $this->searchData;
     $s = $this->s;
     $_s = $this->_s;
     $performance_options = get_option('asl_performance');
     if (is_multisite()) {
         $home_url = network_home_url();
     } else {
         $home_url = home_url();
     }
     foreach ($pageposts as $k => $v) {
         $r =& $pageposts[$k];
         $r->title = w_isset_def($r->title, null);
         $r->content = w_isset_def($r->content, null);
         $r->image = w_isset_def($r->image, null);
         $r->author = w_isset_def($r->author, null);
         $r->date = w_isset_def($r->date, null);
     }
     /* Images, title, desc */
     foreach ($pageposts as $k => $v) {
         // Let's simplify things
         $r =& $pageposts[$k];
         $r->title = apply_filters('asl_result_title_before_prostproc', $r->title, $r->id);
         $r->content = apply_filters('asl_result_content_before_prostproc', $r->content, $r->id);
         $r->image = apply_filters('asl_result_image_before_prostproc', $r->image, $r->id);
         $r->author = apply_filters('asl_result_author_before_prostproc', $r->author, $r->id);
         $r->date = apply_filters('asl_result_date_before_prostproc', $r->date, $r->id);
         $r->link = get_permalink($v->id);
         $image_settings = $searchData['image_options'];
         if ($image_settings['show_images'] != 0) {
             $im = $this->getBFIimage($r);
             if ($im != '' && strpos($im, "mshots/v1") === false && w_isset_def($performance_options['image_cropping'], 0) == 1) {
                 if (w_isset_def($image_settings['image_transparency'], 1) == 1) {
                     $bfi_params = array('width' => $image_settings['image_width'], 'height' => $image_settings['image_height'], 'crop' => true);
                 } else {
                     $bfi_params = array('width' => $image_settings['image_width'], 'height' => $image_settings['image_height'], 'crop' => true, 'color' => wpdreams_rgb2hex($image_settings['image_bg_color']));
                 }
                 $r->image = bfi_thumb($im, $bfi_params);
             } else {
                 $r->image = $im;
             }
         }
         if (!isset($searchData['titlefield']) || $searchData['titlefield'] == "0" || is_array($searchData['titlefield'])) {
             $r->title = get_the_title($r->id);
         } else {
             if ($searchData['titlefield'] == "1") {
                 if (strlen($r->excerpt) >= 200) {
                     $r->title = wd_substr_at_word($r->excerpt, 200);
                 } else {
                     $r->title = $r->excerpt;
                 }
             } else {
                 $mykey_values = get_post_custom_values($searchData['titlefield'], $r->id);
                 if (isset($mykey_values[0])) {
                     $r->title = $mykey_values[0];
                 } else {
                     $r->title = get_the_title($r->id);
                 }
             }
         }
         //remove the search shortcodes properly
         add_shortcode('wpdreams_ajaxsearchpro', array($this, 'return_empty_string'));
         add_shortcode('wpdreams_ajaxsearchlite', array($this, 'return_empty_string'));
         if (!isset($searchData['striptagsexclude'])) {
             $searchData['striptagsexclude'] = "<a><span>";
         }
         if (!isset($searchData['descriptionfield']) || $searchData['descriptionfield'] == "0" || is_array($searchData['descriptionfield'])) {
             if (w_isset_def($searchData['strip_shortcodes'], 0) == 1) {
                 $r->content = strip_shortcodes($r->content);
             }
             if (function_exists('qtrans_getLanguage')) {
                 $r->content = apply_filters('the_content', $r->content);
             }
             $_content = strip_tags($r->content);
         } else {
             if ($searchData['descriptionfield'] == "1") {
                 $_content = strip_tags($r->excerpt);
             } else {
                 if ($searchData['descriptionfield'] == "2") {
                     $_content = strip_tags(get_the_title($r->id));
                 } else {
                     $mykey_values = get_post_custom_values($searchData['descriptionfield'], $r->id);
                     if (isset($mykey_values[0])) {
                         $_content = strip_tags($mykey_values[0]);
                     } else {
                         $_content = strip_tags($r->content);
                     }
                 }
             }
         }
         if ($_content == "" && $r->content != '') {
             $_content = $r->content;
         }
         if ($_content != "") {
             $_content = str_replace('[wpdreams_ajaxsearchlite]', "", $_content);
         }
         if ($_content != "") {
             $_content = apply_filters('the_content', $_content);
         }
         // Remove styles and scripts
         $_content = preg_replace(array('#<script(.*?)>(.*?)</script>#is', '#<style(.*?)>(.*?)</style>#is'), '', $_content);
         $_content = strip_tags($_content);
         // Get the words from around the search phrase, or just the description
         if (w_isset_def($searchData['description_context'], 1) == 1 && count($_s) > 0) {
             $_content = $this->context_find($_content, $_s[0], floor($searchData['descriptionlength'] / 6), $searchData['descriptionlength']);
         } else {
             if ($_content != '' && strlen($_content) > $searchData['descriptionlength']) {
                 $_content = wd_substr_at_word($_content, $searchData['descriptionlength']) . "...";
             }
         }
         $_content = wd_closetags($_content);
         $r->content = $_content;
         // -------------------------- Woocommerce Fixes -----------------------------
         // A trick to fix the url
         if ($r->post_type == 'product_variation' && class_exists('WC_Product_Variation')) {
             $r->title = preg_replace("/(Variation) \\#(\\d+) (of)/si", '', $r->title);
             $wc_prod_var_o = new WC_Product_Variation($r->id);
             $r->link = $wc_prod_var_o->get_permalink();
         }
         // --------------------------------------------------------------------------
         $r->title = apply_filters('asl_result_title_after_prostproc', $r->title, $r->id);
         $r->content = apply_filters('asl_result_content_after_prostproc', $r->content, $r->id);
         $r->image = apply_filters('asl_result_image_after_prostproc', $r->image, $r->id);
         $r->author = apply_filters('asl_result_author_after_prostproc', $r->author, $r->id);
         $r->date = apply_filters('asl_result_date_after_prostproc', $r->date, $r->id);
     }
     /* !Images, title, desc */
     //var_dump($pageposts); die();
     $this->results = $pageposts;
     return $pageposts;
 }
 /**
  * Post-processes the results
  *
  * @return array of results
  */
 protected function post_process()
 {
     $pageposts = is_array($this->results) ? $this->results : array();
     $options = $this->options;
     $searchId = $this->searchId;
     $searchData = $this->searchData;
     $s = $this->s;
     $_s = $this->_s;
     // No post processing is needed on non-ajax search
     if (isset($options['non_ajax_search'])) {
         $this->results = $pageposts;
         return $pageposts;
     }
     if (is_multisite()) {
         $home_url = network_home_url();
     } else {
         $home_url = home_url();
     }
     foreach ($pageposts as $k => $v) {
         $r =& $pageposts[$k];
         $r->title = w_isset_def($r->title, null);
         $r->content = w_isset_def($r->content, null);
         $r->image = w_isset_def($r->image, null);
         $r->author = w_isset_def($r->author, null);
         $r->date = w_isset_def($r->date, null);
     }
     aspDebug::start('--searchContent-posptrocess');
     /* Images, title, desc */
     foreach ($pageposts as $k => $v) {
         // Let's simplify things
         $r =& $pageposts[$k];
         if (isset($options['switch_on_preprocess']) && is_multisite()) {
             switch_to_blog($r->blogid);
         }
         $r = apply_filters('asp_result_before_prostproc', $r, $searchId);
         $r->title = apply_filters('asp_result_title_before_prostproc', $r->title, $r->id, $searchId);
         $r->content = apply_filters('asp_result_content_before_prostproc', $r->content, $r->id, $searchId);
         $r->image = apply_filters('asp_result_image_before_prostproc', $r->image, $r->id, $searchId);
         $r->author = apply_filters('asp_result_author_before_prostproc', $r->author, $r->id, $searchId);
         $r->date = apply_filters('asp_result_date_before_prostproc', $r->date, $r->id, $searchId);
         $r->link = get_permalink($v->id);
         // ---- URL FIX for WooCommerce product variations
         if ($r->post_type == 'product_variation' && class_exists('WC_Product_Variation')) {
             $wc_prod_var_o = new WC_Product_Variation($r->id);
             $r->link = $wc_prod_var_o->get_permalink();
         }
         $caching_options = w_false_def(get_option('asp_caching'), get_option('asp_caching_def'));
         $use_bfi = w_isset_def($caching_options['use_bfi_thumb'], 1);
         $image_settings = $searchData['image_options'];
         if ($image_settings['show_images'] != 0) {
             if ($image_settings['image_cropping'] == 0) {
                 // Use the BFI parser, but no caching
                 $im = $this->getBFIimage($r);
                 if ($im != '') {
                     $r->image = $im;
                 }
             } else {
                 if ($use_bfi == 0) {
                     $im = $this->getCachedImage($r);
                     if ($im != '') {
                         $r->image = $im;
                     }
                 } else {
                     $im = $this->getBFIimage($r);
                     if ($im != '' && strpos($im, "mshots/v1") === false) {
                         if (w_isset_def($image_settings['image_transparency'], 1) == 1) {
                             $bfi_params = array('width' => $image_settings['image_width'], 'height' => $image_settings['image_height'], 'crop' => true);
                         } else {
                             $bfi_params = array('width' => $image_settings['image_width'], 'height' => $image_settings['image_height'], 'crop' => true, 'color' => wpdreams_rgb2hex($image_settings['image_bg_color']));
                         }
                         $r->image = bfi_thumb($im, $bfi_params);
                     } else {
                         $r->image = $im;
                     }
                 }
             }
         }
         if (!isset($searchData['titlefield']) || $searchData['titlefield'] == "0" || is_array($searchData['titlefield'])) {
             $r->title = get_the_title($r->id);
         } else {
             if ($searchData['titlefield'] == "1") {
                 if (strlen($r->excerpt) >= 200) {
                     $r->title = wd_substr_at_word($r->excerpt, 200);
                 } else {
                     $r->title = $r->excerpt;
                 }
             } else {
                 $mykey_values = get_post_custom_values($searchData['titlefield'], $r->id);
                 if (isset($mykey_values[0])) {
                     $r->title = $mykey_values[0];
                 } else {
                     $r->title = get_the_title($r->id);
                 }
             }
         }
         $r->title = $this->adv_title($r->title, $r->id);
         if (!isset($searchData['striptagsexclude'])) {
             $searchData['striptagsexclude'] = "<a><span>";
         }
         //remove the search shortcode properly
         add_shortcode('wpdreams_ajaxsearchpro', array($this, 'return_empty_string'));
         if (!isset($searchData['descriptionfield']) || $searchData['descriptionfield'] == "0" || is_array($searchData['descriptionfield'])) {
             if (function_exists('qtrans_getLanguage')) {
                 $r->content = apply_filters('the_content', $r->content, $searchId);
             }
             $_content = strip_tags($r->content, $searchData['striptagsexclude']);
         } else {
             if ($searchData['descriptionfield'] == "1") {
                 $_content = strip_tags($r->excerpt, $searchData['striptagsexclude']);
             } else {
                 if ($searchData['descriptionfield'] == "2") {
                     $_content = strip_tags(get_the_title($r->id), $searchData['striptagsexclude']);
                 } else {
                     $mykey_values = get_post_custom_values($searchData['descriptionfield'], $r->id);
                     if (isset($mykey_values[0])) {
                         $_content = strip_tags($mykey_values[0], $searchData['striptagsexclude']);
                     } else {
                         $_content = strip_tags($r->content, $searchData['striptagsexclude']);
                     }
                 }
             }
         }
         if ($_content == "") {
             $_content = $r->content;
         }
         if (isset($searchData['runshortcode']) && $searchData['runshortcode'] == 1) {
             if ($_content != "") {
                 $_content = apply_filters('the_content', $_content, $searchId);
             }
         }
         if (isset($searchData['stripshortcode']) && $searchData['stripshortcode'] == 1) {
             if ($_content != "") {
                 $_content = strip_shortcodes($_content);
             }
         }
         // Remove styles and scripts
         $_content = preg_replace(array('#<script(.*?)>(.*?)</script>#is', '#<style(.*?)>(.*?)</style>#is'), '', $_content);
         $_content = strip_tags($_content, $searchData['striptagsexclude']);
         if ($_content != '' && strlen($_content) > $searchData['descriptionlength']) {
             $_content = wd_substr_at_word($_content, $searchData['descriptionlength']) . "...";
         }
         $_content = wd_closetags($_content);
         $r->content = $this->adv_desc($_content, $r->id);
         // -------------------------- Woocommerce Fixes -----------------------------
         // A trick to fix the url
         if ($r->post_type == 'product_variation' && class_exists('WC_Product_Variation')) {
             $r->title = preg_replace("/(Variation) \\#(\\d+) (of)/si", '', $r->title);
             $wc_prod_var_o = new WC_Product_Variation($r->id);
             $r->link = $wc_prod_var_o->get_permalink();
         }
         // --------------------------------------------------------------------------
         $r = apply_filters('asp_result_after_prostproc', $r, $searchId);
         $r->title = apply_filters('asp_result_title_after_prostproc', $r->title, $r->id, $searchId);
         $r->content = apply_filters('asp_result_content_after_prostproc', $r->content, $r->id, $searchId);
         $r->image = apply_filters('asp_result_image_after_prostproc', $r->image, $r->id, $searchId);
         $r->author = apply_filters('asp_result_author_after_prostproc', $r->author, $r->id, $searchId);
         $r->date = apply_filters('asp_result_date_after_prostproc', $r->date, $r->id, $searchId);
     }
     aspDebug::stop('--searchContent-posptrocess');
     if (isset($options['switch_on_preprocess']) && is_multisite()) {
         restore_current_blog();
     }
     /* !Images, title, desc */
     //var_dump($pageposts); die();
     $this->results = $pageposts;
     return $pageposts;
 }
Example #16
0
 function wcsCart()
 {
     global $woocommerce;
     $message = '';
     if (isset($_POST['remove_coupn']) && $_POST['remove_coupn'] != '') {
         $coupon_code = $_POST['remove_coupn'];
         // Coupon is no longer valid, based on date.  Remove it.
         if ($woocommerce->cart->has_discount(sanitize_text_field($coupon_code))) {
             if ($woocommerce->cart->remove_coupons(sanitize_text_field($coupon_code))) {
                 $woocommerce->clear_messages();
             }
             $message = $coupon_code . " code remove succesfully";
             // Manually recalculate totals.  If you do not do this, a refresh is required before user will see updated totals when discount is removed.
             $woocommerce->cart->calculate_totals();
         }
     }
     if (isset($_POST['add_coupon']) && $_POST['add_coupon'] != '') {
         $coupon_code = $_POST['add_coupon'];
         //if ( $woocommerce->cart->has_discount( $coupon_code ) ) return;
         $woocommerce->cart->add_discount($coupon_code);
         if ($woocommerce->cart->applied_coupons) {
             $message = $coupon_code . " code successfully applied";
         } else {
             $message = $coupon_code . " code does not exist";
         }
         $woocommerce->cart->calculate_totals();
     }
     if ($woocommerce->cart) {
         $items_in_cart = $woocommerce->cart->cart_contents_count;
         $prod_ids_in_cart = array();
         foreach ($woocommerce->cart->get_cart() as $cart_item_key => $cart_item) {
             $product_id = apply_filters('woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key);
             array_push($prod_ids_in_cart, $product_id);
         }
         $test01 = 0;
         $test02 = 0;
         $test03 = 0;
         $test04 = 0;
         if (in_array("566", $prod_ids_in_cart)) {
             $test01 = 1;
         }
         if (in_array("568", $prod_ids_in_cart)) {
             $test02 = 1;
         }
         if (in_array("570", $prod_ids_in_cart)) {
             $test03 = 1;
         }
         if (in_array("572", $prod_ids_in_cart)) {
             $test04 = 1;
         }
         $how_many_tests_in_cart = $test01 + $test02 + $test03 + $test04;
         if (in_array("574", $prod_ids_in_cart)) {
             foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
                 if ($cart_item['product_id'] == 574) {
                     $woocommerce->cart->set_quantity($cart_item_key, 0);
                 }
             }
             if ($how_many_tests_in_cart == 0) {
             }
             if ($how_many_tests_in_cart == 1) {
                 $woocommerce->cart->add_to_cart('574', '1', '719', '1');
                 $_product = new WC_Product_Variation(719);
                 $price_urgent = $_product->get_price_html();
             }
             if ($how_many_tests_in_cart == 2) {
                 $woocommerce->cart->add_to_cart('574', '1', '720', '2');
                 $_product = new WC_Product_Variation(720);
                 $price_urgent = $_product->get_price_html();
             }
             if ($how_many_tests_in_cart == 3) {
                 $woocommerce->cart->add_to_cart('574', '1', '721', '3');
                 $_product = new WC_Product_Variation(721);
                 $price_urgent = $_product->get_price_html();
             }
             if ($how_many_tests_in_cart == 4) {
                 $woocommerce->cart->add_to_cart('574', '1', '722', '4');
                 $_product = new WC_Product_Variation(722);
                 $price_urgent = $_product->get_price_html();
             }
         }
         // end if there is processing in cart
         /*$product = new WC_Product( $product_id );
         		if($product_id != '574') {
         		$price = $product->price;
         		}*/
         $html = '';
         if ($woocommerce->cart->get_cart_contents_count() > 0) {
             //$html = '<ul class="cart_list product_list_widget">';
             foreach ($woocommerce->cart->get_cart() as $cart_item_key => $cart_item) {
                 $product_id = apply_filters('woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key);
                 $product = new WC_Product($product_id);
                 if ($product_id == 574) {
                     $price = $price_urgent;
                 } else {
                     $price = $product->get_price_html();
                 }
                 $product = new WC_Product($product_id);
                 //$html .='<li class="mini_cart_item" id="product_id_'.$product_id.'"><a href="javascript:void(0);">'.$product->post->post_title.' ( '. $price.')	</a>							</li>';
                 $html .= '<tr id="product_id_' . $product_id . '"><td class="item_name">' . $product->post->post_title . '</td><td class="item_price">' . $price . '</td></tr>';
             }
             $html .= '<tr><td class="item_name"><strong>Subtotal:</strong></td><td class="item_price"><span class="amount">' . $woocommerce->cart->get_cart_subtotal() . '</span></td></tr>';
             foreach ($woocommerce->cart->get_coupons() as $code => $coupon) {
                 $code_cc = "'{$code}'";
                 $label = apply_filters('woocommerce_cart_totals_coupon_label', esc_html(__('Coupon:', 'woocommerce') . ' ' . $coupon->code), $coupon);
                 $html .= '<tr class="cart-discount coupon-' . esc_attr(sanitize_title($code)) . '"><th>' . $label . '</th><td class="item_price">' . wc_custom_cart_totals_coupon_html($coupon) . '</td></tr>';
             }
             $html .= '<tr><td class="item_name"><strong>Total:</strong></td><td class="item_price"><span class="amount">' . $woocommerce->cart->get_cart_total() . '</span></td></tr>';
             //$html .= '</ul>';
         } else {
             $html .= '<tr><td class="item_name">No product added</td></tr>';
         }
         //$html .= '<p class="total"><strong>Subtotal:</strong> <span class="amount">'.$woocommerce->cart->get_cart_total().'</span></p>';
     }
     // edn of if woocommerce cart
     //wc_clear_notices();
     echo $html . '##' . $woocommerce->cart->get_cart_contents_count() . '##' . wc_print_notices();
     die;
 }
Example #17
0
 /**
  * Link all variations via ajax function.
  */
 public static function link_all_variations()
 {
     check_ajax_referer('link-variations', 'security');
     if (!current_user_can('edit_products')) {
         die(-1);
     }
     wc_maybe_define_constant('WC_MAX_LINKED_VARIATIONS', 49);
     wc_set_time_limit(0);
     $post_id = intval($_POST['post_id']);
     if (!$post_id) {
         die;
     }
     $variations = array();
     $product = wc_get_product($post_id);
     if ($product->is_type('variable')) {
         $attributes = wc_list_pluck(array_filter($product->get_attributes(), 'wc_attributes_array_filter_variation'), 'get_slugs');
         if (!empty($attributes)) {
             // Get existing variations so we don't create duplicates.
             $existing_variations = array_map('wc_get_product', $product->get_children());
             $existing_attributes = array();
             foreach ($existing_variations as $existing_variation) {
                 $existing_attributes[] = $existing_variation->get_attributes();
             }
             $added = 0;
             $possible_attributes = wc_array_cartesian($attributes);
             foreach ($possible_attributes as $possible_attribute) {
                 if (in_array($possible_attribute, $existing_attributes)) {
                     continue;
                 }
                 $variation = new WC_Product_Variation();
                 $variation->set_parent_id($post_id);
                 $variation->set_attributes($possible_attribute);
                 do_action('product_variation_linked', $variation->save());
                 if ($added++ > WC_MAX_LINKED_VARIATIONS) {
                     break;
                 }
             }
             echo $added;
         }
     }
     die;
 }
function thb_product_singlepage($atts, $content = null)
{
    extract(shortcode_atts(array('product_id' => ''), $atts));
    global $post, $product, $woocommerce, $woocommerce_loop;
    $args = array('posts_per_page' => 1, 'post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'no_found_rows' => 1, 'p' => $product_id);
    $single_product = new WP_Query($args);
    $preselected_id = '0';
    // check if sku is a variation
    if (isset($atts['sku']) && $single_product->have_posts() && $single_product->post->post_type === 'product_variation') {
        $variation = new WC_Product_Variation($single_product->post->ID);
        $attributes = $variation->get_variation_attributes();
        // set preselected id to be used by JS to provide context
        $preselected_id = $single_product->post->ID;
        // get the parent product object
        $args = array('posts_per_page' => 1, 'post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'no_found_rows' => 1, 'p' => $single_product->post->post_parent);
        $single_product = new WP_Query($args);
        ?>
			<script type="text/javascript">
				jQuery( document ).ready( function( $ ) {
					var $variations_form = $( '[data-product-page-preselected-id="<?php 
        echo esc_attr($preselected_id);
        ?>
"]' ).find( 'form.variations_form' );
					<?php 
        foreach ($attributes as $attr => $value) {
            ?>
						$variations_form.find( 'select[name="<?php 
            echo esc_attr($attr);
            ?>
"]' ).val( '<?php 
            echo $value;
            ?>
' );
					<?php 
        }
        ?>
				});
			</script>
		<?php 
    }
    ob_start();
    while ($single_product->have_posts()) {
        $single_product->the_post();
        wp_enqueue_script('wc-single-product');
        ?>
		<div class="single-product single-product-shortcode full-height-content" data-product-page-preselected-id="<?php 
        echo esc_attr($preselected_id);
        ?>
">	
			<?php 
        wc_get_template_part('content', 'single-product');
        ?>
		</div>
	<?php 
    }
    // end of the loop.
    wp_reset_postdata();
    $out = ob_get_contents();
    if (ob_get_contents()) {
        ob_end_clean();
    }
    return $out;
}
 public function __construct($variation_id, $parent_id = '', $parent_custom_fields = '')
 {
     _deprecated_function('woocommerce_product_variation', '1.4', 'WC_Product_Variation()');
     parent::__construct($variation_id, $parent_id, $parent_custom_fields);
 }
function woocommerce_add_order_item()
{
    global $woocommerce, $wpdb;
    check_ajax_referer('add-order-item', 'security');
    $index = trim(stripslashes($_POST['index']));
    $item_to_add = trim(stripslashes($_POST['item_to_add']));
    $post = '';
    // Find the item
    if (is_numeric($item_to_add)) {
        $post = get_post($item_to_add);
    }
    if (!$post || $post->post_type !== 'product' && $post->post_type !== 'product_variation') {
        $post_id = $wpdb->get_var($wpdb->prepare("\n\t\t\tSELECT post_id\n\t\t\tFROM {$wpdb->posts}\n\t\t\tLEFT JOIN {$wpdb->postmeta} ON ({$wpdb->posts}.ID = {$wpdb->postmeta}.post_id)\n\t\t\tWHERE {$wpdb->postmeta}.meta_key = '_sku'\n\t\t\tAND {$wpdb->posts}.post_status = 'publish'\n\t\t\tAND {$wpdb->posts}.post_type = 'shop_product'\n\t\t\tAND {$wpdb->postmeta}.meta_value = %s\n\t\t\tLIMIT 1\n\t\t"), $item_to_add);
        $post = get_post($post_id);
    }
    if (!$post || $post->post_type !== 'product' && $post->post_type !== 'product_variation') {
        die;
    }
    if ($post->post_type == "product") {
        $_product = new WC_Product($post->ID);
    } else {
        $_product = new WC_Product_Variation($post->ID);
    }
    ?>
	<tr class="item" rel="<?php 
    echo $index;
    ?>
">
		<td class="product-id">
			<img class="tips" tip="<?php 
    echo '<strong>' . __('Product ID:', 'woocommerce') . '</strong> ' . $_product->id;
    echo '<br/><strong>' . __('Variation ID:', 'woocommerce') . '</strong> ';
    if (isset($_product->variation_id) && $_product->variation_id) {
        echo $_product->variation_id;
    } else {
        echo '-';
    }
    echo '<br/><strong>' . __('Product SKU:', 'woocommerce') . '</strong> ';
    if ($_product->sku) {
        echo $_product->sku;
    } else {
        echo '-';
    }
    ?>
" src="<?php 
    echo $woocommerce->plugin_url();
    ?>
/assets/images/tip.png" />
		</td>
		<td class="sku">
			<?php 
    if ($_product->sku) {
        echo $_product->sku;
    } else {
        echo '-';
    }
    ?>
			<input type="hidden" class="item_id" name="item_id[<?php 
    echo $index;
    ?>
]" value="<?php 
    echo esc_attr($_product->id);
    ?>
" />
			<input type="hidden" name="item_name[<?php 
    echo $index;
    ?>
]" value="<?php 
    echo esc_attr($_product->get_title());
    ?>
" />
			<input type="hidden" name="item_variation[<?php 
    echo $index;
    ?>
]" value="<?php 
    if (isset($_product->variation_id)) {
        echo $_product->variation_id;
    }
    ?>
" />
		</td>
		<td class="name">
		
			<div class="row-actions">
				<span class="trash"><a class="remove_row" href="#"><?php 
    _e('Delete item', 'woocommerce');
    ?>
</a> | </span>
				<span class="view"><a href="<?php 
    echo esc_url(admin_url('post.php?post=' . $_product->id . '&action=edit'));
    ?>
"><?php 
    _e('View product', 'woocommerce');
    ?>
</a>
			</div>
			
			<?php 
    echo $_product->get_title();
    ?>
			<?php 
    if (isset($_product->variation_data)) {
        echo '<br/>' . woocommerce_get_formatted_variation($_product->variation_data, true);
    }
    ?>
			<table class="meta" cellspacing="0">
				<tfoot>
					<tr>
						<td colspan="3"><button class="add_meta button"><?php 
    _e('Add&nbsp;meta', 'woocommerce');
    ?>
</button></td>
					</tr>
				</tfoot>
				<tbody class="meta_items"></tbody>
			</table>
		</td>
		
		<?php 
    do_action('woocommerce_admin_order_item_values', $_product);
    ?>
		
		<td class="tax_class" width="1%">
			<select class="tax_class" name="item_tax_class[<?php 
    echo $loop;
    ?>
]">
				<?php 
    $tax_classes = array_filter(array_map('trim', explode("\n", get_option('woocommerce_tax_classes'))));
    $classes_options = array();
    $classes_options[''] = __('Standard', 'woocommerce');
    if ($tax_classes) {
        foreach ($tax_classes as $class) {
            $classes_options[sanitize_title($class)] = $class;
        }
    }
    foreach ($classes_options as $value => $name) {
        echo '<option value="' . $value . '" ' . selected($value, $_product->get_tax_status(), false) . '>' . $name . '</option>';
    }
    ?>
			</select>
		</td>
		
		<td class="quantity" width="1%">
			<input type="text" name="item_quantity[<?php 
    echo $index;
    ?>
]" placeholder="<?php 
    _e('0', 'woocommerce');
    ?>
" value="1" size="2" class="quantity" />
		</td>
		
		<td class="line_subtotal" width="1%">
			<label><?php 
    _e('Cost', 'woocommerce');
    ?>
: <input type="text" name="line_subtotal[<?php 
    echo $index;
    ?>
]" placeholder="<?php 
    _e('0.00', 'woocommerce');
    ?>
" value="<?php 
    echo esc_attr(number_format($_product->get_price_excluding_tax(), 2, '.', ''));
    ?>
" class="line_subtotal" /></label>
			
			<label><?php 
    _e('Tax', 'woocommerce');
    ?>
: <input type="text" name="line_subtotal_tax[<?php 
    echo $index;
    ?>
]" placeholder="<?php 
    _e('0.00', 'woocommerce');
    ?>
" class="line_subtotal_tax" /></label>
		</td>
		
		<td class="line_total" width="1%">
			<label><?php 
    _e('Cost', 'woocommerce');
    ?>
: <input type="text" name="line_total[<?php 
    echo $index;
    ?>
]" placeholder="<?php 
    _e('0.00', 'woocommerce');
    ?>
" value="<?php 
    echo esc_attr(number_format($_product->get_price_excluding_tax(), 2, '.', ''));
    ?>
" class="line_total" /></label>
			
			<label><?php 
    _e('Tax', 'woocommerce');
    ?>
: <input type="text" name="line_tax[<?php 
    echo $index;
    ?>
]" placeholder="<?php 
    _e('0.00', 'woocommerce');
    ?>
" class="line_tax" /></label>
		</td>
		
	</tr>
	<?php 
    // Quit out
    die;
}
 /**
  * Prepare a single variation for create or update.
  *
  * @param WP_REST_Request $request Request object.
  * @return WP_Error|stdClass $data Post object.
  */
 protected function prepare_item_for_database($request)
 {
     if (isset($request['id'])) {
         $variation = wc_get_product(absint($request['id']));
     } else {
         $variation = new WC_Product_Variation();
     }
     $variation->set_parent_id(absint($request['product_id']));
     /**
      * Filter the query_vars used in `get_items` for the constructed query.
      *
      * The dynamic portion of the hook name, $this->post_type, refers to post_type of the post being
      * prepared for insertion.
      *
      * @param WC_Product_Variation $variation An object representing a single item prepared
      *                                        for inserting or updating the database.
      * @param WP_REST_Request      $request   Request object.
      */
     return apply_filters("woocommerce_rest_pre_insert_{$this->post_type}", $variation, $request);
 }
Example #22
0
 function display_price_in_variation_option_name($term)
 {
     global $wpdb, $product;
     $result = $wpdb->get_col("SELECT slug FROM {$wpdb->prefix}terms WHERE name = '{$term}'");
     $term_slug = !empty($result) ? $result[0] : $term;
     $query = "SELECT postmeta.post_id AS product_id\n\t\t\tFROM {$wpdb->prefix}postmeta AS postmeta\n\t\t\tLEFT JOIN {$wpdb->prefix}posts AS products ON ( products.ID = postmeta.post_id )\n\t\t\tWHERE postmeta.meta_key LIKE 'attribute_%'\n\t\t\tAND postmeta.meta_value = '{$term_slug}'\n\t\t\tAND products.post_parent = {$product->id}";
     $variation_id = $wpdb->get_col($query);
     $parent = wp_get_post_parent_id($variation_id[0]);
     if ($parent > 0) {
         $_product = new WC_Product_Variation($variation_id[0]);
         //this is where you can actually customize how the price is displayed
         return wp_strip_all_tags($term . ' (' . woocommerce_price($_product->get_price()) . ')', true);
     }
     return wp_strip_all_tags($term, true);
 }
Example #23
0
 // Get current product
 $product_id = mysql_real_escape_string($_POST['productid']);
 if ($product_id == 'undefined') {
     $product_id = '';
 }
 if (!empty($product_id)) {
     $product = new WC_Product($product_id);
     $productPrice = $product->get_price();
 }
 // Get the variant of the product if set
 $variation_id = mysql_real_escape_string($_POST['variationid']);
 if ($variation_id == 'undefined') {
     $variation_id = '';
 }
 if (!empty($variation_id)) {
     $variation = new WC_Product_Variation($variation_id);
     $productPrice = $variation->get_price();
 }
 // If user has required ammount of credits then continue
 if ($getUserCredit >= $productPrice) {
     get_currentuserinfo();
     // Save the purchase to the database and update credits balance of the user
     $sql = $wpdb->query("UPDATE `" . $wpdb->prefix . "woocredit_users` SET credit = '" . ($getUserCredit - $productPrice) . "' where user_id=" . get_current_user_id());
     $sql = $wpdb->query("INSERT INTO `" . $wpdb->prefix . "woocredit_products` (user_id, product_id, price) VALUES (" . get_current_user_id() . "," . $_POST['productid'] . "," . $productPrice . ")");
     // If the product or variant are downloadable then send an email with a link to the files
     if ($product && $product->is_downloadable() || $variation && $variation->is_downloadable()) {
         $files = [];
         if ($product && $product->is_downloadable()) {
             $files = $product->get_files();
         }
         if ($variation && $variation->is_downloadable()) {
Example #24
0
 /**
  * Post-processes the results
  *
  * @return array of results
  */
 protected function post_process()
 {
     $pageposts = is_array($this->results) ? $this->results : array();
     $options = $this->options;
     $searchId = $this->searchId;
     $searchData = $this->searchData;
     $s = $this->s;
     $_s = $this->_s;
     // Get multibite or regular functions to variables
     extract($this->mb_f);
     // No post processing is needed on non-ajax search
     if (isset($options['non_ajax_search'])) {
         $this->results = $pageposts;
         return $pageposts;
     }
     if (is_multisite()) {
         $home_url = network_home_url();
     } else {
         $home_url = home_url();
     }
     foreach ($pageposts as $k => $v) {
         $r =& $pageposts[$k];
         $r->title = w_isset_def($r->title, null);
         $r->content = w_isset_def($r->content, null);
         $r->image = w_isset_def($r->image, null);
         $r->author = w_isset_def($r->author, null);
         $r->date = w_isset_def($r->date, null);
     }
     /*--------------------- For Image Parser -----------------------*/
     // Do not select the content field, if it is not used at all
     $get_content = $searchData['showdescription'] == 1 || $searchData['resultstype'] == "isotopic" && $searchData['i_ifnoimage'] == 'description' || $searchData['resultstype'] == "polaroid" && ($searchData['pifnoimage'] == 'descinstead' || $searchData['pshowdesc'] == 1) ? false : true;
     // Do not select excerpt if its not used at all
     $get_excerpt = w_isset_def($searchData['titlefield'], 0) == 1 || w_isset_def($searchData['descriptionfield'], 0) == 1 ? false : true;
     /*---------------------------------------------------------------*/
     aspDebug::start('--searchContent-posptrocess');
     /* Images, title, desc */
     foreach ($pageposts as $k => $v) {
         // Let's simplify things
         $r =& $pageposts[$k];
         if (isset($options['switch_on_preprocess']) && is_multisite()) {
             switch_to_blog($r->blogid);
         }
         $r = apply_filters('asp_result_before_prostproc', $r, $searchId);
         $r->title = apply_filters('asp_result_title_before_prostproc', $r->title, $r->id, $searchId);
         $r->content = apply_filters('asp_result_content_before_prostproc', $r->content, $r->id, $searchId);
         $r->image = apply_filters('asp_result_image_before_prostproc', $r->image, $r->id, $searchId);
         $r->author = apply_filters('asp_result_author_before_prostproc', $r->author, $r->id, $searchId);
         $r->date = apply_filters('asp_result_date_before_prostproc', $r->date, $r->id, $searchId);
         $r->link = get_permalink($v->id);
         // ---- URL FIX for WooCommerce product variations
         if ($r->post_type == 'product_variation' && class_exists('WC_Product_Variation')) {
             $wc_prod_var_o = new WC_Product_Variation($r->id);
             $r->link = $wc_prod_var_o->get_permalink();
         }
         $caching_options = w_false_def(get_option('asp_caching'), get_option('asp_caching_def'));
         $use_bfi = w_isset_def($caching_options['use_bfi_thumb'], 1);
         $image_settings = $searchData['image_options'];
         if ($image_settings['show_images'] != 0) {
             if ($image_settings['image_cropping'] == 0) {
                 // Use the BFI parser, but no caching
                 $im = $this->getBFIimage($r, $get_content, $get_excerpt);
                 if ($im != '') {
                     $r->image = $im;
                 }
             } else {
                 if ($use_bfi == 0) {
                     $im = $this->getCachedImage($r, $get_content, $get_excerpt);
                     if ($im != '') {
                         $r->image = $im;
                     }
                 } else {
                     $im = $this->getBFIimage($r, $get_content, $get_excerpt);
                     if ($im != '' && strpos($im, "mshots/v1") === false) {
                         if (w_isset_def($image_settings['image_transparency'], 1) == 1) {
                             $bfi_params = array('width' => $image_settings['image_width'], 'height' => $image_settings['image_height'], 'crop' => true);
                         } else {
                             $bfi_params = array('width' => $image_settings['image_width'], 'height' => $image_settings['image_height'], 'crop' => true, 'color' => wpdreams_rgb2hex($image_settings['image_bg_color']));
                         }
                         $r->image = bfi_thumb($im, $bfi_params);
                     } else {
                         $r->image = $im;
                     }
                 }
             }
         }
         // If no image and defined, remove the result here, to perevent JS confusions
         if (empty($r->image) && $searchData['resultstype'] == "isotopic" && $searchData['i_ifnoimage'] == 'removeres') {
             unset($pageposts[$k]);
             continue;
         }
         if (!isset($searchData['titlefield']) || $searchData['titlefield'] == "0" || is_array($searchData['titlefield'])) {
             $r->title = get_the_title($r->id);
         } else {
             if ($searchData['titlefield'] == "1") {
                 if ($fn_strlen($r->excerpt) >= 200) {
                     $r->title = wd_substr_at_word($r->excerpt, 200);
                 } else {
                     $r->title = $r->excerpt;
                 }
             } else {
                 $mykey_values = get_post_custom_values($searchData['titlefield'], $r->id);
                 if (isset($mykey_values[0])) {
                     $r->title = $mykey_values[0];
                 } else {
                     $r->title = get_the_title($r->id);
                 }
             }
         }
         $r->title = $this->adv_title($r->title, $r->id);
         if (!isset($searchData['striptagsexclude'])) {
             $searchData['striptagsexclude'] = "<a><span>";
         }
         //remove the search shortcode properly
         add_shortcode('wpdreams_ajaxsearchpro', array($this, 'return_empty_string'));
         if (!isset($searchData['descriptionfield']) || $searchData['descriptionfield'] == "0" || is_array($searchData['descriptionfield'])) {
             if (function_exists('qtrans_getLanguage')) {
                 $r->content = apply_filters('the_content', $r->content, $searchId);
             }
             $_content = strip_tags($r->content, $searchData['striptagsexclude']);
         } else {
             if ($searchData['descriptionfield'] == "1") {
                 $_content = strip_tags($r->excerpt, $searchData['striptagsexclude']);
             } else {
                 if ($searchData['descriptionfield'] == "2") {
                     $_content = strip_tags(get_the_title($r->id), $searchData['striptagsexclude']);
                 } else {
                     $mykey_values = get_post_custom_values($searchData['descriptionfield'], $r->id);
                     if (isset($mykey_values[0])) {
                         $_content = strip_tags($mykey_values[0], $searchData['striptagsexclude']);
                     } else {
                         $_content = strip_tags($r->content, $searchData['striptagsexclude']);
                     }
                 }
             }
         }
         if ($_content == "") {
             $_content = $r->content;
         }
         if (isset($searchData['runshortcode']) && $searchData['runshortcode'] == 1) {
             if ($_content != "") {
                 $_content = apply_filters('the_content', $_content, $searchId);
             }
         }
         if (isset($searchData['stripshortcode']) && $searchData['stripshortcode'] == 1) {
             if ($_content != "") {
                 $_content = strip_shortcodes($_content);
             }
         }
         // Remove styles and scripts
         $_content = preg_replace(array('#<script(.*?)>(.*?)</script>#is', '#<style(.*?)>(.*?)</style>#is'), '', $_content);
         $_content = strip_tags($_content, $searchData['striptagsexclude']);
         // Get the words from around the search phrase, or just the description
         if (w_isset_def($searchData['description_context'], 1) == 1 && count($_s) > 0) {
             $_content = $this->context_find($_content, $_s[0], floor($searchData['descriptionlength'] / 6), $searchData['descriptionlength']);
         } else {
             if ($_content != '' && $fn_strlen($_content) > $searchData['descriptionlength']) {
                 $_content = wd_substr_at_word($_content, $searchData['descriptionlength']) . "...";
             }
         }
         $_content = wd_closetags($_content);
         $r->content = $this->adv_desc($_content, $r->id);
         // -------------------------- Woocommerce Fixes -----------------------------
         // A trick to fix the url
         if ($r->post_type == 'product_variation' && class_exists('WC_Product_Variation')) {
             $r->title = preg_replace("/(Variation) \\#(\\d+) (of)/si", '', $r->title);
             $wc_prod_var_o = new WC_Product_Variation($r->id);
             $r->link = $wc_prod_var_o->get_permalink();
         }
         // --------------------------------------------------------------------------
         // --------------------------------- DATE -----------------------------------
         if ($searchData["showdate"] == 1) {
             $post_time = strtotime($r->date);
             if (w_isset_def($searchData['custom_date'], 0)) {
                 $date_format = w_isset_def($searchData['custom_date_format'], "Y-m-d H:i:s");
             } else {
                 $date_format = get_option('date_format', "Y-m-d") . " " . get_option('time_format', "H:i:s");
             }
             $r->date = @date($date_format, $post_time);
         }
         // --------------------------------------------------------------------------
         $r = apply_filters('asp_result_after_prostproc', $r, $searchId);
         $r->title = apply_filters('asp_result_title_after_prostproc', $r->title, $r->id, $searchId);
         $r->content = apply_filters('asp_result_content_after_prostproc', $r->content, $r->id, $searchId);
         $r->image = apply_filters('asp_result_image_after_prostproc', $r->image, $r->id, $searchId);
         $r->author = apply_filters('asp_result_author_after_prostproc', $r->author, $r->id, $searchId);
         $r->date = apply_filters('asp_result_date_after_prostproc', $r->date, $r->id, $searchId);
     }
     aspDebug::stop('--searchContent-posptrocess');
     if (isset($options['switch_on_preprocess']) && is_multisite()) {
         restore_current_blog();
     }
     /* !Images, title, desc */
     //var_dump($pageposts); die();
     $this->results = $pageposts;
     return $pageposts;
 }
    /**
     * Show a single product page.
     *
     * @param array $atts
     * @return string
     */
    public static function product_page($atts)
    {
        if (empty($atts)) {
            return '';
        }
        if (!isset($atts['id']) && !isset($atts['sku'])) {
            return '';
        }
        $args = array('posts_per_page' => 1, 'post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'no_found_rows' => 1);
        if (isset($atts['sku'])) {
            $args['meta_query'][] = array('key' => '_sku', 'value' => sanitize_text_field($atts['sku']), 'compare' => '=');
            $args['post_type'] = array('product', 'product_variation');
        }
        if (isset($atts['id'])) {
            $args['p'] = absint($atts['id']);
        }
        $single_product = new WP_Query($args);
        $preselected_id = '0';
        // check if sku is a variation
        if (isset($atts['sku']) && $single_product->have_posts() && $single_product->post->post_type === 'product_variation') {
            $variation = new WC_Product_Variation($single_product->post->ID);
            $attributes = $variation->get_variation_attributes();
            // set preselected id to be used by JS to provide context
            $preselected_id = $single_product->post->ID;
            // get the parent product object
            $args = array('posts_per_page' => 1, 'post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'no_found_rows' => 1, 'p' => $single_product->post->post_parent);
            $single_product = new WP_Query($args);
            ?>
			<script type="text/javascript">
				jQuery( document ).ready( function( $ ) {
					var $variations_form = $( '[data-product-page-preselected-id="<?php 
            echo esc_attr($preselected_id);
            ?>
"]' ).find( 'form.variations_form' );

					<?php 
            foreach ($attributes as $attr => $value) {
                ?>
						$variations_form.find( 'select[name="<?php 
                echo esc_attr($attr);
                ?>
"]' ).val( '<?php 
                echo $value;
                ?>
' );
					<?php 
            }
            ?>
				});
			</script>
		<?php 
        }
        ob_start();
        while ($single_product->have_posts()) {
            $single_product->the_post();
            wp_enqueue_script('wc-single-product');
            ?>

			<div class="single-product" data-product-page-preselected-id="<?php 
            echo esc_attr($preselected_id);
            ?>
">

				<?php 
            wc_get_template_part('content', 'single-product');
            ?>

			</div>

		<?php 
        }
        // end of the loop.
        wp_reset_postdata();
        return '<div class="woocommerce">' . ob_get_clean() . '</div>';
    }
 function get_per_night_price($post_id, $days, $booking_settings, $variation_id)
 {
     global $wpdb;
     //echo $variation_id;exit;
     $product_id = $post_id;
     if ($variation_id != '') {
         //$booking_settings = get_post_meta($product_id, 'woocommerce_booking_settings', true);
         if (isset($booking_settings['booking_block_price_enable'])) {
             $_product = new WC_Product_Variation($variation_id);
             $var_attributes = $_product->get_variation_attributes();
             $attribute_names = str_replace("-", " ", $var_attributes);
             /* Querying the database */
             $j = 1;
             $k = 0;
             $attribute_sub_query = '';
             foreach ($attribute_names as $key => $value) {
                 //echo "here".$value;
                 $attribute_sub_query .= " c" . $k . ".attribute_id = '{$j}' AND c" . $k . ".meta_value = '{$value}' AND";
                 $j++;
                 $k++;
             }
             $query = "SELECT c0.block_id FROM `" . $wpdb->prefix . "booking_block_price_attribute_meta` AS c0\n\t\t\t\t\t\t\t\t\tJOIN `" . $wpdb->prefix . "booking_block_price_attribute_meta` AS c1 ON c1.block_id=c0.block_id\n\t\t\t\t\t\t\t\t\tWHERE " . $attribute_sub_query . " c0.post_id = '" . $product_id . "'";
             //print_r("here".$query);
             $results = $wpdb->get_results($query);
             //$number_of_days =  strtotime($checkout_date) - strtotime($checkin_date);
             $number = $days;
             $e = 0;
             foreach ($results as $k => $v) {
                 $query = "SELECT price_per_day, fixed_price FROM `" . $wpdb->prefix . "booking_block_price_meta`\n\t\t\t\t\t\t\tWHERE id = '" . $v->block_id . "' AND post_id = '" . $product_id . "' AND minimum_number_of_days <='" . $number . "' AND maximum_number_of_days >= '" . $number . "'";
                 //echo $query;
                 $results_price[$e] = $wpdb->get_results($query);
                 $e++;
             }
             $price = 0;
             foreach ($results_price as $k => $v) {
                 if (!empty($results_price[$k])) {
                     if (isset($booking_settings['booking_partial_payment_radio']) && $booking_settings['booking_partial_payment_radio'] == 'value') {
                         $price = $booking_settings['booking_partial_payment_value_deposit'];
                     } elseif (isset($booking_settings['booking_partial_payment_radio']) && $booking_settings['booking_partial_payment_radio'] == 'percent') {
                         $sale_price = get_post_meta($variation_id, '_sale_price', true);
                         if (isset($booking_settings['booking_block_price_enable']) && $booking_settings['booking_block_price_enable'] == "yes") {
                             if ($v[0]->fixed_price != 0) {
                                 $oprice = $v[0]->fixed_price;
                                 $pprice = "-fixed";
                             } else {
                                 $oprice = $v[0]->price_per_day;
                                 $pprice = "-per_day";
                             }
                             $price = $booking_settings['booking_partial_payment_value_deposit'] * $oprice / 100;
                             $price .= $pprice;
                         } elseif ($sale_price == '') {
                             $regular_price = get_post_meta($variation_id, '_regular_price', true);
                             $price = $booking_settings['booking_partial_payment_value_deposit'] * $regular_price / 100;
                         } else {
                             $price = $booking_settings['booking_partial_payment_value_deposit'] * $sale_price / 100;
                         }
                     } else {
                         if (isset($booking_settings['booking_block_price_enable']) && $booking_settings['booking_block_price_enable'] == "yes") {
                             //echo $v[0]->fixed_price;
                             if ($v[0]->fixed_price != 0) {
                                 $price = $v[0]->fixed_price;
                                 $price .= "-fixed";
                             } else {
                                 $price = $v[0]->price_per_day;
                                 $price .= "-per_day";
                             }
                         }
                     }
                 } else {
                     unset($results_price[$k]);
                 }
             }
         }
     } else {
         $booking_settings = get_post_meta($product_id, 'woocommerce_booking_settings', true);
         if (isset($booking_settings['booking_block_price_enable'])) {
             //$number_of_days =  strtotime($checkout_date) - strtotime($checkin_date);
             $number = $days;
             $query = "SELECT price_per_day, fixed_price FROM `" . $wpdb->prefix . "booking_block_price_meta`\n\t\t\t\t\t\t\tWHERE post_id = '" . $product_id . "' AND minimum_number_of_days <='" . $number . "' AND maximum_number_of_days >= '" . $number . "'";
             //echo $query;
             $results_price = $wpdb->get_results($query);
             if (count($results_price) == 0) {
                 $sale_price = get_post_meta($product_id, '_sale_price', true);
                 if ($sale_price == '') {
                     $regular_price = get_post_meta($product_id, '_regular_price', true);
                     $price = $regular_price;
                     $price .= "-";
                 } else {
                     $price = $sale_price;
                     $price .= "-";
                 }
             } else {
                 foreach ($results_price as $k => $v) {
                     //print_r($v);
                     if (!empty($results_price[$k])) {
                         if (isset($booking_settings['booking_partial_payment_radio']) && $booking_settings['booking_partial_payment_radio'] == 'value') {
                             $price = $booking_settings['booking_partial_payment_value_deposit'];
                         } elseif (isset($booking_settings['booking_partial_payment_radio']) && $booking_settings['booking_partial_payment_radio'] == 'percent') {
                             $sale_price = get_post_meta($product_id, '_sale_price', true);
                             if (isset($booking_settings['booking_block_price_enable']) && $booking_settings['booking_block_price_enable'] == "yes") {
                                 if ($v->fixed_price != 0) {
                                     $oprice = $v->fixed_price;
                                     $pprice = "-fixed";
                                 } else {
                                     $oprice = $v->price_per_day;
                                     $pprice = "-per_day";
                                 }
                                 $price = $booking_settings['booking_partial_payment_value_deposit'] * $oprice / 100;
                                 $price .= $pprice;
                             } elseif ($sale_price == '') {
                                 $regular_price = get_post_meta($product_id, '_regular_price', true);
                                 $price = $booking_settings['booking_partial_payment_value_deposit'] * $regular_price / 100;
                             } else {
                                 $price = $booking_settings['booking_partial_payment_value_deposit'] * $sale_price / 100;
                             }
                         } else {
                             if (isset($booking_settings['booking_block_price_enable']) && $booking_settings['booking_block_price_enable'] == "yes") {
                                 //echo $v[0]->fixed_price;
                                 if ($v->fixed_price != 0) {
                                     $price = $v->fixed_price;
                                     $price .= "-fixed";
                                 } else {
                                     $price = $v->price_per_day;
                                     $price .= "-per_day";
                                 }
                             }
                         }
                     } else {
                         unset($results_price[$k]);
                     }
                 }
             }
         }
     }
     //echo "<pre>";print_r($price);echo "</pre>";exit;
     return $price;
 }
Example #27
0
function wpp_export($export)
{
    error_reporting(0);
    ob_clean();
    $export = addslashes(substr(strip_tags($_GET['wpp_export']), 0, 5));
    @set_time_limit(864000);
    if (ini_get('max_execution_time') != 864000) {
        @ini_set('max_execution_time', 864000);
    }
    $post_id = url_to_postid($_SERVER['REQUEST_URI']);
    $post = get_post($post_id);
    if ($post->post_status != 'publish') {
        return false;
    }
    if (post_password_required($post->ID)) {
        return false;
    }
    $product = get_product($post->ID);
    $out = '';
    if (function_exists('has_post_thumbnail') && has_post_thumbnail($post->ID)) {
        $thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'shop_single');
        $wpp_featured_image = $thumbnail[0] ? $thumbnail[0] : $thumbnail[0];
    } else {
        $wpp_featured_image = '';
    }
    if ($thumbnail[1]) {
        $wpp_featured_image = '<img width="' . $thumbnail[1] . '" height="' . $thumbnail[2] . '" src="' . $thumbnail[0] . '"/>';
    }
    $wpp_price_html = strip_tags($product->get_price_html());
    $wpp_title = $post->post_title;
    $wpp_sku = $product->get_sku();
    $wpp_permalink = $product->get_permalink();
    $wpp_stock = $product->get_stock_quantity();
    $wpp_rating = strip_tags($product->get_rating_html());
    $wpp_categories = $product->get_categories(', ');
    $wpp_tags = $product->get_tags(', ');
    $wpp_summary = wpp_text_filter($post->post_excerpt);
    $wpp_description = wpp_text_filter($post->post_content);
    $attribute_html = "\r\n<ul>";
    if ($product->enable_dimensions_display()) {
        $attribute_html .= $product->get_dimensions() ? '<li>' . get_option('wpp_ph_dimensions') . ': ' . $product->get_dimensions() . "\r\n</li>" : '';
    }
    $attribute_html .= $product->get_weight() ? '<li>' . get_option('wpp_ph_weight') . ': ' . $product->get_weight() . ' ' . get_option('woocommerce_weight_unit') . "\r\n</li>" : '';
    if ($product->has_attributes()) {
        $wpp_attributes = $product->get_attributes();
        if (!empty($wpp_attributes)) {
            foreach ($wpp_attributes as $attribute) {
                if (!$attribute['is_visible']) {
                    continue;
                }
                if ($attribute['is_taxonomy']) {
                    $product_terms = wp_get_post_terms($post->ID, $attribute['name']);
                    $p_terms = array();
                    //$attribute_name = ucwords(str_replace('attribute_','',str_replace('pa_','',$attribute['name'])));
                    $attribute_name = wc_attribute_label($attribute['name']);
                    foreach ($product_terms as $p_term) {
                        $p_terms[] = $p_term->name;
                    }
                    $attribute_html .= '<li>' . $attribute_name . ': ' . implode(', ', $p_terms) . "\r\n</li>";
                } else {
                    $attribute_html .= '<li>' . $attribute['name'] . ': ' . $attribute['value'] . "\r\n</li>";
                }
            }
        }
    }
    $attribute_html .= '</ul>';
    $attribute_html = str_replace(array(' |', '|'), ',', $attribute_html);
    $wpp_has_variants = false;
    $wpp_variants = "\r\n<ul>";
    $args = array('post_type' => 'product_variation', 'post_status' => 'publish', 'numberposts' => -1, 'orderby' => 'menu_order', 'order' => 'asc', 'post_parent' => $post->ID);
    $variations = get_posts($args);
    if (!empty($variations)) {
        $wpp_has_variants = true;
        foreach ($variations as $variation) {
            $vars = new WC_Product_Variation($variation->ID);
            $wpp_variants .= '<li>' . str_replace($vars->get_sku(), '', html_entity_decode(strip_tags(wpp_text_filter(str_replace('&ndash;', ' - ', $vars->get_formatted_name()))), ENT_QUOTES, "UTF-8")) . "\r\n</li>";
            unset($vars);
        }
        $wpp_variants .= '</ul>';
        $wpp_variants = str_replace(array('<li>  -  ', ',   -  '), array('<li>', '  -  '), $wpp_variants);
    }
    //Post Specific Custom Tabs
    if ($product_meta = get_post_meta($post->ID)) {
        foreach ($product_meta as $meta_key => $meta_value) {
            if (strpos($meta_key, '_wpt_field_') !== FALSE) {
                $custom_tab_slug = str_replace('_wpt_field_', '', $meta_key);
                $custom_tab = get_posts(array('name' => $custom_tab_slug, 'posts_per_page' => 1, 'post_type' => 'woo_product_tab', 'post_status' => 'publish'));
                if (trim($meta_value[0])) {
                    $custom_tab_title_html[] = $custom_tab[0]->post_title;
                    $custom_tab_content_html[] = wpp_text_filter($meta_value[0]);
                }
            }
            continue;
        }
    }
    //General Custom Tabs
    $general_custom_tab = get_posts(array('posts_per_page' => -1, 'post_type' => 'woo_product_tab', 'post_status' => 'publish'));
    foreach ($general_custom_tab as $tab) {
        if (trim($tab->post_content)) {
            $cfkey = '_wpt_field_' . $tab->post_name;
            if (get_post_meta($post->ID, $cfkey, true)) {
                //it's already taken
            } else {
                $custom_tab_title_html[] = $tab->post_title;
                $custom_tab_content_html[] = wpp_text_filter($tab->post_content);
            }
        }
    }
    $wpp_gallery = $product->get_gallery_attachment_ids();
    foreach ($wpp_gallery as $wpp_img) {
        $wpp_gallery_images .= '&nbsp;' . wp_get_attachment_image($wpp_img, 'shop_single') . '&nbsp;';
    }
    if ($export == 'doc') {
        $doc_title = stripslashes($post->post_title);
        $wpp_description = stripslashes($wpp_description);
        $wpp_price = get_option('wpp_ph_price') . ': ' . html_entity_decode(str_replace('&ndash;', ' - ', $product->get_price_html()), ENT_QUOTES, "UTF-8");
        if (get_option('wpp_save_doc_img_max_width')) {
            $wpp_max_image_width = get_option('wpp_save_doc_img_max_width');
        } else {
            $wpp_max_image_width = 500;
        }
        if (preg_match_all('|width=[\'\\"]*(\\d+)[\'\\"]*[^\\>\\<]+height=[\'\\"]*(\\d+)[\'\\"]*|i', $wpp_description, $doc_img_sizes, PREG_SET_ORDER)) {
            foreach ($doc_img_sizes as $doc_img) {
                $doc_img_w = $doc_img[1];
                $doc_img_h = $doc_img[2];
                if ((int) $wpp_max_image_width < (int) $doc_img_w) {
                    $doc_img_h = $doc_img_h * ($wpp_max_image_width / $doc_img_w);
                    $doc_img_w = $wpp_max_image_width;
                }
                $wpp_description = preg_replace('|width=[\'\\"]*' . $doc_img[1] . '[\'\\"]*[^\\>\\<]+height=[\'\\"]*' . $doc_img[2] . '[\'\\"]*|i', 'width="' . $doc_img_w . '" height="' . $doc_img_h . '"', $wpp_description);
            }
        }
        $wpp_description = preg_replace('|\\[caption[^\\]]+\\]([^\\]]*)\\[\\/caption\\]|is', '$1', $wpp_description);
        $wpp_description = preg_replace(array('|<embed[^>]+>[^>]*<\\/embed>|i', '|<object[^>]+>|i', '|<\\/object>|i', '|<param[^>]+>|i', '|<script[^>]+>[^>]*<\\/script>|i'), '', $wpp_description);
        preg_match_all('|<img[^>]+(class[\\s\\n\\t\\r]*=[\\s\\n\\t\\r]*[\'\\"]+[^\'\\">]+[\'\\"]+)[^>]*>|i', $wpp_description, $body_array, PREG_SET_ORDER);
        if (!empty($body_array)) {
            for ($i = 0; $i < count($body_array); $i++) {
                $replace = preg_replace('|(.+)class[\\s\\n\\t\\r]*=[\\s\\n\\t\\r]*[\'\\"]+align([^\\s\\t\\r\\n\'\\">]+)[^\'\\">]*[\'\\"]+(.+)|i', '</span><![if !vml]> $1 align = \'$2\' $3 <![endif]><span style=\'font-size:10.5pt;color:#666666;\'>', $body_array[$i][0]);
                $wpp_description = str_replace($body_array[$i][0], $replace, $wpp_description);
            }
        }
        $wpp_doc_urls = wpp_img_url($wpp_description);
        if (!empty($wpp_doc_urls)) {
            foreach ($wpp_doc_urls as $k => $v) {
                $wpp_description = str_replace($k, $v, $wpp_description);
            }
        }
        $doc_post_date = $post->post_date;
        $doc_post_date_gmt = $post->post_date_gmt;
        $doc_modified_date = $post->post_modified;
        $doc_modified_date_gmt = $post->post_modified_gmt;
        if (!get_option('wpp_doc_t_image')) {
            $wpp_description = preg_replace('|<img[^><]+>|i', '', $wpp_description);
        }
        $doc_t_title = $doc_title && get_option('wpp_doc_t_title') ? '<h2 style="color:#000000;text-align:' . get_option('wpp_save_text_align') . '">' . $doc_title . '</h2><br>' : '';
        $doc_t_date = get_option('wpp_doc_t_date') ? get_option('wpp_ph_prod_date') . ': ' . $doc_post_date . '<br>' : '';
        $doc_t_md_date = get_option('wpp_doc_t_md') ? get_option('wpp_ph_prod_mod_date') . ': ' . $doc_modified_date : '';
        require WPP_FOLDER . 'template/header/doc_head.php';
        if (get_option('wpp_save_doc_template')) {
            require WPP_FOLDER . 'template/save_as_word_document.php';
        } else {
            require WPP_FOLDER . 'template/save_as_word_document_oo.php';
        }
        $doc = trim($doc);
        $length = strlen($doc);
        $file = trim(str_replace(' ', '-', trim($doc_title)), '-');
        $file = $file . '.doc';
        header('Content-Type: application/msword; charset=utf-8');
        if (headers_sent()) {
            echo 'Some data has already been output, can\'t send MS Doc file';
        }
        header('Content-Length: ' . $length);
        header('Content-Disposition: attachment; filename=' . $file);
        header('Cache-Control: private, max-age=0, must-revalidate');
        header('Pragma: public');
        ini_set('zlib.output_compression', '0');
        echo $doc;
    } elseif ($export == 'pdf') {
        global $wpp_html_link;
        $html_title = stripslashes($post->post_title);
        $wpp_html_link = stripslashes($post->guid);
        //Price Style
        $wpp_price = $product->get_price_html();
        $wpp_price = strpos($wpp_price, '&#x4') === FALSE ? $wpp_price : str_replace('&#x440;&#x443;&#x431;', 'руб', strip_tags($wpp_price));
        if ($product->is_on_sale()) {
            $wpp_price = str_replace(array('<del>', '</del>'), array('^[font][' . get_option('wpp_ph_real_price') . ': ', '][200,200,200][14]^<br>
 ^[font][' . get_option('wpp_ph_curr_sale_price') . ':'), str_replace('&ndash;', ' - ', $wpp_price)) . '][15, 117, 84][14]^';
        } else {
            $wpp_price = '^[font][' . get_option('wpp_ph_price') . ': ' . strip_tags($wpp_price) . '][15, 117, 84][14]^';
        }
        //Limiting image sizes
        preg_match_all('|<img[^>]+(class[\\s\\n\\t\\r]*=[\\s\\n\\t\\r]*[\'\\"]+[^\'\\">]+[\'\\"]+)[^>]*>|i', $html_body, $body_array, PREG_SET_ORDER);
        if (!empty($body_array)) {
            for ($i = 0; $i < count($body_array); $i++) {
                $replace = preg_replace('|(.+)class[\\s\\n\\t\\r]*=[\\s\\n\\t\\r]*[\'\\"]+align([^\\s\\t\\r\\n\'\\">]+)[^\'\\">]*[\'\\"]+(.+)|i', '$1 align = "$2" style="padding:5px" $3', $body_array[$i][0]);
                $html_body = str_replace($body_array[$i][0], $replace, $html_body);
            }
        }
        $html_body = preg_replace('|<noscript>.+?</noscript>|is', '', $html_body);
        $html_body = preg_replace("|\r|", "<br>", $html_body);
        $wpp_pdf_urls = wpp_img_url($html_body);
        if (!empty($wpp_pdf_urls)) {
            foreach ($wpp_pdf_urls as $k => $v) {
                if (strpos($k, '../') === FALSE) {
                    $html_body = str_replace($k, $v, $html_body);
                } else {
                    continue;
                }
            }
        }
        require WPP_FOLDER . 'template/header/pdf_head.php';
        require WPP_FOLDER . 'template/save_as_pdf.php';
        require WPP_FOLDER . 'pdf.php';
    } elseif ($export == 'print') {
        $print_title = stripslashes($post->post_title);
        $wpp_description = stripslashes($wpp_description);
        $wpp_price = get_option('wpp_ph_price') . ': ' . html_entity_decode(str_replace('&ndash;', ' - ', $product->get_price_html()), ENT_QUOTES, "UTF-8");
        if (get_option('wpp_save_print_img_max_width')) {
            $wpp_max_image_width = get_option('wpp_save_print_img_max_width');
        } else {
            $wpp_max_image_width = 500;
        }
        if (preg_match_all('|width=[\'\\"]*(\\d+)[\'\\"]*[^\\>\\<]+height=[\'\\"]*(\\d+)[\'\\"]*|i', $wpp_description, $print_img_sizes, PREG_SET_ORDER)) {
            foreach ($print_img_sizes as $print_img) {
                $print_img_w = $print_img[1];
                $print_img_h = $print_img[2];
                if ((int) $wpp_max_image_width < (int) $print_img_w) {
                    $print_img_h = $print_img_h * ($wpp_max_image_width / $print_img_w);
                    $print_img_w = $wpp_max_image_width;
                }
                $wpp_description = preg_replace('|width=[\'\\"]*' . $print_img[1] . '[\'\\"]*[^\\>\\<]+height=[\'\\"]*' . $print_img[2] . '[\'\\"]*|i', 'width="' . $print_img_w . '" height="' . $print_img_h . '"', $wpp_description);
            }
        }
        $wpp_description = preg_replace('|\\[caption[^\\]]+\\]([^\\]]*)\\[\\/caption\\]|is', '$1', $wpp_description);
        $wpp_description = preg_replace(array('|<embed[^>]+>[^>]*<\\/embed>|i', '|<object[^>]+>|i', '|<\\/object>|i', '|<param[^>]+>|i', '|<script[^>]+>[^>]*<\\/script>|i'), '', $wpp_description);
        if (get_option('wpp_pt_links')) {
            preg_match_all("|<a href[\\s\n\t\r]*=[\\s\n\t\r]*[\\'\"]+([^>\\'\"]+)[\\'\"]+[^><]*>([^><]+)</a>|i", $wpp_description, $links_array, PREG_SET_ORDER);
            if (!empty($links_array)) {
                for ($i = 0; $i < count($links_array); $i++) {
                    $print_links .= '<li>' . wpp_phrase_spliter($links_array[$i][1], 50, ' ', false) . '</li>';
                    $wpp_description = str_replace($links_array[$i][0], '<u>' . $links_array[$i][0] . '</u> <sup>' . ($i + 1) . '</sup>', $wpp_description);
                }
            }
        }
        preg_match_all('|<img[^>]+(class[\\s\\n\\t\\r]*=[\\s\\n\\t\\r]*[\'\\"]+[^\'\\">]+[\'\\"]+)[^>]*>|i', $wpp_description, $body_array, PREG_SET_ORDER);
        if (!empty($body_array)) {
            for ($i = 0; $i < count($body_array); $i++) {
                $replace = preg_replace('|(.+)class[\\s\\n\\t\\r]*=[\\s\\n\\t\\r]*[\'\\"]+align([^\\s\\t\\r\\n\'\\">]+)[^\'\\">]*[\'\\"]+(.+)|i', '$1 align = "$2" style="padding:5px" $3', $body_array[$i][0]);
                $wpp_description = str_replace($body_array[$i][0], $replace, $wpp_description);
            }
        }
        $print_excerpt = stripslashes($post->post_excerpt);
        $print_post_date = $post->post_date;
        $print_post_date_gmt = $post->post_date_gmt;
        $print_modified_date = $post->post_modified;
        $print_modified_date_gmt = $post->post_modified_gmt;
        if (!get_option('wpp_pt_image')) {
            $wpp_description = preg_replace('|<img[^><]+>|i', '', $wpp_description);
        }
        $pt_header = get_option('wpp_pt_head_site') ? '<a href="' . get_option('siteurl') . '" target="_blank" class="wpp_header_2">' . get_option('blogname') . '</a> <br/>' : '';
        $pt_header .= get_option('wpp_pt_head_url') ? '<a href="' . get_permalink($post->ID) . '" target="_blank" class="wpp_header_3">' . get_permalink($post->ID) . '</a> <br />' : '';
        $pt_header .= get_option('wpp_pt_head_date') ? get_option('wpp_ph_exp_date') . ': ' . date("D M j G:i:s Y / O ") . ' GMT<br />' : '';
        $pt_header .= '<hr style="border:none; border-top: #DDDDDD dotted 1px;" />';
        $pt_title = $print_title && get_option('wpp_pt_title') ? '<h2 style="text-align:' . get_option('wpp_save_text_align') . '">' . $print_title . '</h2><br>' : '';
        $pt_links = $print_links && get_option('wpp_pt_links') ? '<strong>' . get_option('wpp_ph_links') . ':</strong> <ol type="1">' . $print_links . '</ol>' : '';
        $pt_date = get_option('wpp_pt_date') ? get_option('wpp_ph_prod_date') . ': ' . $print_post_date . '<br>' : '';
        $pt_md_date = get_option('wpp_pt_md') ? get_option('wpp_ph_prod_mod_date') . ': ' . $print_modified_date . '<br>' : '';
        $pt_footer = get_option('wpp_pt_header') ? '<br>' . get_option('wpp_ph_exp_date') . ': ' . date("D M j G:i:s Y / O ") . ' GMT
		<br> ' . get_option('wpp_ph_page_exported_from') . ' ' . get_option('blogname') . ' 
		[ <a href="' . str_replace(array('&wpp_export=print', '?wpp_export=print'), '', $_SERVER['REQUEST_URI']) . '" target="_blank">' . get_option('siteurl') . '</a> ]<hr/>
		Product Print by <a href="http://www.gvectors.com/?wpp" target="_blank">WooCommerce PDF & Print</a> plugin.' : '';
        require WPP_FOLDER . 'template/header/print_head.php';
        require WPP_FOLDER . 'template/print.php';
        echo $print;
    }
    exit;
}
 /**
  * Get the attributes for a product or product variation.
  *
  * @param WC_Product|WC_Product_Variation $product
  * @return array
  */
 protected function get_attributes($product)
 {
     $attributes = array();
     if ($product->is_type('variation')) {
         // Variation attributes.
         foreach ($product->get_variation_attributes() as $attribute_name => $attribute) {
             $name = str_replace('attribute_', '', $attribute_name);
             // Taxonomy-based attributes are prefixed with `pa_`, otherwise simply `attribute_`.
             if (0 === strpos($attribute_name, 'attribute_pa_')) {
                 $attributes[] = array('id' => wc_attribute_taxonomy_id_by_name($name), 'name' => $this->get_attribute_taxonomy_label($name), 'option' => $attribute);
             } else {
                 $attributes[] = array('id' => 0, 'name' => str_replace('pa_', '', $name), 'option' => $attribute);
             }
         }
     } else {
         foreach ($product->get_attributes() as $attribute) {
             if ($attribute['is_taxonomy']) {
                 $attributes[] = array('id' => wc_attribute_taxonomy_id_by_name($attribute['name']), 'name' => $this->get_attribute_taxonomy_label($attribute['name']), 'position' => (int) $attribute['position'], 'visible' => (bool) $attribute['is_visible'], 'variation' => (bool) $attribute['is_variation'], 'options' => $this->get_attribute_options($product->id, $attribute));
             } else {
                 $attributes[] = array('id' => 0, 'name' => str_replace('pa_', '', $attribute['name']), 'position' => (int) $attribute['position'], 'visible' => (bool) $attribute['is_visible'], 'variation' => (bool) $attribute['is_variation'], 'options' => $this->get_attribute_options($product->id, $attribute));
             }
         }
     }
     return $attributes;
 }
 /**
  * Get the downloads for a product or product variation
  *
  * @since 2.1
  * @param WC_Product|WC_Product_Variation $product
  * @return array
  */
 private function get_downloads($product)
 {
     $downloads = array();
     if ($product->is_downloadable()) {
         foreach ($product->get_files() as $file_id => $file) {
             $downloads[] = array('id' => $file_id, 'name' => $file['name'], 'file' => $file['file']);
         }
     }
     return $downloads;
 }
                            $upgradeamount = 100;
                            $upgradeVariation = 783;
                            break;
                        case 100:
                            $upgradeamount = 200;
                            $upgradeVariation = 784;
                            break;
                        case 200:
                            $upgradeamount = -1;
                            // Need to handle the top item with contact us.
                            $upgradeVariation = -1;
                            // Need to handle unknown cost...
                            break;
                    }
                }
                $_product = new WC_Product_Variation($upgradeVariation);
                $upgradecost = intval($_product->get_price()) - $totalPrice + $addupgrade_cost;
            }
        }
        //Setting the counts
        if ($upgradeamount >= 0) {
            $the_final_count = strtoupper($upgradeamount);
        }
    }
    ?>
					<?php 
    if (false) {
        // Old layout for counter
        ?>
<em class="counter"><?php 
        echo $received_count;