本文整理汇总了PHP中WC_Order::get_taxes方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Order::get_taxes方法的具体用法?PHP WC_Order::get_taxes怎么用?PHP WC_Order::get_taxes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WC_Order
的用法示例。
在下文中一共展示了WC_Order::get_taxes方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_number_of_columns
/**
* Number of table columns that will be displayed
* @return int
*/
public function get_number_of_columns()
{
$number_of_columns = 4;
if ($this->template_options['bewpi_show_sku']) {
$number_of_columns++;
}
$order_taxes = $this->order->get_taxes();
if ($this->template_options['bewpi_show_tax'] && wc_tax_enabled() && empty($legacy_order) && !empty($order_taxes)) {
foreach ($order_taxes as $tax_id => $tax_item) {
$number_of_columns++;
}
}
return $number_of_columns;
}
示例2: array
/**
* Test: get_taxes
*/
function test_get_taxes()
{
global $wpdb;
update_option('woocommerce_calc_taxes', 'yes');
$tax_rate = array('tax_rate_country' => '', 'tax_rate_state' => '', 'tax_rate' => '10.0000', 'tax_rate_name' => 'TAX', 'tax_rate_priority' => '1', 'tax_rate_compound' => '0', 'tax_rate_shipping' => '1', 'tax_rate_order' => '1', 'tax_rate_class' => '');
WC_Tax::_insert_tax_rate($tax_rate);
$object = new WC_Order();
$item_1 = new WC_Order_Item_Product();
$item_1->set_props(array('product' => WC_Helper_Product::create_simple_product(), 'quantity' => 4));
$object->add_item($item_1);
$object->calculate_totals();
$this->assertCount(1, $object->get_taxes());
$item = new WC_Order_Item_Tax();
$item->set_rate(100);
$item->set_tax_total(100);
$item->set_shipping_tax_total(100);
$object->add_item($item);
$object->save();
$this->assertCount(2, $object->get_taxes());
// Cleanup
$wpdb->query("DELETE FROM {$wpdb->prefix}woocommerce_tax_rates");
$wpdb->query("DELETE FROM {$wpdb->prefix}woocommerce_tax_rate_locations");
update_option('woocommerce_calc_taxes', 'no');
}
示例3: linksync_OrderFromBackEnd
function linksync_OrderFromBackEnd()
{
//Ordered product(s)
global $wpdb;
$testMode = get_option('linksync_test');
$LAIDKey = get_option('linksync_laid');
$apicall = new linksync_class($LAIDKey, $testMode);
if ($_POST['order_status'] == get_option('order_status_wc_to_vend')) {
//Checking for already sent Order
$orderId = $_POST['ID'];
$sentOrderIds = get_option('linksync_sent_order_id');
if (isset($sentOrderIds)) {
if (!empty($sentOrderIds)) {
$order_id_array = unserialize($sentOrderIds);
} else {
$order_id_array = array();
}
if (!in_array($orderId, $order_id_array)) {
update_option('linksync_sent_order_id', serialize(array_merge($order_id_array, array($orderId))));
$total_quantity = 0;
$order = new WC_Order($orderId);
$order_no = $order->get_order_number();
if (strpos($order_no, '#') !== false) {
$order_no = str_replace('#', '', $order_no);
}
$get_total = $order->get_total();
$currency = $order->get_order_currency();
$order_total = $_POST['_order_total'];
$taxes_included = false;
$registerDb = get_option('wc_to_vend_register');
$vend_user_detail = get_option('wc_to_vend_user');
if (isset($vend_user_detail) && !empty($vend_user_detail)) {
$user = explode('|', $vend_user_detail);
$vend_uid = isset($user[0]) ? $user[0] : null;
$vend_username = isset($user[1]) ? $user[1] : null;
}
//Ordered product(s)
$items = $order->get_items();
$taxes = $order->get_taxes();
foreach ($items as $item) {
foreach ($taxes as $tax_label) {
$sql = mysql_query("SELECT tax_rate_id FROM `" . $wpdb->prefix . "woocommerce_tax_rates` WHERE tax_rate_name='" . $tax_label['label'] . "' AND tax_rate_class='" . $item['item_meta']['_tax_class'][0] . "'");
if (mysql_num_rows($sql) != 0) {
$tax_classes = linksync_tax_classes($tax_label['label'], $item['item_meta']['_tax_class'][0]);
if ($tax_classes['result'] == 'success') {
$vend_taxes = explode('/', $tax_classes['tax_classes']);
}
}
}
$taxId = isset($vend_taxes[0]) ? $vend_taxes[0] : null;
$taxName = isset($vend_taxes[1]) ? $vend_taxes[1] : null;
$taxRate = isset($vend_taxes[2]) ? $vend_taxes[2] : null;
if (isset($item['variation_id']) && !empty($item['variation_id'])) {
$product_id = $item['variation_id'];
} else {
$product_id = $item['product_id'];
}
$pro_object = new WC_Product($product_id);
$itemtotal = (double) $item['item_meta']['_line_subtotal'][0];
if (isset($item['line_subtotal']) && !empty($item['line_subtotal'])) {
$product_amount = (double) ($item['line_subtotal'] / $item['qty']);
}
$discount = (double) $item['item_meta']['_line_subtotal'][0] - (double) $item['item_meta']['_line_total'][0];
if (isset($discount) && !empty($discount)) {
$discount = (double) ($discount / $item['qty']);
}
#---------Changes--------#
//Product Amount = product org amount - discount amount
$product_total_amount = (double) $product_amount - (double) $discount;
$product_sku = $pro_object->get_sku();
if (isset($product_total_amount) && isset($taxRate) && !empty($product_total_amount) && !empty($taxRate)) {
$taxValue = $product_total_amount * $taxRate;
}
$products[] = array('sku' => $product_sku, 'title' => $item['name'], 'price' => $product_total_amount, 'quantity' => $item['qty'], 'discountAmount' => isset($discount) ? $discount : 0, 'taxName' => isset($taxName) ? $taxName : null, 'taxId' => isset($taxId) ? $taxId : null, 'taxRate' => isset($taxRate) ? $taxRate : null, 'taxValue' => isset($taxValue) ? $taxValue : null, 'discountTitle' => isset($discountTitle) ? $discountTitle : 'sale');
$total_quantity += $item['qty'];
unset($taxId);
unset($taxName);
unset($taxRate);
unset($taxValue);
}
#---------Discount-----#
// $total_discount = $order->get_total_discount();
//$total_discount = get_post_meta($orderId, '_order_discount', true);
// if (isset($total_discount) && !empty($total_discount)) {
// $taxes_Discount = $apicall->linksync_getTaxes();
// if (isset($taxes_Discount) && !empty($taxes_Discount)) {
// if (!isset($taxes_Discount['errorCode'])) {
// if (isset($taxes_Discount['taxes'])) {
// foreach ($taxes_Discount['taxes'] as $select_tax) {
// if ($select_tax['name'] == 'GST') {
// $discountTaxName = $select_tax['name'];
// $discountTaxId = $select_tax['id'];
// $discountTaxRate = $select_tax['rate'];
// }
// }
// }
// }
// }
// if (isset($discountTaxRate) && !empty($discountTaxRate)) {
// $taxValue_discount = (float) $discountTaxRate * (float) $total_discount;
//.........这里部分代码省略.........
示例4: get_order_items
/**
* Get order items.
*
* @param WC_Order $order Order data.
*
* @return array Items list, extra amount and shipping cost.
*/
protected function get_order_items($order)
{
$items = array();
$extra_amount = 0;
$shipping_cost = 0;
// Force only one item.
if ('yes' == $this->gateway->send_only_total) {
$items[] = array('description' => $this->sanitize_description(sprintf(__('Order %s', 'woocommerce-pagseguro'), $order->get_order_number())), 'amount' => $this->money_format($order->get_total()), 'quantity' => 1);
} else {
// Products.
if (0 < count($order->get_items())) {
foreach ($order->get_items() as $order_item) {
if ($order_item['qty']) {
$item_name = $order_item['name'];
if (defined('WC_VERSION') && version_compare(WC_VERSION, '2.4.0', '<')) {
$item_meta = new WC_Order_Item_Meta($order_item['item_meta']);
} else {
$item_meta = new WC_Order_Item_Meta($order_item);
}
if ($meta = $item_meta->display(true, true)) {
$item_name .= ' - ' . $meta;
}
$items[] = array('description' => $this->sanitize_description($item_name), 'amount' => $this->money_format($order->get_item_total($order_item, false)), 'quantity' => $order_item['qty']);
}
}
}
// Fees.
if (0 < count($order->get_fees())) {
foreach ($order->get_fees() as $fee) {
$items[] = array('description' => $this->sanitize_description($fee['name']), 'amount' => $this->money_format($fee['line_total']), 'quantity' => 1);
}
}
// Taxes.
if (0 < count($order->get_taxes())) {
foreach ($order->get_taxes() as $tax) {
$items[] = array('description' => $this->sanitize_description($tax['label']), 'amount' => $this->money_format($tax['tax_amount'] + $tax['shipping_tax_amount']), 'quantity' => 1);
}
}
// Shipping Cost.
if (0 < $order->get_total_shipping()) {
$shipping_cost = $this->money_format($order->get_total_shipping());
}
// Discount.
if (defined('WC_VERSION') && version_compare(WC_VERSION, '2.3', '<')) {
if (0 < $order->get_order_discount()) {
$extra_amount = '-' . $this->money_format($order->get_order_discount());
}
}
}
return array('items' => $items, 'extra_amount' => $extra_amount, 'shipping_cost' => $shipping_cost);
}
示例5: generate_beeptify_form
/**
* Beeptify checkout form
*/
public function generate_beeptify_form($order_id)
{
global $woocommerce;
$order = new WC_Order($order_id);
/* Setup known values */
$amount_total = $order->order_total * 100;
$order_number = str_replace('#', null, $order->get_order_number());
$order_id = $order_number;
// Shop URL's
$decline_url = $woocommerce->cart->get_checkout_url();
//$woocommerce->api_request_url("WC_payment_gateway_beeptify");
$callback_url = add_query_arg('wooorderid', $order_id, WC()->api_request_url('WC_payment_gateway_beeptify'));
/* Sale lines */
$SaleLines = array();
/* Make purchase line for display at beeptify */
$reason = get_bloginfo('name') . " sale";
$i = 0;
foreach ($woocommerce->cart->get_cart() as $cart_item_key => $cart_item) {
$this_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key);
$this_product_id = apply_filters('woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key);
$this_product_name = $this_product->get_title();
$quantities = WC()->cart->get_cart_item_quantities();
$this_quantity = $quantities[$this_product_id];
$this_price = $this_product->price;
//$reason .= "$this_product_name: [br] $this_price". get_woocommerce_currency_symbol() ." x $this_quantity [br] Total: " . $this_total ." ". get_woocommerce_currency_symbol();
$SaleLines[$i]['ProductId'] = $this_product_id;
$SaleLines[$i]['ProductName'] = $this_product_name;
$SaleLines[$i]['ProductDescription'] = "";
$SaleLines[$i]['Quantity'] = $this_quantity;
$SaleLines[$i]['PricePerUnit'] = $this_price * 100;
$SaleLines[$i]['IsLoad'] = 0;
$SaleLines[$i]['CodeList'] = "";
/* Check for load on product */
$bCodes = get_post_meta($this_product_id, '_beeptify_code', false);
if (!empty($bCodes[0])) {
$SaleLines[$i]['IsLoad'] = 1;
$bCodes = explode(',', $bCodes[0]);
end($bCodes);
$lastKey = key($bCodes);
reset($bCodes);
foreach ($bCodes as $key => $bCode) {
$SaleLines[$i]['CodeList'] .= trim($bCode);
if ($key != $lastKey) {
$SaleLines[$i]['CodeList'] .= ", ";
}
}
}
$i++;
}
/* Include shipping for sale line */
if ($order->get_total_shipping() > 0) {
$SaleLines[$i]['ProductId'] = "x";
$SaleLines[$i]['ProductName'] = "Shipping";
$SaleLines[$i]['ProductDescription'] = "";
$SaleLines[$i]['Quantity'] = 1;
$SaleLines[$i]['PricePerUnit'] = $order->get_total_shipping() * 100;
$SaleLines[$i]['IsLoad'] = 0;
$SaleLines[$i]['CodeList'] = "";
}
/* Test for tax, and add as sale line */
$taxes = $order->get_taxes();
$total_for_test = $order->get_total_tax();
if (is_array($taxes) && $total_for_test > 0) {
// It seems to land in a random row?
foreach ($taxes as $the_tax) {
$taxes = $the_tax;
}
if (!empty($taxes['tax_amount']) && $taxes['tax_amount'] != 0 || !empty($taxes['shipping_tax_amount']) && $taxes['shipping_tax_amount'] != 0) {
$i++;
$SaleLines[$i]['ProductId'] = "t";
$SaleLines[$i]['ProductName'] = "Tax";
$SaleLines[$i]['ProductDescription'] = "";
$SaleLines[$i]['Quantity'] = 1;
$SaleLines[$i]['PricePerUnit'] = $taxes['tax_amount'] * 100 + $taxes['shipping_tax_amount'] * 100;
$SaleLines[$i]['IsLoad'] = 0;
$SaleLines[$i]['CodeList'] = "";
}
}
$css = '';
/* if frame,send the CSS */
if ($this->yesnotoint($this->frame)) {
$css = plugins_url("css/gateway.beeptify.css", __FILE__);
}
$beeptify_args = array('_selectHost' => $this->liveurl, 'MsgType' => 'sale', 'MerchantId' => $this->merchant_id, 'Reason' => $reason, 'OrderNumber' => $order_number, 'ProductId' => '21', 'Amount' => $amount_total, 'SuccessUrl' => $callback_url, 'ErrorUrl' => $decline_url, 'CancelUrl' => $decline_url, 'UserType' => "unregistered", 'UserEmail' => $order->billing_email, 'Css' => $css, 'Language' => $this->pay_language, 'Mode' => $this->mode, 'Secret' => $this->secret);
$html_form = array();
/* Primary args */
$to_hash = "";
foreach ($beeptify_args as $key => $arg) {
if ($key != '_selectHost' && !empty($arg)) {
$to_hash .= $arg;
}
if ($key != 'Secret') {
$html_form[] = "<input type='hidden' name='{$key}' value='{$arg}'/>";
}
}
/* Sale lines */
foreach ($SaleLines as $key => $line) {
//.........这里部分代码省略.........