/**
  * Get variation price HTML. Prices are not inherited from parents.
  *
  * @return string containing the formatted price
  */
 public function get_price_html($price = '')
 {
     $price = parent::get_price_html($price);
     if (!empty($price)) {
         $price = WC_Subscriptions_Product::get_price_string($this, array('price' => $price));
     }
     return $price;
 }
 /**
  * Get variation price HTML. Prices are not inherited from parents.
  *
  * @return string containing the formatted price
  */
 public function get_price_html($price = '')
 {
     $price = parent::get_price_html($price = '');
     return WC_Subscriptions_Product::get_price_string($this, array('price' => $price));
 }
 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;
 }
示例#4
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;
 }