private function get_product_attr($postID) { global $woocommerce; $return = array(); $product = new WC_Product_Variable($postID); #Step 1: Get product varations $available_variations = $product->get_available_variations(); #Step 2: Get product variation id $variation_id = $available_variations[0]['variation_id']; // Getting the variable id of just the 1st product. You can loop $available_variations to get info about each variation. #Step 3: Create the variable product object $variable_product1 = new WC_Product_Variation($variation_id); #Step 4: You have the data. Have fun :) $return['regular_price'] = get_post_meta($postID, '_regular_price', true); return $return; }
/** * Handle variation duplicate * * @return boolean false if the from product contains no variatoins */ public function duplicate() { $fromVariation = $this->from->get_available_variations(); if (empty($fromVariation)) { return false; } if ($this->to->id === $this->from->id) { /* * In such a case just add the duplicate meta key */ foreach ($fromVariation as $variation) { if (!metadata_exists('post', $variation['variation_id'], self::DUPLICATE_KEY)) { update_post_meta($variation['variation_id'], self::DUPLICATE_KEY, $variation['variation_id']); } } } else { /* This could be a very long operation */ set_time_limit(0); foreach ($fromVariation as $variation) { /* * First we check if the "to" product contains the duplicate meta * key to find out if we have to update or insert */ $posts = get_posts(array('meta_key' => self::DUPLICATE_KEY, 'meta_value' => $variation['variation_id'], 'post_type' => 'product_variation', 'post_parent' => $this->to->id)); switch (count($posts)) { case 1: // update $this->update(wc_get_product($variation['variation_id']), $posts[0], $variation); break; case 0: // insert $this->insert(wc_get_product($variation['variation_id']), $variation); break; default: // we can not handle, something wrong here break; } } /* Restore original timeout */ set_time_limit(ini_get('max_execution_time')); } }
/** * Add woo attributes to a custom field with the same name * * @param $custom_fields * @param $post_id * * @return mixed */ public function filter_custom_fields($custom_fields, $post_id) { if (!isset($custom_fields)) { $custom_fields = array(); } // Get the product correponding to this post $product = wc_get_product($post_id); if (false === $product) { // Not a product return $custom_fields; } switch ($product->get_type()) { case self::PRODUCT_TYPE_VARIABLE: $product_variable = new WC_Product_Variable($product); foreach ($product_variable->get_available_variations() as $variation_array) { foreach ($variation_array['attributes'] as $attribute_name => $attribute_value) { if (!isset($custom_fields[$attribute_name])) { $custom_fields[$attribute_name] = array(); } if (!in_array($attribute_value, $custom_fields[$attribute_name], true)) { array_push($custom_fields[$attribute_name], $attribute_value); } } } break; default: foreach ($product->get_attributes() as $attribute) { //$terms = wc_get_product_terms( $product->id, $attribute['name'], array( 'fields' => 'names' ) ); // Remove the eventual 'pa_' prefix from the global attribute name $attribute_name = $attribute['name']; if (substr($attribute_name, 0, 3) === 'pa_') { $attribute_name = substr($attribute_name, 3, strlen($attribute_name)); } $custom_fields[$attribute_name] = explode(',', $product->get_attribute($attribute['name'])); } break; } return $custom_fields; }
function woocomposer_list_shortcode($atts) { global $woocommerce; $img_position = $img_size = $img_border = $border_size = $border_radius = $border_color = $title_font = $price_font = $price_color = $rating_color = $rating_font = $shortcode = ''; extract(shortcode_atts(array("img_position" => "", "shortcode" => "", "img_size" => "", "img_border" => "", "border_size" => "", "border_radius" => "", "border_color" => "", "title_color" => "", "title_font" => "", "price_font" => "", "price_color" => "", "rating_color" => "", "rating_font" => ""), $atts)); $output = $on_sale = $style = $title_style = $pricing_style = $rating_style = ''; if ($img_size !== "") { $style .= 'width:' . $img_size . 'px; height:' . $img_size . 'px;'; } if ($title_color !== "") { $title_style .= 'color:' . $title_color . ';'; } if ($title_font !== "") { $title_style .= 'font-size:' . $title_font . 'px;'; } if ($img_border !== '') { $style .= 'border-style:' . $img_border . ';'; if ($border_size !== '') { $style .= 'border-width:' . $border_size . 'px;'; } if ($border_color !== '') { $style .= 'border-color:' . $border_color . ';'; } if ($border_radius !== '') { $style .= 'border-radius:' . $border_radius . 'px;'; } } if ($price_font !== "") { $pricing_style .= 'font-size:' . $price_font . 'px;'; } if ($price_color !== "") { $pricing_style .= 'color:' . $price_color . ';'; } if ($rating_color !== "") { $rating_style .= 'color:' . $rating_color . ';'; } if ($rating_font !== "") { $rating_style .= 'font-size:' . $rating_font . 'px;'; } $post_count = '12'; $output .= '<div class="woocomposer_list woocommerce">'; /* $output .= do_shortcode($content); */ $pattern = get_shortcode_regex(); if ($shortcode !== '') { $new_shortcode = rawurldecode(base64_decode(strip_tags($shortcode))); } preg_match_all("/" . $pattern . "/", $new_shortcode, $matches); $shortcode_str = str_replace('"', '', str_replace(" ", "&", trim($matches[3][0]))); $short_atts = parse_str($shortcode_str); //explode("&",$shortcode_str); if (isset($matches[2][0])) { $display_type = $matches[2][0]; } else { $display_type = ''; } if (!isset($columns)) { $columns = '4'; } if (isset($per_page)) { $post_count = $per_page; } if (isset($number)) { $post_count = $number; } if (!isset($order)) { $order = 'ASC'; } if (!isset($orderby)) { $orderby = 'date'; } if (!isset($category)) { $category = ''; } if (!isset($ids)) { $ids = ''; } if ($ids) { $ids = explode(',', $ids); $ids = array_map('trim', $ids); } if ($columns == "2") { $columns = 6; } elseif ($columns == "3") { $columns = 4; } elseif ($columns == "4") { $columns = 3; } $meta_query = ''; if ($display_type == "recent_products") { $meta_query = WC()->query->get_meta_query(); } if ($display_type == "featured_products") { $meta_query = array(array('key' => '_visibility', 'value' => array('catalog', 'visible'), 'compare' => 'IN'), array('key' => '_featured', 'value' => 'yes')); } if ($display_type == "top_rated_products") { add_filter('posts_clauses', array(WC()->query, 'order_by_rating_post_clauses')); $meta_query = WC()->query->get_meta_query(); } $args = array('post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'posts_per_page' => $post_count, 'orderby' => $orderby, 'order' => $order, 'meta_query' => $meta_query); if ($display_type == "sale_products") { $product_ids_on_sale = woocommerce_get_product_ids_on_sale(); $meta_query = array(); $meta_query[] = $woocommerce->query->visibility_meta_query(); $meta_query[] = $woocommerce->query->stock_status_meta_query(); $args['meta_query'] = $meta_query; $args['post__in'] = $product_ids_on_sale; } if ($display_type == "best_selling_products") { $args['meta_key'] = 'total_sales'; $args['orderby'] = 'meta_value_num'; $args['meta_query'] = array(array('key' => '_visibility', 'value' => array('catalog', 'visible'), 'compare' => 'IN')); } if ($display_type == "product_category") { $args['tax_query'] = array(array('taxonomy' => 'product_cat', 'terms' => array(esc_attr($category)), 'field' => 'slug', 'operator' => 'IN')); } if ($display_type == "product_categories") { $args['tax_query'] = array(array('taxonomy' => 'product_cat', 'terms' => $ids, 'field' => 'term_id', 'operator' => 'IN')); } $query = new WP_Query($args); $output .= '<ul class="wcmp-product-list wcmp-img-' . $img_position . ' ' . $order . '">'; if ($query->have_posts()) { while ($query->have_posts()) { $query->the_post(); $product_id = get_the_ID(); $post = get_post($product_id); $product_title = get_the_title(); $product = new WC_Product($product_id); $attachment_ids = $product->get_gallery_attachment_ids(); $price = $product->get_price_html(); $rating = $product->get_rating_html(); $product_var = new WC_Product_Variable($product_id); $available_variations = $product_var->get_available_variations(); $output .= '<li>'; $output .= '<a href="' . get_permalink($product_id) . '">'; $product_img = wp_get_attachment_image_src(get_post_thumbnail_id($product_id), 'full'); $output .= '<img style="' . $style . '" src="' . $product_img[0] . '"/>'; $output .= '<span style="' . $title_style . '">' . $product_title . '</span>'; $output .= '</a>'; if ($display_type == "top_rated_products") { $output .= '<div style="' . $rating_style . '">' . $rating . '</div>'; } $output .= '<span class="amount" style="' . $pricing_style . '">' . $price . '</span>'; $output .= '</li>'; } } $output .= "\n" . '</ul>'; $output .= "\n" . '</div>'; if ($display_type == "top_rated_products") { remove_filter('posts_clauses', array(WC()->query, 'order_by_rating_post_clauses')); } wp_reset_postdata(); return $output; }
function idwc_payment_vars($item, $status, $order_id, $qty_num) { $order = new WC_Order($order_id); if (isset($item['product_id'])) { $product_id = $item['product_id']; } if (isset($item['variation_id'])) { $variation_id = $item['variation_id']; } if (isset($product_id)) { $project_id = get_post_meta($product_id, '_wc_project_pairing', true); if (isset($project_id)) { $product = new WC_Product_Variable($product_id); if (!empty($product)) { $variations = $product->get_available_variations(); $v_array = array(); foreach ($variations as $variant) { $v_array[] = $variant['variation_id']; } $level = array_search($variation_id, $v_array) + 1; } $first_name = get_post_meta($order_id, '_billing_first_name', true); $last_name = get_post_meta($order_id, '_billing_last_name', true); $email = get_post_meta($order_id, '_billing_email', true); $address = get_post_meta($order_id, '_billing_address_1', true); $city = get_post_meta($order_id, '_billing_city', true); $state = get_post_meta($order_id, '_billing_state', true); $zip = get_post_meta($order_id, '_billing_postcode', true); $country = get_post_meta($order_id, '_billing_country', true); $transaction_id = get_post_meta($order_id, '_order_key', true); $price = get_post_meta($variation_id, '_price', true); $date = $order->order_date; $vars = array('id' => null, 'first_name' => $first_name, 'last_name' => $last_name, 'email' => $email, 'address' => $address, 'state' => $state, 'city' => $city, 'zip' => $zip, 'country' => $country, 'product_id' => $project_id, 'transaction_id' => $transaction_id . '-v' . $variation_id . '-' . $qty_num, 'preapproval_key' => '', 'product_level' => $level, 'prod_price' => $price, 'status' => $status, 'created_at' => $date); } } return isset($vars) ? $vars : array(); }
private function get_product_from_post($post_id) { $woocommerce_ver_below_2_1 = false; if (version_compare(WOOCOMMERCE_VERSION, '2.1', '<')) { $woocommerce_ver_below_2_1 = true; } if ($woocommerce_ver_below_2_1) { $product = new WC_Product_Simple($post_id); } else { $product = new WC_Product($post_id); } //$post_categories = wp_get_post_categories( $post_id ); //$categories = get_the_category(); try { $thumbnail = $product->get_image(); if ($thumbnail) { if (preg_match('/data-lazy-src="([^\\"]+)"/s', $thumbnail, $match)) { $thumbnail = $match[1]; } else { if (preg_match('/data-lazy-original="([^\\"]+)"/s', $thumbnail, $match)) { $thumbnail = $match[1]; } else { if (preg_match('/lazy-src="([^\\"]+)"/s', $thumbnail, $match)) { // Animate Lazy Load Wordpress Plugin $thumbnail = $match[1]; } else { if (preg_match('/data-echo="([^\\"]+)"/s', $thumbnail, $match)) { $thumbnail = $match[1]; } else { preg_match('/<img(.*)src(.*)=(.*)"(.*)"/U', $thumbnail, $result); $thumbnail = array_pop($result); } } } } } } catch (Exception $e) { $err_msg = "exception raised in thumbnails"; self::send_error_report($err_msg); $thumbnail = ''; } // handling scheduled sale price update if (!$woocommerce_ver_below_2_1) { $sale_price_dates_from = get_post_meta($post_id, '_sale_price_dates_from', true); $sale_price_dates_to = get_post_meta($post_id, '_sale_price_dates_to', true); if ($sale_price_dates_from || $sale_price_dates_to) { self::schedule_sale_price_update($post_id, null); } if ($sale_price_dates_from) { self::schedule_sale_price_update($post_id, $sale_price_dates_from); } if ($sale_price_dates_to) { self::schedule_sale_price_update($post_id, $sale_price_dates_to); } } $product_tags = array(); foreach (wp_get_post_terms($post_id, 'product_tag') as $tag) { $product_tags[] = $tag->name; } $product_brands = array(); if (taxonomy_exists('product_brand')) { foreach (wp_get_post_terms($post_id, 'product_brand') as $brand) { $product_brands[] = $brand->name; } } $taxonomies = array(); try { $all_taxonomies = get_option('wcis_taxonomies'); if (is_array($all_taxonomies)) { foreach ($all_taxonomies as $taxonomy) { if (taxonomy_exists($taxonomy) && !array_key_exists($taxonomy, $taxonomies)) { foreach (wp_get_post_terms($post_id, $taxonomy) as $taxonomy_value) { if (!array_key_exists($taxonomy, $taxonomies)) { $taxonomies[$taxonomy] = array(); } $taxonomies[$taxonomy][] = $taxonomy_value->name; } } } } } catch (Exception $e) { } $acf_fields = array(); try { if (class_exists('acf') && function_exists('get_field')) { $all_acf_fields = get_option('wcis_acf_fields'); if (is_array($all_acf_fields)) { foreach ($all_acf_fields as $acf_field_name) { $acf_field_value = get_field($acf_field_name, $post_id); if ($acf_field_value) { $acf_fields[$acf_field_name] = $acf_field_value; } } } } } catch (Exception $e) { } $send_product = array('product_id' => $product->id, 'currency' => get_woocommerce_currency(), 'price' => $product->get_price(), 'url' => get_permalink($product->id), 'thumbnail_url' => $thumbnail, 'action' => 'insert', 'description' => $product->get_post_data()->post_content, 'short_description' => $product->get_post_data()->post_excerpt, 'name' => $product->get_title(), 'sku' => $product->get_sku(), 'categories' => $product->get_categories(), 'tag' => $product_tags, 'store_id' => get_current_blog_id(), 'identifier' => (string) $product->id, 'product_brand' => $product_brands, 'taxonomies' => $taxonomies, 'acf_fields' => $acf_fields, 'sellable' => $product->is_purchasable(), 'visibility' => $product->is_visible(), 'stock_quantity' => $product->get_stock_quantity(), 'is_managing_stock' => $product->managing_stock(), 'is_backorders_allowed' => $product->backorders_allowed(), 'is_purchasable' => $product->is_purchasable(), 'is_in_stock' => $product->is_in_stock(), 'product_status' => get_post_status($post_id)); try { $variable = new WC_Product_Variable($post_id); $variations = $variable->get_available_variations(); $variations_sku = ''; if (!empty($variations)) { foreach ($variations as $variation) { if ($product->get_sku() != $variation['sku']) { $variations_sku .= $variation['sku'] . ' '; } } } $send_product['variations_sku'] = $variations_sku; $all_attributes = $product->get_attributes(); $attributes = array(); if (!empty($all_attributes)) { foreach ($all_attributes as $attr_mame => $value) { if ($all_attributes[$attr_mame]['is_taxonomy']) { if (!$woocommerce_ver_below_2_1) { $attributes[$attr_mame] = wc_get_product_terms($post_id, $attr_mame, array('fields' => 'names')); } else { $attributes[$attr_mame] = woocommerce_get_product_terms($post_id, $attr_mame, 'names'); } } else { $attributes[$attr_mame] = $product->get_attribute($attr_mame); } } } $send_product['attributes'] = $attributes; $send_product['total_variable_stock'] = $variable->get_total_stock(); try { if (version_compare(WOOCOMMERCE_VERSION, '2.2', '>=')) { if (function_exists('wc_get_product')) { $original_product = wc_get_product($product->id); if (is_object($original_product)) { $send_product['visibility'] = $original_product->is_visible(); $send_product['product_type'] = $original_product->product_type; } } } else { if (function_exists('get_product')) { $original_product = get_product($product->id); if (is_object($original_product)) { $send_product['visibility'] = $original_product->is_visible(); $send_product['product_type'] = $original_product->product_type; } } } } catch (Exception $e) { } } catch (Exception $e) { $err_msg = "exception raised in attributes"; self::send_error_report($err_msg); } if (!$woocommerce_ver_below_2_1) { try { $send_product['price_compare_at_price'] = $product->get_regular_price(); $send_product['price_min'] = $variable->get_variation_price('min'); $send_product['price_max'] = $variable->get_variation_price('max'); $send_product['price_min_compare_at_price'] = $variable->get_variation_regular_price('min'); $send_product['price_max_compare_at_price'] = $variable->get_variation_regular_price('max'); } catch (Exception $e) { $send_product['price_compare_at_price'] = null; $send_product['price_min'] = null; $send_product['price_max'] = null; $send_product['price_min_compare_at_price'] = null; $send_product['price_max_compare_at_price'] = null; } } else { $send_product['price_compare_at_price'] = null; $send_product['price_min'] = null; $send_product['price_max'] = null; $send_product['price_min_compare_at_price'] = null; $send_product['price_max_compare_at_price'] = null; } $send_product['description'] = self::content_filter_shortcode_with_content($send_product['description']); $send_product['short_description'] = self::content_filter_shortcode_with_content($send_product['short_description']); $send_product['description'] = self::content_filter_shortcode($send_product['description']); $send_product['short_description'] = self::content_filter_shortcode($send_product['short_description']); try { if (defined('ICL_SITEPRESS_VERSION') && is_plugin_active('woocommerce-multilingual/wpml-woocommerce.php') && function_exists('wpml_get_language_information')) { if (version_compare(ICL_SITEPRESS_VERSION, '3.2', '>=')) { $language_info = apply_filters('wpml_post_language_details', NULL, $post_id); } else { $language_info = wpml_get_language_information($post_id); } if ($language_info && is_array($language_info) && array_key_exists('locale', $language_info)) { // WP_Error could be returned from wpml_get_language_information(...) $send_product['lang'] = $language_info['locale']; } } } catch (Exception $e) { } return $send_product; }
/** * Front-end display of widget. * * @see WP_Widget::widget() * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ public function widget($args, $instance) { ?> <div class="checkout_summary"> <div class="before_widget"> <?php echo $args['before_widget']; ?> </div> <div class="before_title"> <?php echo $args['before_title']; ?> </div> <div class="summary_title"> <?php echo $instance['title']; ?> </div> <div class="after_title"> <?php echo $args['after_title']; ?> </div> <div class="csw_content"> <!-- Widget content start from here --> <?php global $woocommerce, $current_user, $product, $post; if (sizeof($woocommerce->cart->get_cart()) > 0) { foreach ($woocommerce->cart->get_cart() as $cart_item_key => $values) { $product = $values['data']; // $attributes = $product->get_attributes(); // $attributes= array_map( 'trim', explode( '|', $attributes['servings']['value'] ) ); //show thumbnail $thumbnail = apply_filters('woocommerce_in_cart_product_thumbnail', $product->get_image(), $values, $cart_item_key); if (!$product->is_visible() || !empty($product->variation_id) && !$product->parent_is_visible()) { echo $thumbnail; } else { printf('<a href="%s">%s</a>', esc_url(get_permalink(apply_filters('woocommerce_in_cart_product_id', $values['product_id']))), $thumbnail); } //end Thumbnail if (!$product->is_visible() || !empty($product->variation_id) && !$product->parent_is_visible()) { echo apply_filters('woocommerce_in_cart_product_title', $product->get_title(), $values, $cart_item_key); } else { printf('<a class="product-title" href="%s">%s</a>', esc_url(get_permalink(apply_filters('woocommerce_in_cart_product_id', $values['product_id']))), apply_filters('woocommerce_in_cart_product_title', $product->get_title(), $values, $cart_item_key)); } $product_id = $product->parent->id ? $product->parent->id : $product->id; $object = new WC_Product_Variable($product_id); $cardDetails = $woocommerce->cart->get_cart(); foreach ($cardDetails as $cDK => $cDV) { $pType = $cDV['data']->parent->product_type ? $cDV['data']->parent->product_type : $cDV['data']->product_type; break; } $attributes = $object->get_available_variations(); foreach ($attributes as $name => $option) { if ('variable-subscription' == $pType) { echo '<div class="plan_content">'; echo '<div class="plan_option">'; } $checked = ""; $single_f_vari = $product->variation_data['attribute_servings']; $html = strip_tags($option['price_html']); if ($product->variation_data['attribute_servings'] == $option['attributes']['attribute_servings']) { $checked = "checked=\"checked\""; } if ('variable-subscription' == $pType) { echo '<input type="radio" ' . $checked . ' vari_id="' . $option["variation_id"] . '" vari_name="' . $option["attributes"]["attribute_servings"] . '" prod_id="' . $product_id . '" class="choose_plan" id="' . $html . '" value="' . $html . '" />' . apply_filters('woocommerce_variation_option_name', $option["attributes"]["attribute_servings"]) . ''; echo '</div>'; echo '<div class="plan_price">'; echo strip_tags($option['price_html']); echo '</div>'; echo '</div>'; } } } if ('variable-subscription' == $pType) { //for subscription echo '<div class="delivery_date_view">'; echo '<h3>First Delivery</h3>'; echo get_delivery_date(); echo '</div>'; } else { //for single delivery echo '<div class="delivery_date_view">'; echo '<h3 style="float: left;">Delivery Date</h3>'; echo '<div style="margin: 20px 0 0 160px;">' . get_delivery_date() . '</div>'; echo '<div style="clear: both;"></div>'; echo '</div>'; echo '<div class="delivery_date_view" style="margin-top: -40px;">'; echo '<h3 style="float: left;margin-top: 2px;">Servings</h3>'; echo '<div style="margin: 4px 0 0 160px;font-weight: bold;">' . $single_f_vari . '</div>'; echo '<div style="clear: both;"></div>'; echo '</div>'; } if ($woocommerce->cart->coupons_enabled() && 'variable-subscription' == $pType) { ?> <script> function changeRef(){ if(document.getElementById('ref').style.display=="block"){ document.getElementById('ref').style.display="none"; document.getElementById('coupon').style.display="block"; }else{ document.getElementById('ref').style.display="block"; document.getElementById('coupon').style.display="none"; } }</script> <div class="woocommerce-content-box full-width"> <h2><?php _e('Have A Promotional Code?', 'woocommerce'); ?> </h2> <form action=""> <div class="pcode"> <input type="radio" name="test1" value="ref" checked="checked" onclick="changeRef()">Referral Code <div class="clear"></div> </div> <div class="pcode"> <input type="radio" name="test1" value="pro" onclick="changeRef()">Coupon Code <div class="clear"></div> </div> <div class="clear"></div> </form><br> <div class="coupon"> <div id="coupon" style="display:none"> <input name="coupon_code" class="input-text" id="coupon_code" value="" st/> <input type="submit" class="button comment-submit small" id="coupon_code_submit" name="apply_coupon" value="<?php _e('Apply', 'woocommerce'); ?> " /> <?php do_action('woocommerce_cart_coupon'); ?> </div> <div id="ref" style="display:block"> <form> <input name="ref_code" class="input-text" id="ref_code" value="<?php echo $_REQUEST['ref_code']; ?> " st/> <input type="submit" id="ref_code_submit" class="button comment-submit small" value="Apply" /> </form> </div> </div> </div> <?php } else { echo '<div style="border-top:1px solid #e0dede !important;"><!-- --></div>'; } echo '<div class="total_contain">'; echo '<div class="total_left">'; echo 'Cart Subtotal'; echo '</div>'; echo '<div class="total_right">'; echo remove_text_from_amount($woocommerce->cart->get_cart_subtotal()); echo '</div>'; echo '<div class="clear"></div>'; echo '<div class="total_left">'; echo 'Shipping'; echo '</div>'; echo '<div class="total_right">'; $available_methods = $woocommerce->shipping->get_available_shipping_methods(); echo woocommerce_get_template('cart/shipping-methods.php', array('available_methods' => $available_methods)); echo '</div>'; echo '<div class="clear"></div>'; if ($woocommerce->cart->get_discounts_before_tax()) { echo '<div class="total_left">'; ?> <?php _e('Order Discount', 'woocommerce'); ?> <!--<a href="<?php echo add_query_arg('remove_discounts', '2', $woocommerce->cart->get_cart_url()); ?> "><?php _e('[Remove]', 'woocommerce'); ?> </a>--> <?php echo '</div>'; echo '<div class="total_right">'; echo remove_text_from_amount($woocommerce->cart->get_discounts_before_tax()); echo '</div>'; echo '<div class="clear"></div>'; } if ($woocommerce->cart->get_discounts_after_tax()) { echo '<div class="total_left">'; ?> <?php _e('Order Discount', 'woocommerce'); ?> <!--<a href="<?php echo add_query_arg('remove_discounts', '2', $woocommerce->cart->get_cart_url()); ?> "><?php _e('[Remove]', 'woocommerce'); ?> </a>--> <?php echo '</div>'; echo '<div class="total_right">'; echo remove_text_from_amount($woocommerce->cart->get_discounts_after_tax()); echo '</div>'; echo '<div class="clear"></div>'; } echo '<div class="total_left">'; echo 'Total'; echo '</div>'; echo '<div class="total_right">'; echo remove_text_from_amount($woocommerce->cart->get_total()); echo '</div>'; echo '<div class="clear"></div>'; if ('variable-subscription' == $pType) { $post = get_post(4964, ARRAY_A); echo $content = $post['post_content']; } echo '<div class="clear"></div>'; echo '</div>'; } ?> <!-- Widget content end --> </div> <div class="after_widget"> <?php echo $args['after_widget']; ?> </div> </div> <?php }
function hocwp_wc_insert_order($data) { $post_id = hocwp_get_value_by_key($data, 'post_id'); if (hocwp_id_number_valid($post_id)) { $post = get_post($post_id); if (is_a($post, 'WP_Post') && 'product' == $post->post_type) { $product = wc_get_product($post_id); $variable_product = new WC_Product_Variable($product); $variations = $variable_product->get_available_variations(); $variation_args = array(); $variation_id = null; foreach ($variations as $variation) { $variation_id = $variation['variation_id']; $variation_args['variation'] = $variation['attributes']; } $name = hocwp_get_value_by_key($data, 'name'); $phone = hocwp_get_value_by_key($data, 'phone'); $email = hocwp_get_value_by_key($data, 'email'); $address = hocwp_get_value_by_key($data, 'address'); $message = hocwp_get_value_by_key($data, 'message'); $name = hocwp_sanitize_first_and_last_name($name); $attributes = hocwp_get_value_by_key($data, 'attributes'); $addresses = array('first_name' => $name['first_name'], 'last_name' => $name['last_name'], 'email' => $email, 'phone' => $phone, 'address_1' => $address); $args = array('customer_note' => $message, 'created_via' => 'programmatically'); if (is_user_logged_in()) { $current = wp_get_current_user(); $args['customer_id'] = $current->ID; } $order = wc_create_order($args); $gateway = WC_Payment_Gateways::instance(); $gateways = $gateway->get_available_payment_gateways(); if (hocwp_array_has_value($gateways)) { $gateway = current($gateways); $order->set_payment_method($gateway); } $order->set_address($addresses); $order->set_address($addresses, 'shipping'); if (hocwp_array_has_value($attributes) && hocwp_id_number_valid($variation_id)) { foreach ($attributes as $attribute) { $attribute_name = hocwp_get_value_by_key($attribute, 'name'); $attribute_value = hocwp_get_value_by_key($attribute, 'value'); if (!empty($attribute_name) && !empty($attribute_value)) { if (isset($variation_args['variation'][$attribute_name])) { $variation_args['variation'][$attribute_name] = $attribute_value; } } } $variation_product = new WC_Product_Variation($variation_id); $order->add_product($variation_product, 1, $variation_args); } else { $order->add_product($product); } $order->record_product_sales(); $order->calculate_totals(); $order->payment_complete(); return $order; } } return false; }