当前位置: 首页>>代码示例>>PHP>>正文


PHP WC_Order::get_currency方法代码示例

本文整理汇总了PHP中WC_Order::get_currency方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Order::get_currency方法的具体用法?PHP WC_Order::get_currency怎么用?PHP WC_Order::get_currency使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WC_Order的用法示例。


在下文中一共展示了WC_Order::get_currency方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: create

 /**
  * Method to create a new order in the database.
  * @param WC_Order $order
  */
 public function create(&$order)
 {
     $order->set_version(WC_VERSION);
     $order->set_date_created(current_time('timestamp'));
     $order->set_currency($order->get_currency() ? $order->get_currency() : get_woocommerce_currency());
     $id = wp_insert_post(apply_filters('woocommerce_new_order_data', array('post_date' => date('Y-m-d H:i:s', $order->get_date_created('edit')), 'post_date_gmt' => get_gmt_from_date(date('Y-m-d H:i:s', $order->get_date_created('edit'))), 'post_type' => $order->get_type('edit'), 'post_status' => 'wc-' . ($order->get_status('edit') ? $order->get_status('edit') : apply_filters('woocommerce_default_order_status', 'pending')), 'ping_status' => 'closed', 'post_author' => 1, 'post_title' => $this->get_post_title(), 'post_password' => uniqid('order_'), 'post_parent' => $order->get_parent_id('edit'), 'post_excerpt' => $this->get_post_excerpt($order))), true);
     if ($id && !is_wp_error($id)) {
         $order->set_id($id);
         $this->update_post_meta($order, true);
         $order->save_meta_data();
         $order->apply_changes();
         $this->clear_caches($order);
     }
 }
开发者ID:shivapoudel,项目名称:woocommerce,代码行数:18,代码来源:abstract-wc-order-data-store-cpt.php

示例2:

 /**
  * Test: get_currency
  */
 function test_get_currency()
 {
     $object = new WC_Order();
     $set_to = 'USD';
     $object->set_currency($set_to);
     $this->assertEquals($set_to, $object->get_currency());
 }
开发者ID:woocommerce,项目名称:woocommerce,代码行数:10,代码来源:crud.php

示例3: get_refund_request

 /**
  * Get refund request args.
  * @param  WC_Order $order
  * @param  float    $amount
  * @param  string   $reason
  * @return array
  */
 public static function get_refund_request($order, $amount = null, $reason = '')
 {
     $request = array('VERSION' => '84.0', 'SIGNATURE' => self::$api_signature, 'USER' => self::$api_username, 'PWD' => self::$api_password, 'METHOD' => 'RefundTransaction', 'TRANSACTIONID' => $order->get_transaction_id(), 'NOTE' => html_entity_decode(wc_trim_string($reason, 255), ENT_NOQUOTES, 'UTF-8'), 'REFUNDTYPE' => 'Full');
     if (!is_null($amount)) {
         $request['AMT'] = number_format($amount, 2, '.', '');
         $request['CURRENCYCODE'] = $order->get_currency();
         $request['REFUNDTYPE'] = 'Partial';
     }
     return apply_filters('woocommerce_paypal_refund_request', $request, $order, $amount, $reason);
 }
开发者ID:pelmered,项目名称:woocommerce,代码行数:17,代码来源:class-wc-gateway-paypal-api-handler.php

示例4: number_format

 /**
  * Format prices.
  * @param  float|int $price
  * @param  WC_Order $order
  * @return string
  */
 protected function number_format($price, $order)
 {
     $decimals = 2;
     if (!$this->currency_has_decimals($order->get_currency())) {
         $decimals = 0;
     }
     return number_format($price, $decimals, '.', '');
 }
开发者ID:shivapoudel,项目名称:woocommerce,代码行数:14,代码来源:class-wc-gateway-paypal-request.php

示例5: validate_currency

 /**
  * Check currency from IPN matches the order.
  * @param WC_Order $order
  * @param string $currency
  */
 protected function validate_currency($order, $currency)
 {
     if ($order->get_currency() != $currency) {
         WC_Gateway_Paypal::log('Payment error: Currencies do not match (sent "' . $order->get_currency() . '" | returned "' . $currency . '")');
         // Put this order on-hold for manual checking.
         $order->update_status('on-hold', sprintf(__('Validation error: PayPal currencies do not match (code %s).', 'woocommerce'), $currency));
         exit;
     }
 }
开发者ID:tlovett1,项目名称:woocommerce,代码行数:14,代码来源:class-wc-gateway-paypal-ipn-handler.php

