Get variation attribute values. Keys are prefixed with attribute_, as stored.
public get_variation_attributes ( ) : array | ||
return | array | of attributes and their values for this variation |
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); }
/** * Get the attributes for a product or product variation. * * @param WC_Product|WC_Product_Variation $product Product instance. * @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); if (!$attribute) { continue; } // Taxonomy-based attributes are prefixed with `pa_`, otherwise simply `attribute_`. if (0 === strpos($attribute_name, 'attribute_pa_')) { $option_term = get_term_by('slug', $attribute, $name); $attributes[] = array('id' => wc_attribute_taxonomy_id_by_name($name), 'name' => $this->get_attribute_taxonomy_label($name), 'option' => $option_term && !is_wp_error($option_term) ? $option_term->name : $attribute); } else { $attributes[] = array('id' => 0, 'name' => $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->get_id(), $attribute)); } else { $attributes[] = array('id' => 0, 'name' => $attribute['name'], 'position' => (int) $attribute['position'], 'visible' => (bool) $attribute['is_visible'], 'variation' => (bool) $attribute['is_variation'], 'options' => $this->get_attribute_options($product->get_id(), $attribute)); } } } return $attributes; }
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; }
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; }
function column_title($post) { global $woocommerce; $post_to_edit_id = $post->post_type == 'product' ? $post->ID : $post->post_parent; $edit_link = admin_url('post.php?post=' . $post_to_edit_id . '&action=edit'); $view_link = esc_url(add_query_arg('preview', 'true', get_permalink($post_to_edit_id))); //Build row actions $actions = array('edit' => '<a href="' . $edit_link . '">' . __('Edit') . '</a>', 'view' => '<a href="' . $view_link . '">' . __('View') . '</a>'); if ($post->post_type == 'product_variation' && $this->last_product_id == $post->post_parent) { $post_title = ''; } else { $post_title = $post->post_title; } // Get variations if ($post->post_type == 'product_variation') { $post_title = trim(current(explode('-', $post_title))); $post_title .= ' — '; if (function_exists('get_product')) { $variable_product = get_product($post->ID); } else { $variable_product = new WC_Product_Variation($post->ID); } $list_attributes = array(); $attributes = $variable_product->get_variation_attributes(); foreach ($attributes as $name => $attribute) { $list_attributes[] = $woocommerce->attribute_label(str_replace('attribute_', '', $name)) . ': <strong>' . $attribute . '</strong>'; } $post_title .= implode(', ', $list_attributes); } //Return the title contents return sprintf('%1$s %2$s', $post_title, $this->row_actions($actions)); }
/** * 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>'; }
/** * This function shows the buy for credit button on products page * @param int $attr */ function single_product_buy_button($attr) { global $translate; global $product; $class = ''; extract(shortcode_atts(array('class' => 'class', 'title' => 'title'), $attr)); if ($class !== 'class') { $class = 'class="' . $class . '"'; } else { $class = 'class="creditsBuyButton button"'; } if ($product->product_type == 'variable') { $available_variations = $product->get_available_variations(); if (!empty($available_variations)) { foreach ($available_variations as $variation) { $variation = new WC_Product_Variation($variation['variation_id']); $title = $variation->get_price() . ' ' . $translate->wooTranslate('Credits', get_bloginfo('language')) . ' - ' . implode(', ', $variation->get_variation_attributes()); echo '<a ' . $class . ' href="javascript:void(0);" onclick="creditdeduct(' . $product->id . ',' . $variation->get_price() . ',' . $variation->variation_id . ')" >' . $title . '</a><br/>'; } } } else { if ($title === 'title') { $title = $product->price . ' ' . $translate->wooTranslate('Credits', get_bloginfo('language')); } echo '<a ' . $class . ' href="javascript:void(0);" onclick="creditdeduct(' . $product->id . ',' . $product->price . ')" >' . $title . '</a>'; } }
/** * 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) { // Taxonomy-based attributes are comma-separated, others are pipe (|) separated. if ($attribute['is_taxonomy']) { $attributes[] = array('id' => $attribute['is_taxonomy'] ? wc_attribute_taxonomy_id_by_name($attribute['name']) : 0, 'name' => $this->get_attribute_taxonomy_label($attribute['name']), 'position' => (int) $attribute['position'], 'visible' => (bool) $attribute['is_visible'], 'variation' => (bool) $attribute['is_variation'], 'options' => array_map('trim', explode(',', $product->get_attribute($attribute['name'])))); } 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' => array_map('trim', explode('|', $product->get_attribute($attribute['name'])))); } } } return $attributes; }
public function custom_process($order_id) { $order = new WC_Order($order_id); $items = $order->get_items(); $index = 1; // for each order item foreach ($items as $item) { $tixids = array(); $eid = get_post_meta($item['product_id'], '_eventid', true); // Make sure these are indeed ticket sales //$terms = wp_get_post_terms($item['product_id'], 'product_cat', array('fields'=>'names')); // Check if these order items are event ticket items if (!empty($eid)) { // get order post meta array $order_meta = get_post_custom($order_id, true); $user_id_ = $order_meta['_customer_user'][0]; // Specify order type only for ticket sale if ($index == 1) { update_post_meta($order_id, '_order_type', 'evotix'); } // get repeat interval for order item $item_meta = !empty($item['Event-Time']) ? $item['Event-Time'] : false; if ($item_meta) { $ri__ = explode('[RI', $item_meta); $ri_ = explode(']', $ri__[1]); $ri = $ri_[0]; } else { $ri = 0; } // Get customer information if ($user_id_ == 0) { // checkout without creating account $_user = array('name' => $order_meta['_billing_first_name'][0] . ' ' . $order_meta['_billing_last_name'][0], 'email' => $order_meta['_billing_email'][0]); } else { //$myuser_id = $order->user_id; $usermeta = get_user_meta($user_id_); $_user = array('name' => $usermeta['first_name'][0] . ' ' . $usermeta['last_name'][0], 'email' => $usermeta['billing_email'][0]); } // create new event ticket post if ($created_tix_id = $this->create_post()) { $ticket_ids = $ticket_ids_ = array(); // variation product if (!empty($item['variation_id'])) { $_product = new WC_Product_Variation($item['variation_id']); $hh = $_product->get_variation_attributes(); foreach ($hh as $f => $v) { $type = $v; } } else { $type = 'Normal'; } // ticket ID(s) $tid = $created_tix_id . '-' . $order_id . '-' . (!empty($item['variation_id']) ? $item['variation_id'] : $item['product_id']); if ($item['qty'] > 1) { $_tid = ''; $str = 'A'; for ($x = 0; $x < $item['qty']; $x++) { // each ticket in item $strng = $x == 0 ? $str : ++$str; $ticket_ids[$tid . $strng] = 'check-in'; $ticket_ids_[] = $tid . $strng; } } else { // just one ticket $ticket_ids[$tid] = 'check-in'; $ticket_ids_[] = $tid; } // save ticket data $this->create_custom_fields($created_tix_id, 'name', $_user['name']); $this->create_custom_fields($created_tix_id, 'email', $_user['email']); $this->create_custom_fields($created_tix_id, 'qty', $item['qty']); $this->create_custom_fields($created_tix_id, 'cost', $order->get_line_subtotal($item)); $this->create_custom_fields($created_tix_id, 'type', $type); $this->create_custom_fields($created_tix_id, 'ticket_ids', $ticket_ids); $this->create_custom_fields($created_tix_id, 'wcid', $item['product_id']); $this->create_custom_fields($created_tix_id, 'tix_status', 'none'); $this->create_custom_fields($created_tix_id, 'status', 'check-in'); $this->create_custom_fields($created_tix_id, '_eventid', $eid); $this->create_custom_fields($created_tix_id, '_orderid', $order_id); $this->create_custom_fields($created_tix_id, '_customerid', $user_id_); $this->create_custom_fields($created_tix_id, 'repeat_interval', $ri); // save event ticket id to order id $tixids = get_post_meta($order_id, '_tixids', true); if (is_array($tixids)) { // if previously saved tixid array $tixids_ = array_merge($tixids, $ticket_ids_); } else { // empty of saved as string $tixids_ = $ticket_ids_; } // save ticket ids as array update_post_meta($order_id, '_tixids', $tixids_); // update product capacity if repeat interval capacity is set // seperately per individual repeat interval $emeta = get_post_meta($eid); if (evo_check_yn($emeta, '_manage_repeat_cap') && evo_check_yn($emeta, 'evcal_repeat') && !empty($emeta['repeat_intervals']) && !empty($emeta['ri_capacity'])) { // repeat capacity values for this event $ri_capacity = unserialize($emeta['ri_capacity'][0]); // repeat capacity for this repeat interval $capacity_for_this_event = $ri_capacity[$ri]; $new_capacity = $capacity_for_this_event - $item['qty']; $ri_capacity[$ri] = $new_capacity >= 0 ? $new_capacity : 0; // save the adjusted repeat capacity update_post_meta($eid, 'ri_capacity', $ri_capacity); } } } $index++; } // endforeach }
public function wpmp_content_invoice($order, $order_detail_by_order_id) { $msg = '<!-- Content -->'; $msg .= '<table border="0" cellpadding="20" cellspacing="0" width="100%">'; $msg .= '<tr>'; $msg .= '<td valign="top" style="padding: 48px;">'; $msg .= '<div id="body_content_inner" style="color: #737373; font-size: 14px; line-height: 150%; text-align: left;"">'; $msg .= '<p style="margin: 0 0 16px;">You have received an order from ' . $order->billing_first_name . ' ' . $order->billing_last_name . '. The order is as follows:</p>'; $msg .= '<h2 style="color: #557da1; display: block; font-size: 18px; font-weight: bold; line-height: 130%; margin: 16px 0 8px; text-align: left;"">'; $msg .= 'Order #' . $order->id . ' ( ' . date_i18n(wc_date_format(), strtotime($order->order_date)) . ' )'; $msg .= '</h2>'; $msg .= '<table cellspacing="0" cellpadding="6" style="width: 100%; border: 1px solid #eee;" border="1" bordercolor="#eee">'; $msg .= '<thead>'; $msg .= '<tr>'; $msg .= '<th scope="col" style="text-align: left; border: 1px solid #eee; padding: 12px;">Product</th>'; $msg .= '<th scope="col" style="text-align: left; border: 1px solid #eee; padding: 12px;">Quantity</th>'; $msg .= '<th scope="col" style="text-align: left; border: 1px solid #eee; padding: 12px;">Price</th>'; $msg .= '</tr>'; $msg .= '</thead>'; $msg .= '<tbody>'; $total_payment = 0; $cur_symbol = get_woocommerce_currency_symbol(get_option('woocommerce_currency')); foreach ($order_detail_by_order_id as $product_id => $details) { for ($i = 0; $i < count($details); $i++) { $total_payment = $total_payment + intval($details[$i]['product_total_price']); if ($details[$i]['variable_id'] == 0) { $msg .= '<tr>'; $msg .= '<td style="text-align: left; vertical-align: middle; border: 1px solid #eee; word-wrap: break-word; padding: 12px;">' . $details[$i]['product_name']; $msg .= '<br>'; $msg .= '<small></small>'; $msg .= '</td>'; $msg .= '<td style="text-align: left; vertical-align: middle; border: 1px solid #eee; padding: 12px;">' . $details[$i]['qty'] . '</td>'; $msg .= '<td style="text-align: left; vertical-align: middle; border: 1px solid #eee; padding: 12px;">'; $msg .= '<span class="amount">' . $cur_symbol . $details[$i]['product_total_price'] . '</span>'; $msg .= '</td>'; $msg .= '</tr>'; } else { $product = new WC_Product($product_id); $attribute = $product->get_attributes(); $attribute_name = ''; foreach ($attribute as $key => $value) { $attribute_name = $value['name']; } $variation = new WC_Product_Variation($details[$i]['variable_id']); $aaa = $variation->get_variation_attributes(); $attribute_prop = strtoupper($aaa['attribute_' . strtolower($attribute_name)]); $msg .= '<tr>'; $msg .= '<td style="text-align: left; vertical-align: middle; border: 1px solid #eee; word-wrap: break-word; padding: 12px;">' . $details[$i]['product_name']; $msg .= '<br><small>' . $attribute_name . ':' . $attribute_prop . '</small>'; $msg .= '</td>'; $msg .= '<td style="text-align: left; vertical-align: middle; border: 1px solid #eee; padding: 12px;">' . $details[$i]['qty'] . '</td>'; $msg .= '<td style="text-align: left; vertical-align: middle; border: 1px solid #eee; padding: 12px;">'; $msg .= '<span class="amount">' . $cur_symbol . $details[$i]['product_total_price'] . '</span>'; $msg .= '</td>'; $msg .= '</tr>'; } } } $msg .= '</tbody>'; $msg .= '<tfoot>'; /*$msg .= '<!-- <tr>'; $msg .= '<th scope="row" colspan="2" style="text-align: left; border: 1px solid #eee; border-top-width: 4px; padding: 12px;">Subtotal:</th>'; $msg .= '<td style="text-align: left; border: 1px solid #eee; border-top-width: 4px; padding: 12px;">'; $msg .= '<span class="amount"></span>'; $msg .= '</td>'; $msg .= '</tr> -->';*/ $msg .= '<tr>'; $msg .= '<th scope="row" colspan="2" style="text-align: left; border: 1px solid #eee; padding: 12px;">Shipping:</th>'; $msg .= '<td style="text-align: left; border: 1px solid #eee; padding: 12px;">' . $order->get_shipping_method() . '</td>'; $msg .= '</tr>'; $msg .= '<tr>'; $msg .= '<th scope="row" colspan="2" style="text-align: left; border: 1px solid #eee; padding: 12px;">Payment Method:</th>'; $msg .= '<td style="text-align: left; border: 1px solid #eee; padding: 12px;">' . $order->payment_method_title . '</td>'; $msg .= '</tr>'; $msg .= '<tr>'; $msg .= '<th scope="row" colspan="2" style="text-align: left; border: 1px solid #eee; padding: 12px;">Total:</th>'; $msg .= '<td style="text-align: left; border: 1px solid #eee; padding: 12px;">'; $msg .= '<span class="amount">' . $total_payment . '</span>'; $msg .= '</td>'; $msg .= '</tr>'; $msg .= '</tfoot>'; $msg .= '</table>'; $msg .= '<h2 style="color: #557da1; display: block; font-size: 18px; font-weight: bold; line-height: 130%; margin: 16px 0 8px; text-align: left;">Customer details</h2>'; $msg .= '<p style="margin: 0 0 16px;">'; $msg .= '<strong>Email:</strong>'; if ($order->billing_email) { $msg .= $order->billing_email; } $msg .= '</p>'; $msg .= '<p style="margin: 0 0 16px;">'; $msg .= '<strong>Tel:</strong>'; if ($order->billing_phone) { $msg .= $order->billing_phone; } $msg .= '</p>'; $msg .= '<table cellspacing="0" cellpadding="0" style="width: 100%; vertical-align: top;" border="0">'; $msg .= '<tr>'; $msg .= '<td valign="top" width="50%" style="padding: 12px;">'; $font = ' font-family: "Helvetica Neue", Helvetica, Roboto, Arial, sans-serif;'; $msg .= "<h3 style='color: #557da1; display: block;" . $font . " font-size: 16px; font-weight: bold; line-height: 130%; margin: 16px 0 8px; text-align: left;'>Billing address</h3>"; $msg .= '<p style="margin: 0 0 16px;">' . $order->get_formatted_billing_address(); $msg .= '</p>'; $msg .= '</td>'; if (!wc_ship_to_billing_address_only() && $order->needs_shipping_address() && ($shipping = $order->get_formatted_shipping_address())) { $msg .= '<td valign="top" width="50%" style="padding: 12px;">'; $msg .= "<h3 style='color: #557da1; display: block; font-size: 16px; font-weight: bold; line-height: 130%; margin: 16px 0 8px; text-align: left;'>Shipping address</h3>"; $msg .= '<p style="margin: 0 0 16px;">' . $shipping; $msg .= '</p>'; $msg .= '</td>'; } $msg .= '</tr>'; $msg .= '</table>'; $msg .= '</div>'; $msg .= '</td>'; $msg .= '</tr>'; $msg .= '</table>'; $msg .= '<!-- End Content -->'; return $msg; }
echo eventon_get_custom_language($evo_options_2, 'evoTX_005a', 'Event Time'); ?> </p> <p style='<?php echo $__styles_03; ?> '><?php echo $event_time; ?> </p> <?php if (!empty($ticket_item['variation_id'])) { $_product = new WC_Product_Variation($ticket_item['variation_id']); $hh = $_product->get_variation_attributes(); foreach ($hh as $f => $v) { if (empty($v)) { continue; } ?> <p style='<?php echo $__styles_03; ?> '><span style='<?php echo $__styles_02a; ?> '><?php echo eventon_get_custom_language($evo_options_2, 'evoTX_006', 'Type'); ?> :</span> <?php
function bf_wc_variations_custom($thepostid, $customfield) { global $variation_data, $post; $post = get_post($thepostid); $variation_data = new WC_Product_Variation($post); $variation_data->get_variation_attributes(); $variation_data = (array) $variation_data; echo '<pre>'; print_r($variation_data); echo '</pre>'; extract($variation_data); ?> <div class="woocommerce_variation wc-metabox closed"> <h3> <a href="#" class="remove_variation delete" rel="<?php echo esc_attr($variation_id); ?> "><?php _e('Remove', 'woocommerce'); ?> </a> <div class="handlediv" title="<?php esc_attr_e('Click to toggle', 'woocommerce'); ?> "></div> <div class="tips sort" data-tip="<?php esc_attr_e('Drag and drop, or click to set menu order manually', 'woocommerce'); ?> "></div> <strong>#<?php echo esc_html($variation_id); ?> : </strong> <?php if (isset($parent_data)) { foreach ($parent_data['attributes'] as $attribute) { // Only deal with attributes that are variations if (!$attribute['is_variation']) { continue; } // Get current value for variation (if set) $variation_selected_value = isset($variation_data['attribute_' . sanitize_title($attribute['name'])]) ? $variation_data['attribute_' . sanitize_title($attribute['name'])] : ''; // Name will be something like attribute_pa_color echo '<select name="attribute_' . sanitize_title($attribute['name']) . '[' . $loop . ']"><option value="">' . __('Any', 'woocommerce') . ' ' . esc_html(wc_attribute_label($attribute['name'])) . '…</option>'; // Get terms for attribute taxonomy or value if its a custom attribute if ($attribute['is_taxonomy']) { $post_terms = wp_get_post_terms($parent_data['id'], $attribute['name']); foreach ($post_terms as $term) { echo '<option ' . selected($variation_selected_value, $term->slug, false) . ' value="' . esc_attr($term->slug) . '">' . apply_filters('woocommerce_variation_option_name', esc_html($term->name)) . '</option>'; } } else { $options = wc_get_text_attributes($attribute['value']); foreach ($options as $option) { $selected = sanitize_title($variation_selected_value) === $variation_selected_value ? selected($variation_selected_value, sanitize_title($option), false) : selected($variation_selected_value, $option, false); echo '<option ' . $selected . ' value="' . esc_attr($option) . '">' . esc_html(apply_filters('woocommerce_variation_option_name', $option)) . '</option>'; } } echo '</select>'; } } ?> <input type="hidden" name="variable_post_id[<?php echo $loop; ?> ]" value="<?php echo esc_attr($variation_id); ?> " /> <input type="hidden" class="variation_menu_order" name="variation_menu_order[<?php echo $loop; ?> ]" value="<?php echo absint($menu_order); ?> " /> </h3> <div class="woocommerce_variable_attributes wc-metabox-content" style="display: none;"> <div class="data"> <p class="form-row form-row-first upload_image"> <a href="#" class="upload_image_button tips <?php if ($_thumbnail_id > 0) { echo 'remove'; } ?> " data-tip="<?php if ($_thumbnail_id > 0) { echo __('Remove this image', 'woocommerce'); } else { echo __('Upload an image', 'woocommerce'); } ?> " rel="<?php echo esc_attr($variation_id); ?> "><img src="<?php if (!empty($image)) { echo esc_attr($image); } else { echo esc_attr(wc_placeholder_img_src()); } ?> " /><input type="hidden" name="upload_image_id[<?php echo $loop; ?> ]" class="upload_image_id" value="<?php echo esc_attr($_thumbnail_id); ?> " /></a> </p> <?php if (wc_product_sku_enabled()) { ?> <p class="sku form-row form-row-last"> <label><?php _e('SKU', 'woocommerce'); ?> : <a class="tips" data-tip="<?php esc_attr_e('Enter a SKU for this variation or leave blank to use the parent product SKU.', 'woocommerce'); ?> " href="#">[?]</a></label> <input type="text" size="5" name="variable_sku[<?php echo $loop; ?> ]" value="<?php if (isset($_sku)) { echo esc_attr($_sku); } ?> " placeholder="<?php echo esc_attr($parent_data['sku']); ?> " /> </p> <?php } else { ?> <input type="hidden" name="variable_sku[<?php echo $loop; ?> ]" value="<?php if (isset($_sku)) { echo esc_attr($_sku); } ?> " /> <?php } ?> <p class="form-row form-row-full options"> <label><input type="checkbox" class="checkbox" name="variable_enabled[<?php echo $loop; ?> ]" <?php checked($variation->post_status, 'publish'); ?> /> <?php _e('Enabled', 'woocommerce'); ?> </label> <label><input type="checkbox" class="checkbox variable_is_downloadable" name="variable_is_downloadable[<?php echo $loop; ?> ]" <?php checked(isset($_downloadable) ? $_downloadable : '', 'yes'); ?> /> <?php _e('Downloadable', 'woocommerce'); ?> <a class="tips" data-tip="<?php esc_attr_e('Enable this option if access is given to a downloadable file upon purchase of a product', 'woocommerce'); ?> " href="#">[?]</a></label> <label><input type="checkbox" class="checkbox variable_is_virtual" name="variable_is_virtual[<?php echo $loop; ?> ]" <?php checked(isset($_virtual) ? $_virtual : '', 'yes'); ?> /> <?php _e('Virtual', 'woocommerce'); ?> <a class="tips" data-tip="<?php esc_attr_e('Enable this option if a product is not shipped or there is no shipping cost', 'woocommerce'); ?> " href="#">[?]</a></label> <?php if (get_option('woocommerce_manage_stock') == 'yes') { ?> <label><input type="checkbox" class="checkbox variable_manage_stock" name="variable_manage_stock[<?php echo $loop; ?> ]" <?php checked(isset($_manage_stock) ? $_manage_stock : '', 'yes'); ?> /> <?php _e('Manage stock?', 'woocommerce'); ?> <a class="tips" data-tip="<?php esc_attr_e('Enable this option to enable stock management at variation level', 'woocommerce'); ?> " href="#">[?]</a></label> <?php } ?> <?php do_action('woocommerce_variation_options', $loop, $variation_data, $variation); ?> </p> <div class="variable_pricing"> <p class="form-row form-row-first"> <label><?php echo __('Regular Price:', 'woocommerce') . ' (' . get_woocommerce_currency_symbol() . ')'; ?> </label> <input type="text" size="5" name="variable_regular_price[<?php echo $loop; ?> ]" value="<?php if (isset($_regular_price)) { echo esc_attr($_regular_price); } ?> " class="wc_input_price" placeholder="<?php esc_attr_e('Variation price (required)', 'woocommerce'); ?> " /> </p> <p class="form-row form-row-last"> <label><?php echo __('Sale Price:', 'woocommerce') . ' (' . get_woocommerce_currency_symbol() . ')'; ?> <a href="#" class="sale_schedule"><?php _e('Schedule', 'woocommerce'); ?> </a><a href="#" class="cancel_sale_schedule" style="display:none"><?php _e('Cancel schedule', 'woocommerce'); ?> </a></label> <input type="text" size="5" name="variable_sale_price[<?php echo $loop; ?> ]" value="<?php if (isset($_sale_price)) { echo esc_attr($_sale_price); } ?> " class="wc_input_price" /> </p> <div class="sale_price_dates_fields" style="display: none"> <p class="form-row form-row-first"> <label><?php _e('Sale start date:', 'woocommerce'); ?> </label> <input type="text" class="sale_price_dates_from" name="variable_sale_price_dates_from[<?php echo $loop; ?> ]" value="<?php echo !empty($_sale_price_dates_from) ? date_i18n('Y-m-d', $_sale_price_dates_from) : ''; ?> " placeholder="<?php echo esc_attr_x('From…', 'placeholder', 'woocommerce'); ?> YYYY-MM-DD" maxlength="10" pattern="[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])" /> </p> <p class="form-row form-row-last"> <label><?php _e('Sale end date:', 'woocommerce'); ?> </label> <input type="text" class="sale_price_dates_to" name="variable_sale_price_dates_to[<?php echo $loop; ?> ]" value="<?php echo !empty($_sale_price_dates_to) ? date_i18n('Y-m-d', $_sale_price_dates_to) : ''; ?> " placeholder="<?php echo esc_attr_x('To…', 'placeholder', 'woocommerce'); ?> YYYY-MM-DD" maxlength="10" pattern="[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])" /> </p> </div> </div> <?php if ('yes' == get_option('woocommerce_manage_stock')) { ?> <div class="show_if_variation_manage_stock" style="display: none;"> <p class="form-row form-row-first"> <label><?php _e('Stock Qty:', 'woocommerce'); ?> <a class="tips" data-tip="<?php esc_attr_e('Enter a quantity to enable stock management at variation level, or leave blank to use the parent product\'s options.', 'woocommerce'); ?> " href="#">[?]</a></label> <input type="number" size="5" name="variable_stock[<?php echo $loop; ?> ]" value="<?php if (isset($_stock)) { echo esc_attr(wc_stock_amount($_stock)); } ?> " step="any" /> </p> <p class="form-row form-row-last"> <label><?php _e('Allow Backorders?', 'woocommerce'); ?> </label> <select name="variable_backorders[<?php echo $loop; ?> ]"> <?php foreach ($parent_data['backorder_options'] as $key => $value) { echo '<option value="' . esc_attr($key) . '" ' . selected($key === $_backorders, true, false) . '>' . esc_html($value) . '</option>'; } ?> </select> </p> </div> <?php } ?> <div class=""> <p class="form-row form-row-full"> <label><?php _e('Stock status', 'woocommerce'); ?> <a class="tips" data-tip="<?php esc_attr_e('Controls whether or not the product is listed as "in stock" or "out of stock" on the frontend.', 'woocommerce'); ?> " href="#">[?]</a></label> <select name="variable_stock_status[<?php echo $loop; ?> ]"> <?php foreach ($parent_data['stock_status_options'] as $key => $value) { echo '<option value="' . esc_attr($key === $_stock_status ? '' : $key) . '" ' . selected($key === $_stock_status, true, false) . '>' . esc_html($value) . '</option>'; } ?> </select> </p> </div> <?php if (wc_product_weight_enabled() || wc_product_dimensions_enabled()) { ?> <div> <?php if (wc_product_weight_enabled()) { ?> <p class="form-row hide_if_variation_virtual form-row-first"> <label><?php echo __('Weight', 'woocommerce') . ' (' . esc_html(get_option('woocommerce_weight_unit')) . '):'; ?> <a class="tips" data-tip="<?php esc_attr_e('Enter a weight for this variation or leave blank to use the parent product weight.', 'woocommerce'); ?> " href="#">[?]</a></label> <input type="text" size="5" name="variable_weight[<?php echo $loop; ?> ]" value="<?php if (isset($_weight)) { echo esc_attr($_weight); } ?> " placeholder="<?php echo esc_attr($parent_data['weight']); ?> " class="wc_input_decimal" /> </p> <?php } else { ?> <p> </p> <?php } ?> <?php if (wc_product_dimensions_enabled()) { ?> <p class="form-row dimensions_field hide_if_variation_virtual form-row-last"> <label for="product_length"><?php echo __('Dimensions (L×W×H)', 'woocommerce') . ' (' . esc_html(get_option('woocommerce_dimension_unit')) . '):'; ?> </label> <input id="product_length" class="input-text wc_input_decimal" size="6" type="text" name="variable_length[<?php echo $loop; ?> ]" value="<?php if (isset($_length)) { echo esc_attr($_length); } ?> " placeholder="<?php echo esc_attr($parent_data['length']); ?> " /> <input class="input-text wc_input_decimal" size="6" type="text" name="variable_width[<?php echo $loop; ?> ]" value="<?php if (isset($_width)) { echo esc_attr($_width); } ?> " placeholder="<?php echo esc_attr($parent_data['width']); ?> " /> <input class="input-text wc_input_decimal last" size="6" type="text" name="variable_height[<?php echo $loop; ?> ]" value="<?php if (isset($_height)) { echo esc_attr($_height); } ?> " placeholder="<?php echo esc_attr($parent_data['height']); ?> " /> </p> <?php } else { ?> <p> </p> <?php } ?> </div> <?php } ?> <div> <p class="form-row hide_if_variation_virtual form-row-full"><label><?php _e('Shipping class:', 'woocommerce'); ?> </label> <?php $args = array('taxonomy' => 'product_shipping_class', 'hide_empty' => 0, 'show_option_none' => __('Same as parent', 'woocommerce'), 'name' => 'variable_shipping_class[' . $loop . ']', 'id' => '', 'selected' => isset($shipping_class) ? esc_attr($shipping_class) : '', 'echo' => 0); echo wp_dropdown_categories($args); ?> </p> <?php if (wc_tax_enabled()) { ?> <p class="form-row form-row-full"> <label><?php _e('Tax class:', 'woocommerce'); ?> </label> <select name="variable_tax_class[<?php echo $loop; ?> ]"> <option value="parent" <?php selected(is_null($_tax_class), true); ?> ><?php _e('Same as parent', 'woocommerce'); ?> </option> <?php foreach ($parent_data['tax_class_options'] as $key => $value) { echo '<option value="' . esc_attr($key) . '" ' . selected($key === $_tax_class, true, false) . '>' . esc_html($value) . '</option>'; } ?> </select> </p> <?php } ?> <p class="form-row form-row-full"> <label><?php _e('Variation Description:', 'woocommerce'); ?> </label> <textarea name="variable_description[<?php echo $loop; ?> ]" rows="3" style="width:100%;"><?php echo isset($variation_data['_variation_description']) ? esc_textarea($variation_data['_variation_description']) : ''; ?> </textarea> </p> </div> <div class="show_if_variation_downloadable" style="display: none;"> <div class="form-row form-row-full downloadable_files"> <label><?php _e('Downloadable Files', 'woocommerce'); ?> :</label> <table class="widefat"> <thead> <div> <th><?php _e('Name', 'woocommerce'); ?> <span class="tips" data-tip="<?php esc_attr_e('This is the name of the download shown to the customer.', 'woocommerce'); ?> ">[?]</span></th> <th colspan="2"><?php _e('File URL', 'woocommerce'); ?> <span class="tips" data-tip="<?php esc_attr_e('This is the URL or absolute path to the file which customers will get access to. URLs entered here should already be encoded.', 'woocommerce'); ?> ">[?]</span></th> <th> </th> </div> </thead> <tbody> <?php if ($_downloadable_files) { foreach ($_downloadable_files as $key => $file) { if (!is_array($file)) { $file = array('file' => $file, 'name' => ''); } include 'html-product-variation-download.php'; } } ?> </tbody> <tfoot> <div> <th colspan="4"> <a href="#" class="button insert" data-row="<?php $file = array('file' => '', 'name' => ''); ob_start(); include 'html-product-variation-download.php'; echo esc_attr(ob_get_clean()); ?> "><?php _e('Add File', 'woocommerce'); ?> </a> </th> </div> </tfoot> </table> </div> </div> <div class="show_if_variation_downloadable" style="display: none;"> <p class="form-row form-row-first"> <label><?php _e('Download Limit:', 'woocommerce'); ?> <a class="tips" data-tip="<?php esc_attr_e('Leave blank for unlimited re-downloads.', 'woocommerce'); ?> " href="#">[?]</a></label> <input type="number" size="5" name="variable_download_limit[<?php echo $loop; ?> ]" value="<?php if (isset($_download_limit)) { echo esc_attr($_download_limit); } ?> " placeholder="<?php esc_attr_e('Unlimited', 'woocommerce'); ?> " step="1" min="0" /> </p> <p class="form-row form-row-last"> <label><?php _e('Download Expiry:', 'woocommerce'); ?> <a class="tips" data-tip="<?php esc_attr_e('Enter the number of days before a download link expires, or leave blank.', 'woocommerce'); ?> " href="#">[?]</a></label> <input type="number" size="5" name="variable_download_expiry[<?php echo $loop; ?> ]" value="<?php if (isset($_download_expiry)) { echo esc_attr($_download_expiry); } ?> " placeholder="<?php esc_attr_e('Unlimited', 'woocommerce'); ?> " step="1" min="0" /> </p> </div> <?php do_action('woocommerce_product_after_variable_attributes', $loop, $variation_data, $variation); ?> </div> </div> </div> <?php }
/** * */ 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; }
include 'bulk-edit-pagination.php'; echo '<table class="widefat wp-list-table">'; echo '<thead>'; echo '<tr>'; echo '<th>Variation Name</th>'; echo '<th>Parent Product</th>'; echo '<th>Images</th>'; echo '<th> </th>'; echo '</tr>'; echo '</thead>'; echo '<tbody>'; $i = 0; while ($variations->have_posts()) { $variations->the_post(); $variation = new WC_Product_Variation(get_the_id()); $variationAtts = $variation->get_variation_attributes(); $images = get_post_meta(get_the_id(), 'variation_image_gallery', true); $parents = get_post_ancestors(get_the_id()); $parentId = $parents[0]; $parentEditUrl = admin_url('post.php?post=' . $parentId . '&action=edit'); $parentName = get_the_title($parentId); // List Variation Attributes $atts = ""; if (is_array($variationAtts) && !empty($variationAtts)) { $atts = '<ul class="variationAtts">'; foreach ($variationAtts as $attName => $variationAtt) { if ($variationAtt != "") { $atts .= '<li><em>' . $attName . '</em>: ' . $variationAtt . '</li>'; } } $atts .= '</ul>';
/** * Get the attributes for a product or product variation * * @since 2.1 * @param WC_Product|WC_Product_Variation $product * @return array */ private function get_attributes($product) { $attributes = array(); if ($product->is_type('variation')) { // variation attributes foreach ($product->get_variation_attributes() as $attribute_name => $attribute) { // taxonomy-based attributes are prefixed with `pa_`, otherwise simply `attribute_` $attributes[] = array('name' => ucwords(str_replace('attribute_', '', str_replace('pa_', '', $attribute_name))), 'option' => $attribute); } } else { foreach ($product->get_attributes() as $attribute) { $attributes[] = array('name' => ucwords(str_replace('pa_', '', $attribute['name'])), 'position' => $attribute['position'], 'visible' => (bool) $attribute['is_visible'], 'variation' => (bool) $attribute['is_variation'], 'options' => $this->get_attribute_options($product->get_id(), $attribute)); } } return $attributes; }
function process_bulk_order_form() { $prod_name = ''; if (isset($_POST['submit'])) { $prod_name = $_POST['wcbulkorderproduct']; $prod_quantity = $_POST['wcbulkorderquantity']; $prod_id = $_POST['wcbulkorderid']; print_r($_POST); $i = 0; foreach ($prod_id as $key => $value) { $ancestors = ''; $ancestors = get_post_ancestors($prod_id); $quantity = $_POST['wcbulkorderquantity'][$i]; $product_id = $value; $variation_id = ''; $attributes = ''; if ('product_variation' == get_post_type($product_id)) { $variation_id = $product_id; $product_id = wp_get_post_parent_id($variation_id); $product = new WC_Product_Variation($variation_id); $attributes = $product->get_variation_attributes(); $attributes = isset($attributes) ? $attributes : ''; } if (!empty($ancestors)) { global $woocommerce; $woocommerce->cart->add_to_cart($ancestors[0], $quantity, $variation_id, $attributes, null); ++$i; } else { global $woocommerce; $woocommerce->cart->add_to_cart($_POST['wcbulkorderid'][$i], $quantity, $variation_id, $attributes, null); ++$i; } } } }
/** * Get the attributes for a product or product variation * * @since 2.1 * @param WC_Product|WC_Product_Variation $product * @return array */ private function get_attributes($product) { $attributes = array(); if ($product->is_type('variation')) { // variation attributes foreach ($product->get_variation_attributes() as $attribute_name => $attribute) { // taxonomy-based attributes are prefixed with `pa_`, otherwise simply `attribute_` $attributes[] = array('name' => wc_attribute_label(str_replace('attribute_', '', $attribute_name)), 'slug' => str_replace('attribute_', '', str_replace('pa_', '', $attribute_name)), 'option' => $attribute); } } else { foreach ($product->get_attributes() as $attribute) { // taxonomy-based attributes are comma-separated, others are pipe (|) separated if ($attribute['is_taxonomy']) { $options = explode(',', $product->get_attribute($attribute['name'])); } else { $options = explode('|', $product->get_attribute($attribute['name'])); } $attributes[] = array('name' => wc_attribute_label($attribute['name']), 'slug' => str_replace('pa_', '', $attribute['name']), 'position' => (int) $attribute['position'], 'visible' => (bool) $attribute['is_visible'], 'variation' => (bool) $attribute['is_variation'], 'options' => array_map('trim', $options)); } } return $attributes; }
function bulk_order_product_search() { // Query for suggestions $term = $_REQUEST['term']; $category = !empty($_REQUEST['category']) ? explode(',', $_REQUEST['category']) : array(); $excluded_products = !empty($_REQUEST['excluded']) ? explode(',', $_REQUEST['excluded']) : array(); $included_products = !empty($_REQUEST['included']) ? explode(',', $_REQUEST['included']) : array(); $search_by = isset($this->options['search_by']) ? $this->options['search_by'] : '4'; $max_items = isset($this->options['max_items']) ? $this->options['max_items'] : '-1'; $excluded_products = apply_filters('wc_bulk_order_excluded_products', $excluded_products); $included_products = apply_filters('wc_bulk_order_included_products', $included_products); if (empty($term)) { die; } if (!empty($category)) { if (is_numeric($term)) { if ($search_by == 2 || $search_by == 4) { $products1 = array('post_type' => array('product', 'product_variation'), 'post_status' => array('publish'), 'posts_per_page' => $max_items, 'post__in' => array(0, $term), 'fields' => 'ids', 'tax_query' => array(array('taxonomy' => 'product_cat', 'field' => 'id', 'terms' => $category)), 'suppress_filters' => false, 'no_found_rows' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'cache_results' => false); $products2 = array('post_type' => array('product', 'product_variation'), 'post_status' => array('publish'), 'posts_per_page' => $max_items, 'post_parent' => $term, 'fields' => 'ids', 'tax_query' => array(array('taxonomy' => 'product_cat', 'field' => 'id', 'terms' => $category)), 'suppress_filters' => false, 'no_found_rows' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'cache_results' => false); } if ($search_by == 3 || $search_by == 4) { $products4 = array('post_type' => array('product', 'product_variation'), 'post_status' => array('publish'), 'posts_per_page' => $max_items, 's' => $term, 'fields' => 'ids', 'post__not_in' => $excluded_products, 'post__in' => $included_products, 'tax_query' => array(array('taxonomy' => 'product_cat', 'field' => 'id', 'terms' => $category)), 'suppress_filters' => false, 'no_found_rows' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'cache_results' => false); } if ($search_by == 1 || $search_by == 4) { $products3 = array('post_type' => array('product', 'product_variation'), 'post_status' => array('publish'), 'posts_per_page' => $max_items, 'meta_query' => array(array('key' => '_sku', 'value' => '^' . $term, 'compare' => 'REGEXP')), 'fields' => 'ids', 'post__not_in' => $excluded_products, 'post__in' => $included_products, 'tax_query' => array(array('taxonomy' => 'product_cat', 'field' => 'id', 'terms' => $category)), 'suppress_filters' => false, 'no_found_rows' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'cache_results' => false); } if ($search_by == 1) { $products = array_unique(array_merge(get_posts($products3))); } elseif ($search_by == 2) { $products = array_unique(array_merge(get_posts($products1), get_posts($products2))); } elseif ($search_by == 3) { $products = array_unique(array_merge(get_posts($products4))); } else { $products = array_unique(array_merge(get_posts($products1), get_posts($products2), get_posts($products3), get_posts($products4))); } } else { if ($search_by == 1 || $search_by == 4) { $products1 = array('post_type' => array('product', 'product_variation'), 'post_status' => array('publish'), 'posts_per_page' => $max_items, 'meta_query' => array(array('key' => '_sku', 'value' => '^' . $term, 'compare' => 'REGEXP')), 'fields' => 'ids', 'post__not_in' => $excluded_products, 'post__in' => $included_products, 'tax_query' => array(array('taxonomy' => 'product_cat', 'field' => 'id', 'terms' => $category)), 'suppress_filters' => false, 'no_found_rows' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'cache_results' => false); } if ($search_by == 3 || $search_by == 4) { $products2 = array('post_type' => array('product', 'product_variation'), 'post_status' => array('publish'), 'posts_per_page' => $max_items, 's' => $term, 'fields' => 'ids', 'post__not_in' => $excluded_products, 'post__in' => $included_products, 'tax_query' => array(array('taxonomy' => 'product_cat', 'field' => 'id', 'terms' => $category)), 'suppress_filters' => false, 'no_found_rows' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'cache_results' => false); } if ($search_by == 1) { $products = array_unique(array_merge(get_posts($products1))); } elseif ($search_by == 3) { $products = array_unique(array_merge(get_posts($products2))); } else { $products = array_unique(array_merge(get_posts($products1), get_posts($products2))); } } } else { if (is_numeric($term)) { if ($search_by == 2 || $search_by == 4) { $products1 = array('post_type' => array('product', 'product_variation'), 'post_status' => array('publish'), 'posts_per_page' => $max_items, 'post__in' => array(0, $term), 'fields' => 'ids', 'suppress_filters' => false, 'no_found_rows' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'cache_results' => false); $products2 = array('post_type' => array('product', 'product_variation'), 'post_status' => array('publish'), 'posts_per_page' => $max_items, 'post_parent' => $term, 'fields' => 'ids', 'suppress_filters' => false, 'no_found_rows' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'cache_results' => false); } if ($search_by == 3 || $search_by == 4) { $products4 = array('post_type' => array('product', 'product_variation'), 'post_status' => array('publish'), 'posts_per_page' => $max_items, 's' => $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); } if ($search_by == 1 || $search_by == 4) { $products3 = array('post_type' => array('product', 'product_variation'), 'post_status' => array('publish'), 'posts_per_page' => $max_items, 'meta_query' => array(array('key' => '_sku', 'value' => '^' . $term, 'compare' => 'REGEXP')), '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); } if ($search_by == 1) { $products = array_unique(array_merge(get_posts($products3))); } elseif ($search_by == 2) { $products = array_unique(array_merge(get_posts($products1), get_posts($products2))); } elseif ($search_by == 3) { $products = array_unique(array_merge(get_posts($products4))); } else { $products = array_unique(array_merge(get_posts($products1), get_posts($products2), get_posts($products3), get_posts($products4))); } } else { if ($search_by == 1 || $search_by == 4) { $products1 = array('post_type' => array('product', 'product_variation'), 'post_status' => array('publish'), 'posts_per_page' => $max_items, 'meta_query' => array(array('key' => '_sku', 'value' => '^' . $term, 'compare' => 'REGEXP')), '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); } if ($search_by == 3 || $search_by == 4) { $products2 = array('post_type' => array('product', 'product_variation'), 'post_status' => array('publish'), 'posts_per_page' => $max_items, 's' => $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); } if ($search_by == 1) { $products = array_unique(array_merge(get_posts($products1))); } elseif ($search_by == 3) { $products = array_unique(array_merge(get_posts($products2))); } else { $products = array_unique(array_merge(get_posts($products1), get_posts($products2))); } } } // JSON encode and echo // Initialise suggestions array global $post, $woocommerce, $product; $suggestions = ''; foreach ($products as $prod) { $hide_product = 'false'; $post_type = get_post_type($prod); $child_args = array('post_parent' => $prod, 'post_type' => 'product_variation'); $children = get_children($child_args); if ('product' == $post_type && empty($children)) { $product = wc_get_product($prod); $id = $product->id; $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; $sku = $product->get_sku(); $title = get_the_title($product->id); $title = html_entity_decode($title, ENT_COMPAT, 'UTF-8'); $img = wp_get_attachment_image_src(get_post_thumbnail_id($id), 'thumbnail'); $img = $img[0]; if (!empty($img)) { $img = $img; } else { $img = apply_filters('woocommerce_placeholder_img_src', WC_Bulk_Order_Form_Compatibility::WC()->plugin_url() . '/assets/images/placeholder.png'); } } elseif ('product' == $post_type && !empty($children)) { $hide_product = 'true'; } elseif ('product_variation' == $post_type) { $product = new WC_Product_Variation($prod); $parent = wc_get_product($prod); $id = $product->variation_id; $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; $sku = $product->get_sku(); $title = $product->get_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 = $value; $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 ($hide_product == 'false') { $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(); $switch_data = isset($this->options['search_format']) ? $this->options['search_format'] : '1'; $price = apply_filters('wc_bulk_order_form_price', $price, $product); switch ($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'] = apply_filters('wc_bulk_order_form_label', $label, $price, $title, $sku, $symbol); $suggestion['price'] = $price; $suggestion['symbol'] = $symbol; $suggestion['id'] = $id; $suggestion['imgsrc'] = $img; 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; }