/** * Print appointment details inside order items in the backend. * * @param $item_id */ public function afterOrderItemMeta($item_id) { $data = wc_get_order_item_meta($item_id, 'bookly'); if ($data) { $other_data = $this->getItemData(array(), array('bookly' => $data)); echo $other_data[0]['name'] . '<br/>' . nl2br($other_data[0]['value']); } }
function set($item_id, $values, $cart_item_key) { global $wpdb; global $DOPBSP; $reservation_data = $wpdb->get_row('SELECT * FROM ' . $DOPBSP->tables->woocommerce . ' WHERE variation_id=' . wc_get_order_item_meta($item_id, '_variation_id')); if ($reservation_data) { $reservation = json_decode($reservation_data->data); $reservation->currency = $reservation_data->currency; $reservation->item_id = $item_id; $calendar = $wpdb->get_row('SELECT * FROM ' . $DOPBSP->tables->calendars . ' WHERE id=' . $reservation_data->calendar_id); $settings = $wpdb->get_row('SELECT * FROM ' . $DOPBSP->tables->settings . ' WHERE calendar_id=' . $reservation_data->calendar_id); $DOPBSP->classes->translation->setTranslation($reservation_data->language, false); /* * Display details data. */ wc_add_order_item_meta($item_id, $DOPBSP->text('RESERVATIONS_RESERVATION_DETAILS_TITLE'), $this->getDetails($reservation, $calendar, $settings)); /* * Display extra data. */ if ($settings->extra != 0) { wc_add_order_item_meta($item_id, $DOPBSP->text('EXTRAS_FRONT_END_TITLE'), $this->getExtras($reservation, $settings)); } /* * Display discount data. */ if ($settings->discount != 0) { wc_add_order_item_meta($item_id, $DOPBSP->text('DISCOUNTS_FRONT_END_TITLE'), $this->getDiscount($reservation, $settings)); } } }
/** * Filter the document table row cells to add custom column data * * @param string $table_row_cells The table row cells. * @param string $type WC_PIP_Document type * @param string $item_id Item id * @param array $item Item data * @param \WC_Product $product Product object * @param \WC_Order $order Order object * @return array The filtered table row cells. */ function sv_wc_pip_document_table_row_cells($table_row_cells, $document_type, $item_id, $item, $product, $order) { // set custom column content for invoices if ('invoice' === $document_type) { $table_row_cells['warranty'] = wc_get_order_item_meta($item_id, '_warranty'); } elseif ('packing-list' === $document_type || 'pick-list' === $document_type) { // display the value of the `_warehouse_location` order meta if it exists $table_row_cells['warehouse_location'] = $order->warehouse_location; } return $table_row_cells; }
/** * @param $order_id */ public function process_items($order_id) { $order = new WC_Order($order_id); $items = $order->get_items(array('line_item')); // check general BooXtream conditions $accountkey = $this->settings->get_accountkey(); if (!is_null($accountkey)) { foreach ($items as $item_id => $item) { $downloadlinks = wc_get_order_item_meta($item_id, '_bx_downloadlinks', true); if (!is_array($downloadlinks) && 'yes' === get_post_meta($item['product_id'], '_bx_booxtreamable', true)) { $this->request_downloadlinks($item['product_id'], $order_id, $item_id); // use this for actual data } } } return null; }
/** * Create or update a line item * * @since 2.2 * @param \WC_Order $order * @param array $item line item data * @param string $action 'create' to add line item or 'update' to update it * @throws WC_API_Exception invalid data, server error */ protected function set_line_item($order, $item, $action) { $creating = 'create' === $action; // product is always required if (!isset($item['product_id'])) { throw new WC_API_Exception('woocommerce_api_invalid_product_id', __('Product ID is required', 'woocommerce'), 400); } // when updating, ensure product ID provided matches if ('update' === $action) { $item_product_id = wc_get_order_item_meta($item['id'], '_product_id'); $item_variation_id = wc_get_order_item_meta($item['id'], '_variation_id'); if ($item['product_id'] != $item_product_id && $item['product_id'] != $item_variation_id) { throw new WC_API_Exception('woocommerce_api_invalid_product_id', __('Product ID provided does not match this line item', 'woocommerce'), 400); } } $product = wc_get_product($item['product_id']); // must be a valid WC_Product if (!is_object($product)) { throw new WC_API_Exception('woocommerce_api_invalid_product', __('Product is invalid', 'woocommerce'), 400); } // quantity must be positive float if (isset($item['quantity']) && floatval($item['quantity']) <= 0) { throw new WC_API_Exception('woocommerce_api_invalid_product_quantity', __('Product quantity must be a positive float', 'woocommerce'), 400); } // quantity is required when creating if ($creating && !isset($item['quantity'])) { throw new WC_API_Exception('woocommerce_api_invalid_product_quantity', __('Product quantity is required', 'woocommerce'), 400); } $item_args = array(); // quantity if (isset($item['quantity'])) { $item_args['qty'] = $item['quantity']; } // variations must each have a key & value if (isset($item['variations']) && is_array($item['variations'])) { foreach ($item['variations'] as $key => $value) { if (!$key || !$value) { throw new WC_API_Exception('woocommerce_api_invalid_product_variation', __('The product variation is invalid', 'woocommerce'), 400); } } $item_args['variation'] = $item['variations']; } // total if (isset($item['total'])) { $item_args['totals']['total'] = floatval($item['total']); } // total tax if (isset($item['total_tax'])) { $item_args['totals']['tax'] = floatval($item['total_tax']); } // subtotal if (isset($item['subtotal'])) { $item_args['totals']['subtotal'] = floatval($item['subtotal']); } // subtotal tax if (isset($item['subtotal_tax'])) { $item_args['totals']['subtotal_tax'] = floatval($item['subtotal_tax']); } if ($creating) { $item_id = $order->add_product($product, $item_args['qty'], $item_args); if (!$item_id) { throw new WC_API_Exception('woocommerce_cannot_create_line_item', __('Cannot create line item, try again', 'woocommerce'), 500); } } else { $item_id = $order->update_product($item['id'], $product, $item_args); if (!$item_id) { throw new WC_API_Exception('woocommerce_cannot_update_line_item', __('Cannot update line item, try again', 'woocommerce'), 500); } } }
/** * Custom Title In Order View Page * @since 1.0 */ public function custom_order_details_page_info($order) { $is_donation = wc_get_order_item_meta($order->id, '_is_donation'); if ($is_donation === true) { echo '<p><strong>' . get_option('wc_quick_donation_project_section_title') . ' :</strong>' . wc_get_order_item_meta($order->id, '_project_details') . '</p>'; } }
/** * @param $item_id * @return array */ public function get_packages_for_order_item($item_id) { return wc_get_order_item_meta($item_id, '_fraktguiden_packages', true); }
/** * * Update order item product when changing booking dates * * @param int $order_id * @param array $posted - Order content * **/ public function easy_booking_update_order_product($order_id, $posted) { $order = new WC_Order($order_id); $items = $order->get_items(); if ($items) { foreach ($items as $item_id => $item) { $product = $order->get_product_from_item($item); if (!$product) { continue; } $start = wc_get_order_item_meta($item_id, '_ebs_start_format'); $end = wc_get_order_item_meta($item_id, '_ebs_end_format'); $product_id = wc_get_order_item_meta($item_id, '_product_id'); $variation_id = wc_get_order_item_meta($item_id, '_variation_id'); $id = empty($variation_id) ? $product_id : $variation_id; // Is product bookable ? $is_bookable = get_post_meta($id, '_booking_option', true); if (!empty($start) && !empty($end) || isset($is_bookable) && $is_bookable === 'yes') { if (class_exists('WC_Session')) { $session_data = WC()->session->get_session_data(); $order_booking_session = !empty($session_data['order_booking_' . $item_id]) ? WC()->session->get('order_booking_' . $item_id) : ''; } else { $order_booking_session = ''; } $item_tax_class = $posted['order_item_tax_class'][$item_id]; $order_item['quantity'] = wc_get_order_item_meta($item_id, '_qty'); if (!empty($order_booking_session)) { $start = $order_booking_session['start']; $end = $order_booking_session['end']; $start_date = $order_booking_session['start_date']; $end_date = $order_booking_session['end_date']; if ($order_booking_session['new_price']) { $new_price = $order_booking_session['new_price']; $subtotal_price = $new_price['subtotal']; $total_price = $new_price['total']; } if (!empty($item_tax_class)) { $tax_subtotal = isset($new_price['tax_subtotal']) ? $new_price['tax_subtotal'] : ''; $tax_total = isset($new_price['tax_total']) ? $new_price['tax_total'] : ''; } wc_update_order_item_meta($item_id, '_ebs_start_format', $start); wc_update_order_item_meta($item_id, '_ebs_end_format', $end); wc_update_order_item_meta($item_id, '_ebs_start_display', $start_date); wc_update_order_item_meta($item_id, '_ebs_end_display', $end_date); WC()->session->set('order_booking_' . $item_id, ''); } else { $order_item['tax_class'] = $item_tax_class; $coupons = $order->get_used_coupons(); $item_prices = $this->easy_booking_get_booking_price($product, $item_id, $start, $end, $order_item, $coupons); if ($item_prices) { $subtotal_price = $item_prices['subtotal']; $total_price = $item_prices['total']; } if (!empty($item_tax_class)) { $tax_subtotal = isset($new_price['tax_subtotal']) ? $new_price['tax_subtotal'] : ''; $tax_total = isset($new_price['tax_total']) ? $new_price['tax_total'] : ''; } } // Update totals if (isset($subtotal_price)) { wc_update_order_item_meta($item_id, '_line_subtotal', wc_format_decimal($subtotal_price)); } if (isset($total_price)) { wc_update_order_item_meta($item_id, '_line_total', wc_format_decimal($total_price)); } if (!empty($tax_subtotal)) { wc_update_order_item_meta($item_id, '_line_subtotal_tax', wc_format_decimal($tax_subtotal)); } if (!empty($tax_total)) { wc_update_order_item_meta($item_id, '_line_tax', wc_format_decimal($tax_total)); } if (!empty($tax_subtotal) && !empty($tax_total)) { wc_update_order_item_meta($item_id, '_line_tax_data', array('total' => $tax_total, 'subtotal' => $tax_subtotal)); } do_action('easy_booking_update_order_product', $order, $item_id, $order_item); } } } }
/** * Create or update a line item * * @since 2.2 * @param \WC_Order $order * @param array $item line item data * @param string $action 'create' to add line item or 'update' to update it * @throws WC_API_Exception invalid data, server error */ protected function set_line_item($order, $item, $action) { $creating = 'create' === $action; // product is always required if (!isset($item['product_id']) && !isset($item['sku'])) { throw new WC_API_Exception('woocommerce_api_invalid_product_id', __('Product ID or SKU is required', 'woocommerce'), 400); } // when updating, ensure product ID provided matches if ('update' === $action) { $item_product_id = wc_get_order_item_meta($item['id'], '_product_id'); $item_variation_id = wc_get_order_item_meta($item['id'], '_variation_id'); if ($item['product_id'] != $item_product_id && $item['product_id'] != $item_variation_id) { throw new WC_API_Exception('woocommerce_api_invalid_product_id', __('Product ID provided does not match this line item', 'woocommerce'), 400); } } if (isset($item['product_id'])) { $product_id = $item['product_id']; } elseif (isset($item['sku'])) { $product_id = wc_get_product_id_by_sku($item['sku']); } // variations must each have a key & value $variation_id = 0; if (isset($item['variations']) && is_array($item['variations'])) { foreach ($item['variations'] as $key => $value) { if (!$key || !$value) { throw new WC_API_Exception('woocommerce_api_invalid_product_variation', __('The product variation is invalid', 'woocommerce'), 400); } } $variation_id = $this->get_variation_id(wc_get_product($product_id), $item['variations']); } $product = wc_get_product($variation_id ? $variation_id : $product_id); // must be a valid WC_Product if (!is_object($product)) { throw new WC_API_Exception('woocommerce_api_invalid_product', __('Product is invalid', 'woocommerce'), 400); } // quantity must be positive float if (isset($item['quantity']) && floatval($item['quantity']) <= 0) { throw new WC_API_Exception('woocommerce_api_invalid_product_quantity', __('Product quantity must be a positive float', 'woocommerce'), 400); } // quantity is required when creating if ($creating && !isset($item['quantity'])) { throw new WC_API_Exception('woocommerce_api_invalid_product_quantity', __('Product quantity is required', 'woocommerce'), 400); } if ($creating) { $item = new WC_Order_Item_Product(); } else { $item = new WC_Order_Item_Product($item['id']); } $item->set_product($product); $item->set_order_id($order->id); if (isset($item['quantity'])) { $item->set_quantity($item['quantity']); } if (isset($item['total'])) { $item->set_total(floatval($item['total'])); } if (isset($item['total_tax'])) { $item->set_total_tax(floatval($item['total_tax'])); } if (isset($item['subtotal'])) { $item->set_subtotal(floatval($item['subtotal'])); } if (isset($item['subtotal_tax'])) { $item->set_subtotal_tax(floatval($item['subtotal_tax'])); } if ($variation_id) { $item->set_variation_id($variation_id); $item->set_variation($item['variations']); } $item_id = $item->save(); if (!$item_id) { throw new WC_API_Exception('woocommerce_cannot_create_line_item', __('Cannot create line item, try again', 'woocommerce'), 500); } }
/** * Change commission label value * * @param $attribute_label The Label Value * @param $meta_key The Meta Key value * @param bool|\The $product The Product object * * @return string The label value */ public function commissions_attribute_label($attribute_label, $meta_key, $product = false) { global $pagenow; if ($product && 'post.php' == $pagenow && isset($_GET['post']) && ($order = wc_get_order($_GET['post']))) { $line_items = $order->get_items('line_item'); $item_meta_key = wp_get_post_parent_id($order->id) ? '_commission_id' : '_child__commission_id'; foreach ($line_items as $line_item_id => $line_item) { if ($line_item['product_id'] == $product->id) { $commission_id = wc_get_order_item_meta($line_item_id, $item_meta_key, true); $admin_url = YITH_Commission($commission_id)->get_view_url('admin'); $attribute_label = $item_meta_key == $meta_key ? sprintf("<a href='%s' class='%s'>" . __('commission_id', 'yith_wc_product_vendors') . '</a>', $admin_url, 'commission-id-label') : $attribute_label; } } } return $attribute_label; }
function generate_commission_data() { global $wpdb; $user_id = get_current_user_id(); if (!isset($_POST['security']) || !wp_verify_nonce($_POST['security'], 'vibe_security') || !current_user_can('edit_posts')) { echo __('Security error', 'wplms-dashboard'); die; } if (function_exists('vibe_get_option')) { $instructor_commission = vibe_get_option('instructor_commission'); } if (!isset($instructor_commission) || !$instructor_commission) { $instructor_commission = 70; } $commissions = get_option('instructor_commissions'); $query = apply_filters('wplms_dashboard_courses_instructors', $wpdb->prepare("\n SELECT posts.ID as course_id\n FROM {$wpdb->posts} AS posts\n WHERE posts.post_type = 'course'\n AND posts.post_author = %d\n ", $user_id)); $instructor_courses = $wpdb->get_results($query, ARRAY_A); $total_commission = 0; $commision_array = array(); $course_product_map = array(); $daily_val = array(); if (count($instructor_courses)) { foreach ($instructor_courses as $key => $value) { $course_id = $value['course_id']; $pid = get_post_meta($course_id, 'vibe_product', true); if (is_numeric($pid)) { if (isset($commissions[$course_id][$user_id])) { $course_commission[$course_id] = $commissions[$course_id][$user_id]; } else { $course_commission[$value['course_id']] = $instructor_commission; } $product_ids[] = $pid; $course_product_map[$pid] = $course_id; } } if (!is_array($product_ids)) { die; } $product_id_string = implode(',', $product_ids); $item_meta_table = $wpdb->prefix . 'woocommerce_order_itemmeta'; $order_items_table = $wpdb->prefix . 'woocommerce_order_items'; // CALCULATED COMMISSIONS $product_sales = $wpdb->get_results("\n SELECT order_meta.meta_value as value,order_meta.order_item_id as item_id,MONTH(post_meta.meta_value) as date,order_items.order_id as order_id\n FROM {$item_meta_table} AS order_meta\n LEFT JOIN {$order_items_table} as order_items ON order_items.order_item_id = order_meta.order_item_id\n LEFT JOIN {$wpdb->postmeta} as post_meta ON post_meta.post_id = order_items.order_id\n WHERE order_meta.meta_key = 'commission{$user_id}'\n AND post_meta.meta_key = '_completed_date'\n ", ARRAY_A); $sales_pie = array(); $i = count($product_sales); if (is_array($product_sales) && $i) { foreach ($product_sales as $sale) { $pid = wc_get_order_item_meta($sale['item_id'], '_product_id', true); $ctitle = get_the_title($course_product_map[$pid]); $sales_pie[$course_product_map[$pid]] += $sale['value']; $val = $sale['value']; $order_ids[] = $sale['order_id']; $total_commission += $val; $daily_val[$sale['date']] += $val; } } $oquery = "SELECT order_meta.meta_value as value,order_meta.order_item_id as item_id,MONTH(post_meta.meta_value) as date,order_items.order_id as order_id\n FROM {$item_meta_table} AS order_meta\n LEFT JOIN {$order_items_table} as order_items ON order_items.order_item_id = order_meta.order_item_id\n LEFT JOIN {$wpdb->postmeta} as post_meta ON post_meta.post_id = order_items.order_id\n WHERE order_meta.meta_key = '_line_total'\n AND post_meta.meta_key = '_completed_date'\n AND order_meta.order_item_id IN (\n SELECT order_item_id\n FROM {$item_meta_table} as t\n WHERE t.meta_key = '_product_id'\n AND t.meta_value IN ({$product_id_string})\n )"; $order_id_string = ''; if (is_array($order_ids)) { $order_id_string = implode(',', $order_ids); $oquery .= "AND post_meta.post_id NOT IN ({$order_id_string})"; } // FOR UNCALCULATED COMMISSIONS $product_sales = $wpdb->get_results($oquery, ARRAY_A); $i = count($product_sales); if (is_array($product_sales) && $i) { foreach ($product_sales as $sale) { // echo $sale['date'].' => '. $sale['value'].' - '.$sale['order_id'].' | '; $pid = wc_get_order_item_meta($sale['item_id'], '_product_id', true); if (isset($course_commission[$course_product_map[$pid]]) && $course_commission[$course_product_map[$pid]]) { $commission_percentage = $course_commission[$course_product_map[$pid]]; } else { $commission_percentage = $instructor_commission; } $ctitle = get_the_title($course_product_map[$pid]); //.' - '.$course_product_map[$pid]; $val = round($sale['value'] * $commission_percentage / 100, 2); $sales_pie[$course_product_map[$pid]] += $val; $total_commission += $val; $daily_val[$sale['date']] += $val; } } if (is_array($daily_val)) { if (count($daily_val)) { ksort($daily_val); foreach ($daily_val as $key => $value) { $commission_array[$key] = array('date' => date('M', mktime(0, 0, 0, $key, 10)), 'sales' => $value); } } update_user_meta($user_id, 'commission_data', $commission_array); update_user_meta($user_id, 'sales_pie', $sales_pie); update_user_meta($user_id, 'total_commission', $total_commission); } // Commission Paid out calculation $flag = 0; $commission_recieved = array(); $commissions_paid = $wpdb->get_results($wpdb->prepare("\n SELECT meta_value,post_id FROM {$wpdb->postmeta} \n WHERE meta_key = %s\n ", 'vibe_instructor_commissions')); if (isset($commissions_paid) && is_Array($commissions_paid) && count($commissions_paid)) { foreach ($commissions_paid as $commission) { if (isset($commission->meta_value[$user_id]) && isset($commission->meta_value[$user_id]['commission'])) { $flag = 1; $commission->meta_value = unserialize($commission->meta_value); $date = $wpdb->get_var($wpdb->prepare("SELECT MONTH(post_date) FROM {$wpdb->posts} WHERE ID = %d", $commission->post_id)); $k = date('n', mktime(0, 0, 0, $date, 10)); $commission_recieved[$k] = array('date' => date('M', mktime(0, 0, 0, $date, 10)), 'commission' => $commission->meta_value[$user_id]['commission']); } } } if ($flag || !count($commission_recieved)) { update_user_meta($user_id, 'commission_recieved', $commission_recieved); } echo 1; die; } // End count courses _e('No courses found for Instructor', 'wplms-dashboard'); die; }
public static function compile_ticket_info_images($current, $oiid, $order_id) { // do not process this unless the ticket information has been loaded if (!is_object($current) || is_wp_error($current)) { return $current; } // create the list of pairs to calculate $pairs = array('image_id_left' => self::$options->{'qsot-ticket-image-shown'}, 'image_id_right' => self::$options->{'qsot-ticket-image-shown-right'}); // calculate each pair foreach ($pairs as $key => $setting) { switch ($setting) { default: case 'event': if (isset($current->event, $current->event->image_id)) { $current->{$key} = $current->event->image_id; } break; case 'product': $product = wc_get_product(wc_get_order_item_meta($oiid, '_product_id', true)); if (is_object($product)) { $current->{$key} = get_post_thumbnail_id($product->id); } break; case 'venue': if (isset($current->venue, $current->venue->image_id)) { $current->{$key} = $current->venue->image_id; } break; case 'none': $current->{$key} = 0; break; } } return $current; }
/** * Generate PDF for Voucher * * Handles to Generate PDF on run time when * user will execute the url which is sent to * user email with purchase receipt * * @package WooCommerce - PDF Vouchers * @since 1.0.0 */ function woo_vou_process_product_pdf($productid, $orderid, $item_id = '', $orderdvoucodes = array(), $pdf_args = array()) { $prefix = WOO_VOU_META_PREFIX; global $current_user, $woo_vou_model; //model class $model = $woo_vou_model; // If pdf argument is not array then make it array $pdf_args = !is_array($pdf_args) ? (array) $pdf_args : $pdf_args; // Taking voucher key if (!empty($pdf_args['pdf_vou_key'])) { $pdf_vou_key = $pdf_args['pdf_vou_key']; } else { $pdf_vou_key = isset($_GET['key']) ? $_GET['key'] : ''; } if (!empty($productid) && !empty($orderid)) { // Check product id & order id are not empty //get all voucher details from order meta $allorderdata = $model->woo_vou_get_all_ordered_data($orderid); // Creating order object for order details $woo_order = new WC_Order($orderid); $woo_order_details = $woo_order; $items = $woo_order_details->get_items(); foreach ($items as $key => $item) { $qty = $items[$key]['qty']; } // Getting product name $woo_product_details = $model->woo_vou_get_product_details($orderid, $items); // get product $product = wc_get_product($productid); // if product type is variable then $productid will contain variation id $variation_id = $productid; // check if product type is variable then we need to take parent id of variation id if ($product->is_type('variation') || $product->is_type('variable')) { // productid is variation id in case of variable product so we need to take actual product id $woo_variation = new WC_Product_Variation($productid); $productid = !empty($woo_variation->id) ? $woo_variation->id : $variation_id; } $product = wc_get_product($productid); $duree = get_the_terms($productid, 'pa_duree'); $args = array('post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => $productid); $attachments = get_posts($args); if ($attachments) { foreach ($attachments as $attachment) { $image = wp_get_attachment_image($attachment->ID, 'full'); } } // Getting order details $buyer_email = $woo_order_details->billing_email; $buyer_fname = $woo_order_details->billing_first_name; $buyer_lname = $woo_order_details->billing_last_name; $buyer_fullname = $buyer_fname . ' ' . $buyer_lname; $productname = isset($woo_product_details[$variation_id]) ? $woo_product_details[$variation_id]['product_name'] : ''; //Added in version 2.3.7 for sold indivdual bug $item_key = $item_id; if (empty($item_key)) { $item_key = isset($woo_product_details[$variation_id]) ? $woo_product_details[$variation_id]['item_key'] : ''; } $variation_data = $model->woo_vou_get_variation_data($woo_order, $item_key); $productname = $productname . $variation_data; //Get recipient fields $recipient_data = $model->woo_vou_get_recipient_data_using_item_key($woo_order, $item_key); $productprice = !empty($woo_product_details[$variation_id]['product_formated_price']) ? $woo_product_details[$variation_id]['product_formated_price'] : ''; //Get voucher codes $voucher_codes = wc_get_order_item_meta($item_id, $prefix . 'codes'); //get all voucher details from order meta $allvoucherdata = isset($allorderdata[$productid]) ? $allorderdata[$productid] : array(); //how to use the voucher details $howtouse = isset($allvoucherdata['redeem']) ? $allvoucherdata['redeem'] : ''; //start date $start_date = isset($allvoucherdata['start_date']) ? $allvoucherdata['start_date'] : ''; //expiry data $exp_date = isset($allvoucherdata['exp_date']) ? $allvoucherdata['exp_date'] : ''; //vou order date $orderdate = get_the_time('Y-m-d', $orderid); if (!empty($orderdate)) { $orderdate = $model->woo_vou_get_date_format($orderdate); } //vou logo $voulogo = isset($allvoucherdata['vendor_logo']) ? $allvoucherdata['vendor_logo'] : ''; $voulogo = isset($voulogo['src']) && !empty($voulogo['src']) ? $voulogo['src'] : ''; //vendor logo $voulogohtml = ''; if (!empty($voulogo)) { $voulogohtml = '<img src="' . $voulogo . '" alt="" />'; } //site logo $vousitelogohtml = ''; $vou_site_url = get_option('vou_site_logo'); if (!empty($vou_site_url)) { $vousitelogohtml = '<img src="' . $vou_site_url . '" alt="" />'; } //start date if (!empty($start_date)) { $start_date_time = $model->woo_vou_get_date_format($start_date, true); $start_date = $model->woo_vou_get_date_format($start_date); } else { $start_date = $start_date_time = __('No Start Date', 'woovoucher'); } //expiration date if (!empty($exp_date)) { $expiry_date = $model->woo_vou_get_date_format($exp_date); $expiry_date_time = $model->woo_vou_get_date_format($exp_date, true); } else { $expiry_date = $expiry_date_time = __('No Expiration', 'woovoucher'); } //website url $website = isset($allvoucherdata['website_url']) ? $allvoucherdata['website_url'] : ''; //vendor address $addressphone = isset($allvoucherdata['vendor_address']) ? $allvoucherdata['vendor_address'] : ''; //location where voucher is availble $locations = isset($allvoucherdata['avail_locations']) ? $allvoucherdata['avail_locations'] : ''; //vendor user $vendor_user = get_post_meta($productid, $prefix . 'vendor_user', true); //get vendor detail $vendor_detail = $model->woo_vou_get_vendor_detail($productid, $vendor_user); //pdf template $pdf_template_meta = $vendor_detail['pdf_template']; $voucodes = ''; //Get mutiple pdf option from order meta $multiple_pdf = empty($orderid) ? '' : get_post_meta($orderid, $prefix . 'multiple_pdf', true); if ($multiple_pdf == 'yes' && !empty($orderdvoucodes)) { //check is enable multiple pdf $key = $pdf_vou_key; $voucodes = $orderdvoucodes[$key]; } elseif (!empty($voucher_codes)) { $voucodes = trim($voucher_codes); } $recipientname = isset($recipient_data['recipient_name']) ? $recipient_data['recipient_name'] : ''; $recipientemail = isset($recipient_data['recipient_email']) ? $recipient_data['recipient_email'] : ''; $recipientmessage = isset($recipient_data['recipient_message']) ? $recipient_data['recipient_message'] : ''; $payment_method = isset($woo_order_details->payment_method_title) ? $woo_order_details->payment_method_title : ''; include WOO_VOU_DIR . '/includes/woo-vou-generate-order-pdf.php'; } }
public function handle_download($query) { //gets the global query var object global $wp_query; if ($wp_query->get('bx-download')) { $item_id = $wp_query->get('bx-item-id'); $download_id = $wp_query->get('bx-download-id'); $bx_links = wc_get_order_item_meta($item_id, '_bx_downloadlinks'); if (is_array($bx_links)) { if ($download_id === wc_get_order_item_meta($item_id, '_bx_epub_link')) { $link = $bx_links['epub']; } elseif ($download_id === wc_get_order_item_meta($item_id, '_bx_mobi_link')) { $link = $bx_links['mobi']; } header('Location: ' . $link); exit; } else { //gets the front page id set in options $page_id = get_option('woocommerce_download_processing_page_id'); if (false === $page_id) { echo '<h1>' . __('Your download is not ready yet', 'woocommerce_booxtream') . '</h1>'; echo '<p>' . __('We are currently processing your download, please try again in a few seconds', 'woocommerce_booxtream') . '</p>'; exit; } if (!$query->is_main_query()) { return; } $query->set('post_type', 'page'); $query->set('p', $page_id); //we remove the actions hooked on the '__after_loop' (post navigation) remove_all_actions('__after_loop'); return $query; } } }
/** * Adding Hooks * * Adding proper hoocks for the discount codes * * @package WooCommerce - PDF Vouchers * @since 2.3.1 */ public function woo_vou_my_pdf_vouchers_download_link($downloads = array()) { //get prefix $prefix = WOO_VOU_META_PREFIX; if (is_user_logged_in()) { //If user is logged in //Get user ID $user_id = get_current_user_id(); //Get User Order Arguments $args = array('numberposts' => -1, 'meta_key' => '_customer_user', 'meta_value' => $user_id, 'post_type' => WOO_VOU_MAIN_SHOP_POST_TYPE, 'post_status' => array('wc-completed'), 'meta_query' => array(array('key' => $prefix . 'meta_order_details', 'compare' => 'EXISTS'))); //user orders $user_orders = get_posts($args); if (!empty($user_orders)) { //If orders are not empty foreach ($user_orders as $user_order) { //Get order ID $order_id = isset($user_order->ID) ? $user_order->ID : ''; if (!empty($order_id)) { //Order it not empty global $vou_order; //Set global order ID $vou_order = $order_id; //Get cart details $cart_details = new Wc_Order($order_id); $order_items = $cart_details->get_items(); $order_date = isset($cart_details->order_date) ? $cart_details->order_date : ''; $order_date = date('d-m-y', strtotime($order_date)); if (!empty($order_items)) { // Check cart details are not empty foreach ($order_items as $item_id => $product_data) { //Get product from Item ( It is required otherwise multipdf voucher link not work ) $_product = apply_filters('woocommerce_order_item_product', $cart_details->get_product_from_item($product_data), $product_data); if (!$_product) { //If product deleted $download_file_data = array(); } else { //Get download files $download_file_data = $cart_details->get_item_downloads($product_data); } //Get voucher codes $codes = wc_get_order_item_meta($item_id, $prefix . 'codes'); if (!empty($download_file_data) && !empty($codes)) { //If download exist and code is not empty foreach ($download_file_data as $key => $download_file) { //check download key is voucher key or not $check_key = strpos($key, 'woo_vou_pdf_'); //get voucher number $voucher_number = str_replace('woo_vou_pdf_', '', $key); if (empty($voucher_number)) { //If empty voucher number $voucher_number = 1; } if (!empty($download_file) && $check_key !== false) { //Get download URL $download_url = $download_file['download_url']; //add arguments array $add_arguments = array('item_id' => $item_id); //PDF Download URL $download_url = add_query_arg($add_arguments, $download_url); //get product name $product_name = isset($_product->post->post_title) ? $_product->post->post_title : ''; //Download file arguments $download_args = array('download_url' => $download_url, 'download_name' => $product_name . ' - ' . $download_file['name'] . ' ' . $voucher_number . ' ( ' . $order_date . ' )', 'downloads_remaining' => ''); //append voucher download to downloads array $downloads[] = $download_args; } } } } } //reset global order ID $vou_order = 0; } } } } return $downloads; }
/** * Refund a transaction * * @param $order_id * @param $refund_id * * @return bool */ public function refund_transaction($order_id, $refund_id) { // Get the Taxamo transaction key $transaction_key = get_post_meta($order_id, 'taxamo_transaction_key', true); // Get refund $refund = wc_get_order($refund_id); // Get refund line items $refund_items = $refund->get_items(array('line_item', 'shipping')); // Check & loop if (count($refund_items) > 0) { foreach ($refund_items as $refund_item) { // Get the line key $line_key = wc_get_order_item_meta($refund_item['refunded_item_id'], self::OIM_LINE_KEY, true); // Only do the refund when the line item exists if ('' !== $line_key) { // Get correct amount $amount = abs(isset($refund_item['line_total']) ? $refund_item['line_total'] : (isset($refund_item['cost']) ? $refund_item['cost'] : 0)); // Only continue if amount > 0 if ($amount > 0) { // Create refund request $refund_request = new WC_TA_Request_Refund($transaction_key, $line_key, $amount); // Do the rquest $refund_request->do_request(); } } } } // Refund done return true; }
public function recalculate_order($order_id) { $order_currency = get_post_meta($order_id, '_order_currency', true); //lets avoid recalculation for order which is already in if ($order_currency == $this->default_currency or empty($order_currency)) { return; } //*** $currencies = $this->get_currencies(); $_woocs_order_rate = get_post_meta($order_id, '_woocs_order_rate', true); if (empty($_woocs_order_rate)) { $_woocs_order_rate = $currencies[$order_currency]['rate']; } //*** update_post_meta($order_id, '_woocs_order_currency', $this->default_currency); update_post_meta($order_id, '_order_currency', $this->default_currency); update_post_meta($order_id, '_woocs_order_base_currency', $this->default_currency); wc_update_order_item_meta($order_id, '_woocs_order_base_currency', $this->default_currency); update_post_meta($order_id, '_woocs_order_rate', 1); wc_update_order_item_meta($order_id, '_woocs_order_rate', 1); update_post_meta($order_id, '_woocs_order_currency_changed_mannualy', time()); wc_add_order_item_meta($order_id, '_woocs_order_currency_changed_mannualy', time(), true); //*** $_order_shipping = get_post_meta($order_id, '_order_shipping', true); update_post_meta($order_id, '_order_shipping', $this->back_convert($_order_shipping, $_woocs_order_rate)); $_order_total = get_post_meta($order_id, '_order_total', true); update_post_meta($order_id, '_order_total', $this->back_convert($_order_total, $_woocs_order_rate)); $_refund_amount = get_post_meta($order_id, '_refund_amount', true); update_post_meta($order_id, '_refund_amount', $this->back_convert($_refund_amount, $_woocs_order_rate)); $_cart_discount_tax = get_post_meta($order_id, '_cart_discount_tax', true); update_post_meta($order_id, '_cart_discount_tax', $this->back_convert($_cart_discount_tax, $_woocs_order_rate)); $_order_tax = get_post_meta($order_id, '_order_tax', true); update_post_meta($order_id, '_order_tax', $this->back_convert($_order_tax, $_woocs_order_rate)); $_order_shipping_tax = get_post_meta($order_id, '_order_shipping_tax', true); update_post_meta($order_id, '_order_shipping_tax', $this->back_convert($_order_shipping_tax, $_woocs_order_rate)); $_cart_discount = get_post_meta($order_id, '_cart_discount', true); update_post_meta($order_id, '_cart_discount', $this->back_convert($_cart_discount, $_woocs_order_rate)); //*** global $wpdb; $get_items_sql = $wpdb->prepare("SELECT order_item_id,order_item_type FROM {$wpdb->prefix}woocommerce_order_items WHERE order_id = %d ", $order_id); $line_items = $wpdb->get_results($get_items_sql, ARRAY_N); if (!empty($line_items) and is_array($line_items)) { foreach ($line_items as $v) { $order_item_id = $v[0]; $order_item_type = $v[1]; switch ($order_item_type) { case 'line_item': $amount = wc_get_order_item_meta($order_item_id, '_line_subtotal', true); wc_update_order_item_meta($order_item_id, '_line_subtotal', $this->back_convert($amount, $_woocs_order_rate, 2)); $amount = wc_get_order_item_meta($order_item_id, '_line_total', true); wc_update_order_item_meta($order_item_id, '_line_total', $this->back_convert($amount, $_woocs_order_rate, 2)); $amount = wc_get_order_item_meta($order_item_id, '_line_subtotal_tax', true); wc_update_order_item_meta($order_item_id, '_line_subtotal_tax', $this->back_convert($amount, $_woocs_order_rate, 2)); $amount = wc_get_order_item_meta($order_item_id, '_line_tax', true); wc_update_order_item_meta($order_item_id, '_line_tax', $this->back_convert($amount, $_woocs_order_rate, 2)); $_line_tax_data = wc_get_order_item_meta($order_item_id, '_line_tax_data', true); if (!empty($_line_tax_data) and is_array($_line_tax_data)) { foreach ($_line_tax_data as $key => $values) { if (!empty($values)) { if (is_array($values)) { foreach ($values as $k => $value) { if (is_numeric($value)) { $_line_tax_data[$key][$k] = $this->back_convert($value, $_woocs_order_rate, 2); } } } else { if (is_numeric($values)) { $_line_tax_data[$key] = $this->back_convert($values, $_woocs_order_rate, 2); } } } } } wc_update_order_item_meta($order_item_id, '_line_tax_data', $_line_tax_data); break; case 'shipping': $amount = wc_get_order_item_meta($order_item_id, 'cost', true); wc_update_order_item_meta($order_item_id, 'cost', $this->back_convert($amount, $_woocs_order_rate, 2)); $taxes = wc_get_order_item_meta($order_item_id, 'taxes', true); if (!empty($taxes) and is_array($taxes)) { foreach ($taxes as $key => $values) { if (!empty($values)) { if (is_array($values)) { foreach ($values as $k => $value) { if (is_numeric($value)) { $taxes[$key][$k] = $this->back_convert($value, $_woocs_order_rate, 2); } } } else { if (is_numeric($values)) { $taxes[$key] = $this->back_convert($values, $_woocs_order_rate, 2); } } } } } wc_update_order_item_meta($order_item_id, 'taxes', $taxes); break; case 'tax': $amount = wc_get_order_item_meta($order_item_id, 'tax_amount', true); wc_update_order_item_meta($order_item_id, 'tax_amount', $this->back_convert($amount, $_woocs_order_rate, 3)); $amount = wc_get_order_item_meta($order_item_id, 'shipping_tax_amount', true); wc_update_order_item_meta($order_item_id, 'shipping_tax_amount', $this->back_convert($amount, $_woocs_order_rate, 2)); break; default: break; } } } //*** $order = new WC_Order($order_id); $refunds = $order->get_refunds(); if (!empty($refunds)) { foreach ($refunds as $refund) { $post_id = $refund->id; $amount = get_post_meta($post_id, '_refund_amount', true); update_post_meta($post_id, '_refund_amount', $this->back_convert($amount, $_woocs_order_rate, 2)); $amount = get_post_meta($post_id, '_order_total', true); update_post_meta($post_id, '_order_total', $this->back_convert($amount, $_woocs_order_rate, 2)); update_post_meta($post_id, '_order_currency', $this->default_currency); } } }
$_product = apply_filters('woocommerce_order_item_product', $cart_details->get_product_from_item($product_data), $product_data); if (!$_product) { //If product deleted $download_file_data = array(); } else { //Get download files $download_file_data = $cart_details->get_item_downloads($product_data); } //Get product ID $product_id = $product_data['product_id']; //get all voucher details from order meta $allvoucherdata = isset($allorderdata[$product_id]) ? $allorderdata[$product_id] : array(); //Get product item meta $product_item_meta = isset($product_data['item_meta']) ? $product_data['item_meta'] : array(); //Get voucher code from item meta "Now we store voucher codes in item meta fields" $codes_item_meta = wc_get_order_item_meta($item_id, $prefix . 'codes'); if (!empty($codes_item_meta)) { // Check Voucher Data are not empty ?> <tr> <td class="woo-vou-history-td"><img src="<?php echo $allvoucherdata['vendor_logo']['src']; ?> " alt="" width="70" height="30" /></td> <td class="woo-vou-history-td"><?php if (!empty($_product)) { echo '<a href="' . esc_url(admin_url('post.php?post=' . absint($product_id) . '&action=edit')) . '">' . $product_data['name'] . '</a>'; } else { echo $product_data['name']; }
public function recalculate_profit_callback() { $redirect = wp_get_referer() ? wp_get_referer() : admin_url('admin.php?page=wc-reports&tab=profit'); if (!isset($_REQUEST['token']) || !wp_verify_nonce($_REQUEST['token'], 'funkwoocost-recalculate-profit')) { wp_redirect(add_query_arg(array('status' => 'failed'), $redirect)); die; } global $wpdb; $order_items = $wpdb->get_results("\n SELECT order_items.order_item_id,\n meta_product_id.meta_value AS product_id,\n meta_variation_id.meta_value AS variation_id\n FROM {$wpdb->prefix}woocommerce_order_items AS order_items\n LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS meta_product_id ON order_items.order_item_id=meta_product_id.order_item_id AND meta_product_id.meta_key='_product_id'\n LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS meta_variation_id ON order_items.order_item_id=meta_variation_id.order_item_id AND meta_variation_id.meta_key='_variation_id'\n WHERE order_items.order_item_type='line_item'\n "); // echo "<pre>"; // print_r($order_items); // echo "</pre>"; // exit(); if (!empty($order_items)) { foreach ($order_items as $order_item) { $cost_of_good = !empty($order_item->variation_id) ? get_post_meta($order_item->variation_id, '_funkwoocost', true) : get_post_meta($order_item->product_id, '_funkwoocost', true); // echo $cost_of_good; exit(); $order_item_qty = wc_get_order_item_meta($order_item->order_item_id, '_qty', true); wc_update_order_item_meta($order_item->order_item_id, '_line_funkwoocost_order', wc_format_decimal($cost_of_good * $order_item_qty)); } } // clear transient delete_transient(strtolower('WooCost_Report_Profit_By_Date')); wp_redirect(add_query_arg(array('status' => 'success'), $redirect)); die; }
/** * Display the values for the listable columns * * @since 1.0 * @param string $column the column name */ public function render_column_content($column) { global $post, $wpdb; foreach (wc_checkout_add_ons()->get_add_ons($post->ID) as $add_on) { if ($column == $add_on->get_key()) { $query = $wpdb->prepare("\n\t\t\t\t\tSELECT\n\t\t\t\t\t\twoi.order_item_id\n\t\t\t\t\tFROM {$wpdb->prefix}woocommerce_order_itemmeta woim\n\t\t\t\t\tRIGHT JOIN {$wpdb->prefix}woocommerce_order_items woi ON woim.order_item_id = woi.order_item_id\n\t\t\t\t\tWHERE 1=1\n\t\t\t\t\t\tAND woi.order_id = %d\n\t\t\t\t\t\tAND woim.meta_key = '_wc_checkout_add_on_id'\n\t\t\t\t\t\tAND woim.meta_value = %d\n\t\t\t\t\t", $post->ID, $add_on->id); $item_id = $wpdb->get_var($query); if ($item_id) { switch ($add_on->type) { case 'checkbox': echo wc_get_order_item_meta($item_id, '_wc_checkout_add_on_value', true) ? '✓' : ''; break; case 'file': $file_ids = explode(',', wc_get_order_item_meta($item_id, '_wc_checkout_add_on_value', true)); $files_count = count($file_ids); $file_labels = array(); echo '<a href="#" class="wc-checkout-add-ons-files-toggle">' . sprintf(_n('%d file', '%d files', $files_count, WC_Checkout_Add_Ons::TEXT_DOMAIN), $files_count) . '</a>'; echo '<ul class="wc-checkout-add-ons-files">'; foreach ($file_ids as $key => $file_id) { if ($url = get_edit_post_link($file_id)) { echo '<li><a href="' . esc_url($url) . '">' . esc_html(get_the_title($file_id)) . '</a></li>'; } else { echo '<li>' . __('(File has been removed)', WC_Checkout_Add_Ons::TEXT_DOMAIN) . '</li>'; } } echo '</ul>'; break; case 'text': case 'textarea': $label = wc_get_order_item_meta($item_id, '_wc_checkout_add_on_label', true); echo $add_on->truncate_label($label); break; default: $label = wc_get_order_item_meta($item_id, '_wc_checkout_add_on_label', true); echo is_array($label) ? implode(', ', $label) : $label; } } break; } } }
function set_order_currency() { if (!wp_verify_nonce($_REQUEST['wcml_nonce'], 'set_order_currency')) { echo json_encode(array('error' => __('Invalid nonce', 'wpml-wcml'))); die; } setcookie('_wcml_order_currency', $_POST['currency'], time() + 86400, COOKIEPATH, COOKIE_DOMAIN); //update order items price if (isset($_POST['order_id'])) { global $wpdb, $woocommerce_wpml; $items = $wpdb->get_results($wpdb->prepare("SELECT order_item_id FROM {$wpdb->prefix}woocommerce_order_items WHERE order_id = '%d'", $_POST['order_id'])); $return = array(); $currencies = $woocommerce_wpml->multi_currency_support->get_currencies(); if (isset($currencies[$_POST['currency']])) { $currency_info = $currencies[$_POST['currency']]; $decimals_num = $currency_info['num_decimals']; $decimal_sep = $currency_info['decimal_sep']; $thousand_sep = $currency_info['thousand_sep']; } else { $decimals_num = get_option('woocommerce_price_num_decimals'); $decimal_sep = get_option('woocommerce_price_decimal_sep'); $thousand_sep = get_option('woocommerce_price_thousand_sep'); } foreach ($items as $item) { $line_subtotal = wc_get_order_item_meta($item->order_item_id, '_line_subtotal', true); $line_subtotal_tax = wc_get_order_item_meta($item->order_item_id, '_line_subtotal_tax', true); $line_total = wc_get_order_item_meta($item->order_item_id, '_line_total', true); $line_tax = wc_get_order_item_meta($item->order_item_id, '_line_tax', true); $order_item_id = wc_get_order_item_meta($item->order_item_id, '_variation_id', true); if (!$order_item_id) { $order_item_id = wc_get_order_item_meta($item->order_item_id, '_product_id', true); } if ($_POST['currency'] == get_option('woocommerce_currency')) { $custom_price = get_post_meta($order_item_id, '_price', true); } else { $custom_price = get_post_meta($order_item_id, '_price_' . $_POST['currency'], true); } if ($_POST['prev_currency'] != 'false') { if (!$custom_price) { $line_subtotal = $this->unconvert_price_amount($line_subtotal, $_POST['prev_currency'], $decimals_num, $decimal_sep, $thousand_sep); $line_total = $this->unconvert_price_amount($line_total, $_POST['prev_currency'], $decimals_num, $decimal_sep, $thousand_sep); } $line_subtotal_tax = $this->unconvert_price_amount($line_subtotal_tax, $_POST['prev_currency'], $decimals_num, $decimal_sep, $thousand_sep); $line_tax = $this->unconvert_price_amount($line_tax, $_POST['prev_currency'], $decimals_num, $decimal_sep, $thousand_sep); } if ($custom_price) { $line_subtotal = $custom_price; $line_total = $custom_price; } else { $line_subtotal = $this->apply_rounding_rules($this->convert_price_amount($line_subtotal, $_POST['currency'], $decimals_num, $decimal_sep, $thousand_sep), $_POST['currency']); $line_total = $this->apply_rounding_rules($this->convert_price_amount($line_total, $_POST['currency'], $decimals_num, $decimal_sep, $thousand_sep), $_POST['currency']); } wc_update_order_item_meta($item->order_item_id, '_line_subtotal', $line_subtotal); wc_update_order_item_meta($item->order_item_id, '_line_subtotal_tax', $this->convert_price_amount($line_subtotal_tax, $_POST['currency'], $decimals_num, $decimal_sep, $thousand_sep)); wc_update_order_item_meta($item->order_item_id, '_line_total', $line_total); wc_update_order_item_meta($item->order_item_id, '_line_tax', $this->convert_price_amount($line_tax, $_POST['currency'], $decimals_num, $decimal_sep, $thousand_sep)); $return['items'][$item->order_item_id]['line_subtotal'] = $line_subtotal; $return['items'][$item->order_item_id]['line_total'] = $line_total; $return['items'][$item->order_item_id]['display_total'] = $this->apply_currency_position($line_total, $_POST['currency']); } $shipp = (double) preg_replace('/[^0-9.]*/', '', $_POST['shipp']); $disc = $_POST['disc']; $total = $_POST['total']; $refund = (double) preg_replace('/[^0-9.]*/', '', $_POST['refund']); if ($_POST['prev_currency'] != 'false') { $shipp = $this->unconvert_price_amount($shipp, $_POST['prev_currency'], $decimals_num, $decimal_sep, $thousand_sep); $disc = $this->unconvert_price_amount($disc, $_POST['prev_currency'], $decimals_num, $decimal_sep, $thousand_sep); $total = $this->unconvert_price_amount($total, $_POST['prev_currency'], $decimals_num, $decimal_sep, $thousand_sep); $refund = $this->unconvert_price_amount($refund, $_POST['prev_currency'], $decimals_num, $decimal_sep, $thousand_sep); } $return['shipp'] = $this->apply_currency_position($this->apply_rounding_rules($this->convert_price_amount($shipp, $_POST['currency'], $decimals_num, $decimal_sep, $thousand_sep), $_POST['currency']), $_POST['currency']); $return['disc'] = $this->apply_rounding_rules($this->convert_price_amount($disc, $_POST['currency'], $decimals_num, $decimal_sep, $thousand_sep), $_POST['currency']); $return['disc_disp'] = $this->apply_currency_position($return['disc'], $_POST['currency']); $return['total'] = $this->apply_rounding_rules($this->convert_price_amount($total, $_POST['currency'], $decimals_num, $decimal_sep, $thousand_sep), $_POST['currency']); $return['total_disp'] = $this->apply_currency_position($return['total'], $_POST['currency']); $return['refund'] = $this->apply_currency_position($this->apply_rounding_rules($this->convert_price_amount($refund, $_POST['currency'], $decimals_num, $decimal_sep, $thousand_sep), $_POST['currency']), $_POST['currency']); echo json_encode($return); } die; }
/** * @param $line_items * @return mixed */ private function filter_qty($line_items) { foreach ($line_items as &$item) { $qty = wc_get_order_item_meta($item['id'], '_qty'); $item['quantity'] = wc_stock_amount($qty); } return $line_items; }
/** * Get rental order by month * @since 1.0.9 * */ function getOrderByYear() { global $wpdb; global $wp_query; $year = STInput::post('year', date('Y')); $item_post_type = STInput::post('item_post_type', ''); $_st_st_booking_post_type = STInput::post('_st_st_booking_post_type', ''); if ($item_post_type == '' or $_st_st_booking_post_type == '') { echo ''; die; } $sql = "SELECT DISTINCT " . $wpdb->posts . ".* FROM " . $wpdb->posts . " INNER JOIN " . $wpdb->postmeta . " ON " . $wpdb->posts . ".ID=" . $wpdb->postmeta . ".post_id\r\n INNER JOIN " . $wpdb->postmeta . " as mt1 ON mt1.post_id=" . $wpdb->posts . ".ID AND mt1.meta_key='item_post_type' AND mt1.meta_value='{$item_post_type}'\r\n INNER JOIN " . $wpdb->postmeta . " as mt2 ON mt2.post_id=" . $wpdb->posts . ".ID AND mt2.meta_key='check_in' AND YEAR(mt2.meta_value)='{$year}'\r\n INNER JOIN " . $wpdb->postmeta . " as mt3 ON mt3.post_id=" . $wpdb->posts . ".ID AND mt3.meta_key='check_out' AND YEAR(mt3.meta_value)='{$year}'\r\n WHERE " . $wpdb->posts . ".post_type='st_order'"; $posts = $wpdb->get_results($sql, OBJECT); $result = array(); if (is_array($posts) && count($posts)) { foreach ($posts as $post) { $start = date('Y/m/d', strtotime(get_post_meta($post->ID, 'check_in', 'true'))); $end = date('Y/m/d', strtotime(get_post_meta($post->ID, 'check_out', 'true'))); $result = array_merge($this->getListDate($start, $end), $result); } } $sql = "SELECT DISTINCT * FROM " . $wpdb->prefix . "woocommerce_order_items \r\n INNER JOIN " . $wpdb->prefix . "woocommerce_order_itemmeta \r\n ON " . $wpdb->prefix . "woocommerce_order_items.order_item_id = " . $wpdb->prefix . "woocommerce_order_itemmeta.order_item_id \r\n INNER JOIN " . $wpdb->prefix . "woocommerce_order_itemmeta as mt1 \r\n ON mt1.order_item_id = " . $wpdb->prefix . "woocommerce_order_items.order_item_id \r\n AND mt1.meta_key = '_st_st_booking_post_type' \r\n AND mt1.meta_value = '{$_st_st_booking_post_type}' \r\n INNER JOIN " . $wpdb->prefix . "woocommerce_order_itemmeta as mt2 \r\n ON mt2.order_item_id = " . $wpdb->prefix . "woocommerce_order_items.order_item_id \r\n AND mt2.meta_key = '_st_check_in' \r\n AND YEAR(DATE_FORMAT(STR_TO_DATE(mt2.meta_value, '%m/%d/%Y'), '%Y/%m/%d')) = '{$year}' \r\n INNER JOIN " . $wpdb->prefix . "woocommerce_order_itemmeta as mt3 \r\n ON mt3.order_item_id = " . $wpdb->prefix . "woocommerce_order_items.order_item_id \r\n AND mt3.meta_key = '_st_check_out' \r\n AND YEAR(DATE_FORMAT(STR_TO_DATE(mt2.meta_value, '%m/%d/%Y'), '%Y/%m/%d')) = '{$year}' \r\n GROUP BY " . $wpdb->prefix . "woocommerce_order_itemmeta.order_item_id"; $posts = $wpdb->get_results($sql); if (is_array($posts) && count($posts)) { foreach ($posts as $post) { $item = $post->order_item_id; $start = date('Y/m/d', strtotime(wc_get_order_item_meta($item, '_st_check_in'))); $end = date('Y/m/d', strtotime(wc_get_order_item_meta($item, '_st_check_out'))); $result = array_merge($this->getListDate($start, $end), $result); } } echo json_encode($result); die; }
/** * @deprecated */ function woocommerce_get_order_item_meta($item_id, $key, $single = true) { return wc_get_order_item_meta($item_id, $key, $single); }
/** * Voucher Code Shortcode * Handles to replace the voucher code in purchase note * * @package WooCommerce - PDF Vouchers * @since 1.6 */ function woo_vou_codes_replace($atts, $content) { global $woo_vou_order_item, $woo_vou_item_id; //Get prefix $prefix = WOO_VOU_META_PREFIX; // If order item is not empty if (!empty($woo_vou_order_item)) { //Get voucher codes $codes = wc_get_order_item_meta($woo_vou_item_id, $prefix . 'codes'); $content .= $codes; } return $content; }
/** * WCMp Calculate shipping for order * * @support flat rate per item * @param int $order_id * @param object $order_posted * @return void */ function wcmp_checkout_order_processed($order_id, $order_posted) { global $wpdb, $WCMp; $order = new WC_Order($order_id); if ($order->has_shipping_method('flat_rate')) { $woocommerce_flat_rate_settings = get_option('woocommerce_flat_rate_settings'); $line_items = $order->get_items('line_item'); if ($woocommerce_flat_rate_settings['enabled'] == 'yes') { if (version_compare(WC_VERSION, '2.5.0', '>=')) { if ($woocommerce_flat_rate_settings['type'] == 'class') { if (!empty($line_items)) { foreach ($line_items as $item_id => $item) { $wc_flat_rate = new WC_Shipping_Flat_Rate(); $product = $order->get_product_from_item($item); $shipping_class = $product->get_shipping_class_id(); $class_cost_string = $shipping_class ? $wc_flat_rate->get_option('class_cost_' . $shipping_class, '') : $wc_flat_rate->get_option('no_class_cost', ''); $cost_item_id = $this->evaluate_flat_shipping_cost($class_cost_string, array('qty' => $item['qty'], 'cost' => $order->get_line_subtotal($item))); $flat_shipping_per_item_val = wc_get_order_item_meta($item_id, 'flat_shipping_per_item', true); if (!$flat_shipping_per_item_val) { wc_add_order_item_meta($item_id, 'flat_shipping_per_item', round($cost_item_id, 2)); } } } } } else { if (version_compare(WC_VERSION, '2.4.0', '>')) { if ($woocommerce_flat_rate_settings['type'] == 'class') { if (!empty($line_items)) { foreach ($line_items as $item_id => $item) { $wc_flat_rate = new WC_Shipping_Flat_Rate(); $product = $order->get_product_from_item($item); $shipping_class = $product->get_shipping_class(); $class_cost_string = $shipping_class ? $wc_flat_rate->get_option('class_cost_' . $shipping_class, '') : $wc_flat_rate->get_option('no_class_cost', ''); $cost_item_id = $this->evaluate_flat_shipping_cost($class_cost_string, array('qty' => $item['qty'], 'cost' => $order->get_line_subtotal($item))); $flat_shipping_per_item_val = wc_get_order_item_meta($item_id, 'flat_shipping_per_item', true); if (!$flat_shipping_per_item_val) { wc_add_order_item_meta($item_id, 'flat_shipping_per_item', round($cost_item_id, 2)); } } } } } else { $woocommerce_flat_rate_settings_cost = $woocommerce_flat_rate_settings['cost']; $woocommerce_flat_rate_settings_fee = $woocommerce_flat_rate_settings['fee']; $woocommerce_flat_rates = get_option('woocommerce_flat_rates'); if ($woocommerce_flat_rate_settings['type'] == 'item') { if (!empty($line_items)) { foreach ($line_items as $item_id => $item) { $fee = $cost = 0; $_product = $order->get_product_from_item($item); $shipping_class = $_product->get_shipping_class(); if (isset($woocommerce_flat_rates[$shipping_class])) { $cost = $woocommerce_flat_rates[$shipping_class]['cost']; $fee = $this->get_fee($woocommerce_flat_rates[$shipping_class]['fee'], $_product->get_price()); } elseif ($woocommerce_flat_rate_settings_cost !== '') { $cost = $woocommerce_flat_rate_settings_cost; $fee = $this->get_fee($woocommerce_flat_rate_settings_fee, $_product->get_price()); $matched = true; } $cost_item_id = ($cost + $fee) * $item['qty']; $flat_shipping_per_item_val = wc_get_order_item_meta($item_id, 'flat_shipping_per_item', true); if (!$flat_shipping_per_item_val) { wc_add_order_item_meta($item_id, 'flat_shipping_per_item', round($cost_item_id, 2)); } } } } } } } } if ($order->has_shipping_method('international_delivery')) { $woocommerce_international_delivery_settings = get_option('woocommerce_international_delivery_settings'); $line_items = $order->get_items('line_item'); if ($woocommerce_international_delivery_settings['enabled'] == 'yes') { if (version_compare(WC_VERSION, '2.5.0', '>=')) { if ($woocommerce_international_delivery_settings['type'] == 'class') { if (!empty($line_items)) { $item_id = false; foreach ($line_items as $item_id => $item) { $wc_international_flat_rate = new WC_Shipping_International_Delivery(); $product = $order->get_product_from_item($item); $shipping_class = $product->get_shipping_class_id(); $class_cost_string = $shipping_class ? $wc_international_flat_rate->get_option('class_cost_' . $shipping_class, '') : $wc_international_flat_rate->get_option('no_class_cost', ''); $cost_item_id = $this->evaluate_flat_shipping_cost($class_cost_string, array('qty' => $item['qty'], 'cost' => $order->get_line_subtotal($item))); $international_flat_shipping_per_item_val = wc_get_order_item_meta($item_id, 'international_flat_shipping_per_item', true); if (!$international_flat_shipping_per_item_val) { wc_add_order_item_meta($item_id, 'international_flat_shipping_per_item', $cost_item_id); } } } } } else { if (version_compare(WC_VERSION, '2.4.0', '>')) { if ($woocommerce_international_delivery_settings['type'] == 'class') { if (!empty($line_items)) { $item_id = false; foreach ($line_items as $item_id => $item) { $wc_international_flat_rate = new WC_Shipping_International_Delivery(); $product = $order->get_product_from_item($item); $shipping_class = $product->get_shipping_class(); $class_cost_string = $shipping_class ? $wc_international_flat_rate->get_option('class_cost_' . $shipping_class, '') : $wc_international_flat_rate->get_option('no_class_cost', ''); $cost_item_id = $this->evaluate_flat_shipping_cost($class_cost_string, array('qty' => $item['qty'], 'cost' => $order->get_line_subtotal($item))); $international_flat_shipping_per_item_val = wc_get_order_item_meta($item_id, 'international_flat_shipping_per_item', true); if (!$international_flat_shipping_per_item_val) { wc_add_order_item_meta($item_id, 'international_flat_shipping_per_item', $cost_item_id); } } } } } } } } $vendor_shipping_array = get_post_meta($order_id, 'dc_pv_shipped', true); $order = new WC_Order($order_id); $commission_array = array(); $mark_ship = 0; $items = $order->get_items('line_item'); foreach ($items as $order_item_id => $item) { $comm_pro_id = $product_id = $item['product_id']; $variation_id = $item['variation_id']; if ($variation_id) { $comm_pro_id = $variation_id; } if ($product_id) { $product_vendors = get_wcmp_product_vendors($product_id); if ($product_vendors) { if (isset($product_vendors->id) && is_array($vendor_shipping_array)) { if (in_array($product_vendors->id, $vendor_shipping_array)) { $mark_ship = 1; } } $insert_query = $wpdb->query($wpdb->prepare("INSERT INTO `{$wpdb->prefix}wcmp_vendor_orders` ( order_id, commission_id, vendor_id, shipping_status, order_item_id, product_id )\n\t\t\t\t\t\t\t\t\t\t\t\t\t VALUES\n\t\t\t\t\t\t\t\t\t\t\t\t\t ( %d, %d, %d, %s, %d, %d ) ON DUPLICATE KEY UPDATE `created` = now()", $order_id, 0, $product_vendors->id, $mark_ship, $order_item_id, $comm_pro_id)); } } } }
/** * Include free order add-on fee meta * * @since 1.0 * @param bool $excl_free true is free item meta should be excluded * @param int $item_id the item meta id * @return bool $excl_free */ public function include_free_order_add_on_fee_meta($excl_free, $item_id) { $excl_free = wc_get_order_item_meta($item_id, '_wc_checkout_add_on_id') ? false : $excl_free; return $excl_free; }
/** * Update shipping method for order * * Note this does not update the order total * * @since 2.2 * @param int $item_id * @param array $args * @return bool */ public function update_shipping($item_id, $args) { if (!$item_id) { return false; } // method title if (isset($args['method_title'])) { wc_update_order_item($item_id, array('order_item_name' => $args['method_title'])); } // method ID if (isset($args['method_id'])) { wc_update_order_item_meta($item_id, 'method_id', $args['method_id']); } // method cost if (isset($args['cost'])) { // Get old cost before updating $old_cost = wc_get_order_item_meta($item_id, 'cost'); // Update wc_update_order_item_meta($item_id, 'cost', wc_format_decimal($args['cost'])); // Update total $this->set_total($this->order_shipping - wc_format_decimal($old_cost) + wc_format_decimal($args['cost']), 'shipping'); } do_action('woocommerce_order_update_shipping', $this->id, $item_id, $args); return true; }
/** * Get Item Data From Voucher Code * * Handles to get voucher data using * voucher codes from order items * * @package WooCommerce - PDF Vouchers * @since 2.3.6 */ public function woo_vou_get_item_data_using_voucher_code($order_items, $voucode) { $prefix = WOO_VOU_META_PREFIX; //initilize item $return_item = array('item_id' => '', 'item_data' => array()); if (!empty($order_items)) { //if items are not empty foreach ($order_items as $item_id => $item) { $voucher_codes = wc_get_order_item_meta($item_id, $prefix . 'codes'); //vouchers data of pdf $voucher_codes = !empty($voucher_codes) ? explode(',', $voucher_codes) : array(); $voucher_codes = array_map('trim', $voucher_codes); $check_code = trim($voucode); if (in_array($check_code, $voucher_codes)) { $return_item['item_id'] = $item_id; $return_item['item_data'] = $item; break; } } } return apply_filters('woo_vou_get_item_data_using_voucher_code', $return_item, $order_items, $voucode); }
/** * Create or update a line item. * * @param WC_Order $order Order data. * @param array $item Line item data. * @param string $action 'create' to add line item or 'update' to update it. * @throws WC_REST_Exception Invalid data, server error. */ protected function set_line_item($order, $item, $action = 'create') { $creating = 'create' === $action; $item_args = array(); // Product is always required. if (empty($item['product_id']) && empty($item['sku']) && empty($item['variation_id'])) { throw new WC_REST_Exception('woocommerce_rest_required_product_reference', __('Product ID or SKU is required.', 'woocommerce'), 400); } if (!empty($item['sku'])) { $product_id = (int) wc_get_product_id_by_sku($item['sku']); } elseif (!empty($item['product_id']) && empty($item['variation_id'])) { $product_id = (int) $item['product_id']; } elseif (!empty($item['variation_id'])) { $product_id = (int) $item['variation_id']; } // When updating, ensure product ID provided matches. if ('update' === $action && !empty($item['id'])) { $item_product_id = (int) wc_get_order_item_meta($item['id'], '_product_id'); $item_variation_id = (int) wc_get_order_item_meta($item['id'], '_variation_id'); if ($product_id !== $item_product_id && $product_id !== $item_variation_id) { throw new WC_REST_Exception('woocommerce_rest_required_product_reference', __('Product ID or variation ID provided does not match this line item.', 'woocommerce'), 400); } } $product = wc_get_product($product_id); // Must be a valid WC_Product. if (!is_object($product)) { throw new WC_REST_Exception('woocommerce_rest_invalid_product', __('Product is invalid.', 'woocommerce'), 400); } // Quantity must be positive float. if (isset($item['quantity']) && 0 >= floatval($item['quantity'])) { throw new WC_REST_Exception('woocommerce_rest_invalid_product_quantity', __('Product quantity must be a positive float.', 'woocommerce'), 400); } // Quantity is required when creating. if ($creating && !isset($item['quantity'])) { throw new WC_REST_Exception('woocommerce_rest_invalid_product_quantity', __('Product quantity is required.', 'woocommerce'), 400); } // Get variation attributes. if (method_exists($product, 'get_variation_attributes')) { $item_args['variation'] = $product->get_variation_attributes(); } // Quantity. if (isset($item['quantity'])) { $item_args['qty'] = $item['quantity']; } // Total. if (isset($item['total'])) { $item_args['totals']['total'] = floatval($item['total']); } // Total tax. if (isset($item['total_tax'])) { $item_args['totals']['tax'] = floatval($item['total_tax']); } // Subtotal. if (isset($item['subtotal'])) { $item_args['totals']['subtotal'] = floatval($item['subtotal']); } // Subtotal tax. if (isset($item['subtotal_tax'])) { $item_args['totals']['subtotal_tax'] = floatval($item['subtotal_tax']); } if ($creating) { $item_id = $order->add_product($product, $item_args['qty'], $item_args); if (!$item_id) { throw new WC_REST_Exception('woocommerce_rest_cannot_create_line_item', __('Cannot create line item, try again.', 'woocommerce'), 500); } } else { $item_id = $order->update_product($item['id'], $product, $item_args); if (!$item_id) { throw new WC_REST_Exception('woocommerce_rest_cannot_update_line_item', __('Cannot update line item, try again.', 'woocommerce'), 500); } } }