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


PHP WC_Order::get_cart_tax方法代码示例

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


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

示例1: 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->id);
     $dp = wc_get_price_decimals();
     $order_data = array('id' => $order->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_order_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_total_shipping(), $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->payment_method, 'method_title' => $order->payment_method_title, 'paid' => isset($order->paid_date)), 'billing_address' => array('first_name' => $order->billing_first_name, 'last_name' => $order->billing_last_name, 'company' => $order->billing_company, 'address_1' => $order->billing_address_1, 'address_2' => $order->billing_address_2, 'city' => $order->billing_city, 'state' => $order->billing_state, 'postcode' => $order->billing_postcode, 'country' => $order->billing_country, 'email' => $order->billing_email, 'phone' => $order->billing_phone), 'shipping_address' => array('first_name' => $order->shipping_first_name, 'last_name' => $order->shipping_last_name, 'company' => $order->shipping_company, 'address_1' => $order->shipping_address_1, 'address_2' => $order->shipping_address_2, 'city' => $order->shipping_city, 'state' => $order->shipping_state, 'postcode' => $order->shipping_postcode, 'country' => $order->shipping_country), 'note' => $order->customer_note, 'customer_ip' => $order->customer_ip_address, 'customer_user_agent' => $order->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['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:jgcopple,项目名称:drgaryschwantz,代码行数:48,代码来源:class-wc-cli-order.php

示例2:

 /**
  * Test: get_cart_tax
  */
 function test_get_cart_tax()
 {
     $object = new WC_Order();
     $object->set_cart_tax(5);
     $this->assertEquals(5, $object->get_cart_tax());
 }
开发者ID:woocommerce,项目名称:woocommerce,代码行数:9,代码来源:crud.php

示例3: do_reference_transaction

 /**
  * Charge a payment against a reference token
  *
  * @link https://developer.paypal.com/docs/classic/express-checkout/integration-guide/ECReferenceTxns/#id094UM0DA0HS
  * @link https://developer.paypal.com/docs/classic/api/merchant/DoReferenceTransaction_API_Operation_NVP/
  *
  * @param string $reference_id the ID of a refrence object, e.g. billing agreement ID.
  * @param WC_Order $order order object
  * @param array $args {
  *     @type string 'payment_type'         (Optional) Specifies type of PayPal payment you require for the billing agreement. It is one of the following values. 'Any' or 'InstantOnly'. Echeck is not supported for DoReferenceTransaction requests.
  *     @type string 'payment_action'       How you want to obtain payment. It is one of the following values: 'Authorization' - this payment is a basic authorization subject to settlement with PayPal Authorization and Capture; or 'Sale' - This is a final sale for which you are requesting payment.
  *     @type string 'return_fraud_filters' (Optional) Flag to indicate whether you want the results returned by Fraud Management Filters. By default, you do not receive this information.
  * }
  * @since 2.0
  */
 public function do_reference_transaction($reference_id, $order, $args = array())
 {
     $defaults = array('amount' => $order->get_total(), 'payment_type' => 'Any', 'payment_action' => 'Sale', 'return_fraud_filters' => 1, 'notify_url' => WC()->api_request_url('WC_Gateway_Paypal'), 'invoice_number' => wcs_str_to_ascii(ltrim($order->get_order_number(), _x('#', 'hash before the order number', 'woocommerce-subscriptions'))), 'custom' => json_encode(array('order_id' => $order->id, 'order_key' => $order->order_key)));
     $args = wp_parse_args($args, $defaults);
     $this->set_method('DoReferenceTransaction');
     // set base params
     $this->add_parameters(array('REFERENCEID' => $reference_id, 'BUTTONSOURCE' => 'WooThemes_Cart', 'RETURNFMFDETAILS' => $args['return_fraud_filters'], 'AMT' => $order->get_total(), 'CURRENCYCODE' => $order->get_order_currency(), 'INVNUM' => $args['invoice_number'], 'PAYMENTACTION' => $args['payment_action'], 'NOTIFYURL' => $args['notify_url'], 'CUSTOM' => $args['custom']));
     $order_subtotal = $i = 0;
     $order_items = array();
     // add line items
     foreach ($order->get_items() as $item) {
         $order_items[] = array('NAME' => wcs_get_paypal_item_name($item['name']), 'AMT' => $order->get_item_subtotal($item), 'QTY' => !empty($item['qty']) ? absint($item['qty']) : 1);
         $order_subtotal += $item['line_total'];
     }
     // add fees
     foreach ($order->get_fees() as $fee) {
         $order_items[] = array('NAME' => wcs_get_paypal_item_name($fee['name']), 'AMT' => $fee['line_total'], 'QTY' => 1);
         $order_subtotal += $fee['line_total'];
     }
     // WC 2.3+, no after-tax discounts
     if ($order->get_total_discount() > 0) {
         $order_items[] = array('NAME' => __('Total Discount', 'woocommerce-subscriptions'), 'QTY' => 1, 'AMT' => -$order->get_total_discount());
     }
     if ($order->prices_include_tax) {
         $item_names = array();
         foreach ($order_items as $item) {
             $item_names[] = sprintf('%s x %s', $item['NAME'], $item['QTY']);
         }
         // add a single item for the entire order
         $this->add_line_item_parameters(array('NAME' => sprintf(__('%s - Order', 'woocommerce-subscriptions'), get_option('blogname')), 'DESC' => wcs_get_paypal_item_name(implode(', ', $item_names)), 'AMT' => $order_subtotal + $order->get_cart_tax(), 'QTY' => 1), 0);
         // add order-level parameters - do not send the TAXAMT due to rounding errors
         $this->add_payment_parameters(array('ITEMAMT' => $order_subtotal + $order->get_cart_tax(), 'SHIPPINGAMT' => $order->get_total_shipping() + $order->get_shipping_tax()));
     } else {
         // add individual order items
         foreach ($order_items as $item) {
             $this->add_line_item_parameters($item, $i++);
         }
         // add order-level parameters
         $this->add_payment_parameters(array('ITEMAMT' => $order_subtotal, 'SHIPPINGAMT' => $order->get_total_shipping(), 'TAXAMT' => $order->get_total_tax()));
     }
 }
开发者ID:ltdat287,项目名称:id.nhomdichvu,代码行数:56,代码来源:class-wcs-paypal-reference-transaction-api-request.php

示例4: array

                $term_list = wp_get_post_terms($product_id, 'product_cat', array('fields' => 'ids'));
                $cat_id = (int) $term_list[0];
                $category = get_term($cat_id, 'product_cat');
                $items[$i]['name'] = $item['name'];
                $items[$i]['quantity'] = $item['qty'];
                $items[$i]['sku'] = $product->get_sku();
                $items[$i]['price'] = $product->get_price();
                $items[$i]['category'] = $category->name;
                $product_variation_id = $item['variation_id'];
                // etc
                $i++;
            }
            $amount = $order->get_total();
            $affliation = 'Order ' . $order_id . ' details';
            $order_shipping_total = $order->get_total_shipping();
            $order_cart_tax = $order->get_cart_tax();
            //echo '<pre>'; print_r($order);
            // Transaction Data
            $trans = array('id' => $order_id, 'affiliation' => $affliation, 'revenue' => $amount, 'shipping' => $order_shipping_total, 'tax' => $order_cart_tax);
            // Function to return the JavaScript representation of a TransactionData object.
            function getTransactionJs(&$trans)
            {
                return <<<HTML
ga('ecommerce:addTransaction', {
  'id': '{$trans['id']}',
  'affiliation': '{$trans['affiliation']}',
  'revenue': '{$trans['revenue']}',
  'shipping': '{$trans['shipping']}',
  'tax': '{$trans['tax']}'
});
HTML;
开发者ID:WP-Panda,项目名称:allergenics,代码行数:31,代码来源:step4.php

示例5: sendCustomerInvoice


//.........这里部分代码省略.........
																				</tr>';
    }
    $invoice_mail_content .= '																		
																	</tbody>
																	<tfoot style="text-align: left;">
																		<tr>
																			<th scope="row" colspan="2">
																				<font align="left">Cart Subtotal:</font>
																			</th>
																			<td>
																				<font align="left">
																					<span class="amount">$' . sprintf('%0.2f', $wooCommerceOrderObject->get_subtotal()) . '</span>
																				</font>
																			</td>
																		</tr>';
    if ($wooCommerceOrderObject->get_total_discount() > 0.0) {
        $invoice_mail_content .= '<tr>
																			<th scope="row" colspan="2">
																				<font align="left">Discount:</font>
																			</th>
																			<td>
																				<font align="left">
																					<span class="amount">$' . sprintf('%0.2f', $wooCommerceOrderObject->get_total_discount()) . '</span>
																				</font>
																			</td>
																		</tr>';
    }
    $invoice_mail_content .= '<tr>
																			<th scope="row" colspan="2">
																				<font align="left">Tax:</font>
																			</th>
																			<td>
																				<font align="left">
																					<span class="amount">$' . sprintf('%0.2f', $wooCommerceOrderObject->get_cart_tax() + $wooCommerceOrderObject->get_shipping_tax()) . '</span>
																				</font>
																			</td>
																		</tr>
																		<tr>
																			<th scope="row" colspan="2">
																				<font align="left">Shipping:</font>
																			</th>
																			<td>
																				<font align="left">
																					<span class="amount">$' . $wooCommerceOrderObject->get_total_shipping() . '</span>&nbsp;<small>via ' . $wooCommerceOrderObject->get_shipping_method() . '</small>
																				</font>
																			</td>
																		</tr>
																		<tr>
																			<th scope="row" colspan="2">
																				<font align="left">Payment Method:</font>
																			</th>
																			<td>
																				<font align="left">' . $wooCommerceOrderObject->payment_method_title . '</font>
																			</td>
																		</tr>
																		<tr>
																			<th scope="row" colspan="2">
																				<font align="left">Order Total:</font>
																			</th>
																			<td>
																				<font align="left">
																					<span class="amount">$' . sprintf('%0.2f', $wooCommerceOrderObject->get_total()) . '</span>
																				</font>
																			</td>
																		</tr>
																	</tfoot>
开发者ID:quadranttech,项目名称:wp-plex,代码行数:67,代码来源:plexsupportforwoocommerce.php


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