示例6: get_order_data

 /**
  * Get the order data for the given ID.
  *
  * @since  2.5.0
  * @param  WC_Order $order The order instance
  * @return array
  */
 protected function get_order_data($order)
 {
     $order_post = get_post($order->get_id());
     $dp = wc_get_price_decimals();
     $order_data = array('id' => $order->get_id(), 'order_number' => $order->get_order_number(), 'created_at' => $this->format_datetime($order_post->post_date_gmt), 'updated_at' => $this->format_datetime($order_post->post_modified_gmt), 'completed_at' => $this->format_datetime($order->completed_date, true), 'status' => $order->get_status(), 'currency' => $order->get_currency(), 'total' => wc_format_decimal($order->get_total(), $dp), 'subtotal' => wc_format_decimal($order->get_subtotal(), $dp), 'total_line_items_quantity' => $order->get_item_count(), 'total_tax' => wc_format_decimal($order->get_total_tax(), $dp), 'total_shipping' => wc_format_decimal($order->get_shipping_total(), $dp), 'cart_tax' => wc_format_decimal($order->get_cart_tax(), $dp), 'shipping_tax' => wc_format_decimal($order->get_shipping_tax(), $dp), 'total_discount' => wc_format_decimal($order->get_total_discount(), $dp), 'shipping_methods' => $order->get_shipping_method(), 'payment_details' => array('method_id' => $order->get_payment_method(), 'method_title' => $order->get_payment_method_title(), 'paid' => 0 < $order->get_date_paid()), 'billing_address' => array('first_name' => $order->get_billing_first_name(), 'last_name' => $order->get_billing_last_name(), 'company' => $order->get_billing_company(), 'address_1' => $order->get_billing_address_1(), 'address_2' => $order->get_billing_address_2(), 'city' => $order->get_billing_city(), 'state' => $order->get_billing_state(), 'postcode' => $order->get_billing_postcode(), 'country' => $order->get_billing_country(), 'email' => $order->get_billing_email(), 'phone' => $order->get_billing_phone()), 'shipping_address' => array('first_name' => $order->get_shipping_first_name(), 'last_name' => $order->get_shipping_last_name(), 'company' => $order->get_shipping_company(), 'address_1' => $order->get_shipping_address_1(), 'address_2' => $order->get_shipping_address_2(), 'city' => $order->get_shipping_city(), 'state' => $order->get_shipping_state(), 'postcode' => $order->get_shipping_postcode(), 'country' => $order->get_shipping_country()), 'note' => $order->get_customer_note(), 'customer_ip' => $order->get_customer_ip_address(), 'customer_user_agent' => $order->get_customer_user_agent(), 'customer_id' => $order->get_user_id(), 'view_order_url' => $order->get_view_order_url(), 'line_items' => array(), 'shipping_lines' => array(), 'tax_lines' => array(), 'fee_lines' => array(), 'coupon_lines' => array());
     // add line items
     foreach ($order->get_items() as $item_id => $item) {
         $product = $order->get_product_from_item($item);
         $product_id = null;
         $product_sku = null;
         // Check if the product exists.
         if (is_object($product)) {
             $product_id = isset($product->variation_id) ? $product->variation_id : $product->id;
             $product_sku = $product->get_sku();
         }
         $meta = new WC_Order_Item_Meta($item, $product);
         $item_meta = array();
         foreach ($meta->get_formatted(null) as $meta_key => $formatted_meta) {
             $item_meta[] = array('key' => $meta_key, 'label' => $formatted_meta['label'], 'value' => $formatted_meta['value']);
         }
         $order_data['line_items'][] = array('id' => $item_id, 'subtotal' => wc_format_decimal($order->get_line_subtotal($item, false, false), $dp), 'subtotal_tax' => wc_format_decimal($item['line_subtotal_tax'], $dp), 'total' => wc_format_decimal($order->get_line_total($item, false, false), $dp), 'total_tax' => wc_format_decimal($item['line_tax'], $dp), 'price' => wc_format_decimal($order->get_item_total($item, false, false), $dp), 'quantity' => wc_stock_amount($item['qty']), 'tax_class' => !empty($item['tax_class']) ? $item['tax_class'] : null, 'name' => $item->get_name(), 'product_id' => $product_id, 'sku' => $product_sku, 'meta' => $item_meta);
     }
     // Add shipping.
     foreach ($order->get_shipping_methods() as $shipping_item_id => $shipping_item) {
         $order_data['shipping_lines'][] = array('id' => $shipping_item_id, 'method_id' => $shipping_item['method_id'], 'method_title' => $shipping_item['name'], 'total' => wc_format_decimal($shipping_item['cost'], $dp));
     }
     // Add taxes.
     foreach ($order->get_tax_totals() as $tax_code => $tax) {
         $order_data['tax_lines'][] = array('id' => $tax->id, 'rate_id' => $tax->rate_id, 'code' => $tax_code, 'title' => $tax->label, 'total' => wc_format_decimal($tax->amount, $dp), 'compound' => (bool) $tax->is_compound);
     }
     // Add fees.
     foreach ($order->get_fees() as $fee_item_id => $fee_item) {
         $order_data['fee_lines'][] = array('id' => $fee_item_id, 'title' => $fee_item['name'], 'tax_class' => !empty($fee_item['tax_class']) ? $fee_item['tax_class'] : null, 'total' => wc_format_decimal($order->get_line_total($fee_item), $dp), 'total_tax' => wc_format_decimal($order->get_line_tax($fee_item), $dp));
     }
     // Add coupons.
     foreach ($order->get_items('coupon') as $coupon_item_id => $coupon_item) {
         $order_data['coupon_lines'][] = array('id' => $coupon_item_id, 'code' => $coupon_item['name'], 'amount' => wc_format_decimal($coupon_item['discount_amount'], $dp));
     }
     $order_data = apply_filters('woocommerce_cli_order_data', $order_data);
     return $this->flatten_array($order_data);
 }
开发者ID:pelmered,项目名称:woocommerce,代码行数:48,代码来源:class-wc-cli-order.php


注:本文中的WC_Order::get_currency方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。