本文整理汇总了PHP中WC_Order::get_order_currency方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Order::get_order_currency方法的具体用法?PHP WC_Order::get_order_currency怎么用?PHP WC_Order::get_order_currency使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WC_Order
的用法示例。
在下文中一共展示了WC_Order::get_order_currency方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_total
/**
* Get the total amount with or without refunds
* @return string
*/
public function get_total()
{
$total = '';
if ($this->order->get_total_refunded() > 0) {
$total_after_refund = $this->order->get_total() - $this->order->get_total_refunded();
$total = '<del class="total-without-refund">' . strip_tags($this->order->get_formatted_order_total()) . '</del> <ins>' . wc_price($total_after_refund, array('currency' => $this->order->get_order_currency())) . '</ins>';
} else {
$total = $this->order->get_formatted_order_total();
}
return $total;
}
示例2: receipt_page
/**
* Redirect to allPay
*/
public function receipt_page($order_id)
{
# Clean the cart
global $woocommerce;
$woocommerce->cart->empty_cart();
$order = new WC_Order($order_id);
try {
$this->invoke_allpay_module();
$aio = new AllInOne();
$aio->Send['MerchantTradeNo'] = '';
$service_url = '';
if ($this->allpay_test_mode == 'yes') {
$service_url = 'http://payment-stage.allpay.com.tw/Cashier/AioCheckOut';
$aio->Send['MerchantTradeNo'] = date('YmdHis');
} else {
$service_url = 'https://payment.allpay.com.tw/Cashier/AioCheckOut';
}
$aio->MerchantID = $this->allpay_merchant_id;
$aio->HashKey = $this->allpay_hash_key;
$aio->HashIV = $this->allpay_hash_iv;
$aio->ServiceURL = $service_url;
$aio->Send['ReturnURL'] = add_query_arg('wc-api', 'WC_Gateway_Allpay', home_url('/'));
$aio->Send['ClientBackURL'] = home_url('?page_id=' . get_option('woocommerce_myaccount_page_id') . '&view-order=' . $order->id);
$aio->Send['MerchantTradeNo'] .= $order->id;
$aio->Send['MerchantTradeDate'] = date('Y/m/d H:i:s');
# Set the product info
$aio->Send['TotalAmount'] = $order->get_total();
array_push($aio->Send['Items'], array('Name' => '網路商品一批', 'Price' => $aio->Send['TotalAmount'], 'Currency' => $order->get_order_currency(), 'Quantity' => 1));
$aio->Send['TradeDesc'] = 'allPay_module_woocommerce_1_0_3';
# Get the chosen payment and installment
$notes = $order->get_customer_order_notes();
$choose_payment = '';
$choose_installment = '';
if (isset($notes[0])) {
list($choose_payment, $choose_installment) = explode('_', $notes[0]->comment_content);
}
$aio->Send['ChoosePayment'] = $choose_payment;
# Set the extend information
switch ($aio->Send['ChoosePayment']) {
case 'Credit':
# Do not support UnionPay
$aio->SendExtend['UnionPay'] = false;
# Credit installment parameters
if (!empty($choose_installment)) {
$aio->SendExtend['CreditInstallment'] = $choose_installment;
$aio->SendExtend['InstallmentAmount'] = $aio->Send['TotalAmount'];
$aio->SendExtend['Redeem'] = false;
}
break;
case 'WebATM':
break;
case 'ATM':
$aio->SendExtend['ExpireDate'] = 3;
$aio->SendExtend['PaymentInfoURL'] = $aio->Send['ReturnURL'];
break;
case 'CVS':
case 'BARCODE':
$aio->SendExtend['Desc_1'] = '';
$aio->SendExtend['Desc_2'] = '';
$aio->SendExtend['Desc_3'] = '';
$aio->SendExtend['Desc_4'] = '';
$aio->SendExtend['PaymentInfoURL'] = $aio->Send['ReturnURL'];
break;
case 'Alipay':
$aio->SendExtend['Email'] = $order->billing_email;
$aio->SendExtend['PhoneNo'] = $order->billing_phone;
$aio->SendExtend['UserName'] = $order->billing_first_name . ' ' . $order->billing_last_name;
break;
case 'Tenpay':
$aio->SendExtend['ExpireTime'] = date('Y/m/d H:i:s', strtotime('+3 days'));
break;
case 'TopUpUsed':
break;
default:
throw new Exception($this->tran('Invalid payment method.'));
break;
}
$aio->CheckOut();
exit;
} catch (Exception $e) {
$this->add_error($e->getMessage());
}
}
示例3: woo_vou_get_formatted_product_price
/**
* Gets Order product Price in voucher code
*
* @package WooCommerce - PDF Vouchers
* @since 1.1.0
*/
public function woo_vou_get_formatted_product_price($orderid, $item, $tax_display = '')
{
//Get prefix
$prefix = WOO_VOU_META_PREFIX;
//Get Order
$woo_order = new WC_Order($orderid);
if (!$tax_display) {
$tax_display = $woo_order->tax_display_cart;
}
if (!isset($item['line_subtotal']) || !isset($item['line_subtotal_tax'])) {
return '';
}
//get multipdf option in ordermeta
$multiple_pdf = get_post_meta($orderid, $prefix . 'multiple_pdf', true);
//Get Item quantity
$item_qty = isset($item['qty']) ? $item['qty'] : '';
if ('excl' == $tax_display) {
$ex_tax_label = $woo_order->prices_include_tax ? 1 : 0;
$line_subtotal = $woo_order->get_line_subtotal($item);
if ($multiple_pdf == 'yes' && !empty($item_qty)) {
$line_subtotal = $line_subtotal / $item_qty;
}
$subtotal = wc_price($line_subtotal, array('ex_tax_label' => $ex_tax_label, 'currency' => $woo_order->get_order_currency()));
} else {
$line_subtotal = $woo_order->get_line_subtotal($item, true);
if ($multiple_pdf == 'yes' && !empty($item_qty)) {
$line_subtotal = $line_subtotal / $item_qty;
}
$subtotal = wc_price($line_subtotal, array('currency' => $woo_order->get_order_currency()));
}
return apply_filters('woo_vou_get_formatted_product_price', $subtotal, $orderid, $item, $tax_display);
}
示例4: output_order_tracking_code
/**
* Output the order tracking code for enabled networks
*
* @param int $order_id
*
* @return string
*/
public function output_order_tracking_code($order_id)
{
$order = new WC_Order($order_id);
$code = "<script>fbq('track', 'Purchase', {value: '" . esc_js($order->get_total()) . "', currency: '" . esc_js($order->get_order_currency()) . "'});</script>";
$code .= '<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=' . esc_js($this->facebook_id) . '&ev=Purchase&cd[value]=' . urlencode($order->get_total()) . '&cd[currency]=' . urlencode($order->get_order_currency()) . '&noscript=1"
/></noscript>';
echo $code;
}
开发者ID:bitpiston,项目名称:woocommerce-facebook-remarketing,代码行数:16,代码来源:class-wc-facebook-remarketing-integration.php
示例5: validate_currency
/**
* Check currency from IPN matches the order
* @param WC_Order $order
* @param string $currency
*/
protected function validate_currency($order, $currency)
{
// Validate currency
if ($order->get_order_currency() != $currency) {
WC_Gateway_Komoju::log('Payment error: Currencies do not match (sent "' . $order->get_order_currency() . '" | returned "' . $currency . '")');
// Put this order on-hold for manual checking
$order->update_status('on-hold', sprintf(__('Validation error: Komoju currencies do not match (code %s).', 'woocommerce'), $currency));
exit;
}
}
示例6: order_status_changed
public static function order_status_changed($id, $status = '', $new_status = '')
{
$rules = get_option('woorule_rules', array());
foreach ($rules as $k => $rule) {
$enabled = get_option($rule['enabled']['id']) === 'yes' ? true : false;
if ($enabled) {
$which_event = get_option($rule['occurs']['id']);
$is_opt_in_rule = false;
$want_in = true;
if (isset($rule['show_opt_in'])) {
$is_opt_in_rule = get_option($rule['show_opt_in']['id']) === 'yes' ? true : false;
}
if ($is_opt_in_rule) {
$want_in = get_post_meta($id, 'woorule_opt_in_' . $k, false);
if (!empty($want_in)) {
$want_in = $want_in[0] === 'yes' ? true : false;
}
}
if ($want_in && $new_status === $which_event) {
$integration = new WC_Integration_RuleMailer();
$order = new WC_Order($id);
$user = $order->get_user();
$currency = $order->get_order_currency();
$order_subtotal = $order->order_total - ($order->order_shipping_tax + $order->order_shipping) - $order->cart_discount;
$items = $order->get_items();
$brands = array();
$categories = array();
$tags = array();
foreach ($items as $item) {
$p = new WC_Product_Simple($item['product_id']);
$brands[] = $p->get_attribute('brand');
// this is bullshit
$cat = strip_tags($p->get_categories(''));
$tag = strip_tags($p->get_tags(''));
if (!empty($cat)) {
$categories[] = $cat;
}
if (!empty($tag)) {
$tags[] = $tag;
}
}
$subscription = array('apikey' => $integration->api_key, 'update_on_duplicate' => get_option($rule['update_on_duplicate']['id']) === 'yes' ? true : false, 'auto_create_tags' => get_option($rule['auto_create_tags']['id']) === 'yes' ? true : false, 'auto_create_fields' => get_option($rule['auto_create_fields']['id']) === 'yes' ? true : false, 'tags' => explode(',', get_option($rule['tags']['id'])), 'subscribers' => array('email' => $order->billing_email, 'phone_number' => $order->billing_phone, 'fields' => array(array('key' => 'Order.Number', 'value' => $order->get_order_number()), array('key' => 'Order.Date', 'value' => $order->order_date), array('key' => 'Order.FirstName', 'value' => $order->billing_first_name), array('key' => 'Order.LastName', 'value' => $order->billing_last_name), array('key' => 'Order.Street1', 'value' => $order->billing_address_1), array('key' => 'Order.Street2', 'value' => $order->billing_address_2), array('key' => 'Order.City', 'value' => $order->billing_city), array('key' => 'Order.Country', 'value' => $order->billing_country), array('key' => 'Order.State', 'value' => $order->billing_state), array('key' => 'Order.Subtotal', 'value' => $order_subtotal), array('key' => 'Order.Discount', 'value' => $order->cart_discount), array('key' => 'Order.Shipping', 'value' => $order->order_shipping + $order->order_shipping_tax), array('key' => 'Order.Total', 'value' => $order->order_total), array('key' => 'Order.Vat', 'value' => $order->order_tax))));
if (!empty($categories)) {
$subscription['subscribers']['fields'][] = array('key' => 'Order.Categories', 'value' => $categories, 'type' => 'multiple');
}
if (!empty($tags)) {
$subscription['subscribers']['fields'][] = array('key' => 'Order.Tags', 'value' => array($tags), 'type' => 'multiple');
}
if (!empty($brands)) {
$subscription['subscribers']['fields'][] = array('key' => 'Order.Brands', 'value' => $brands, 'type' => 'multiple');
}
$api = WP_RuleMailer_API::get_instance();
$api::subscribe($integration->api_url, $subscription);
}
}
}
}
示例7: get_request
/**
* Get refund request args
* @param WC_Order $order
* @param float $amount
* @param string $reason
* @return array
*/
public static function get_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_order_currency();
$request['REFUNDTYPE'] = 'Partial';
}
return apply_filters('woocommerce_paypal_refund_request', $request, $order, $amount, $reason);
}
示例8: orderpost
function orderpost($orderId)
{
global $wpdb;
$testMode = get_option('linksync_test');
$LAIDKey = get_option('linksync_laid');
$apicall = new linksync_class($LAIDKey, $testMode);
//Checking for already sent Order
$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)) {
$order = new WC_Order($orderId);
if ($order->post_status == get_option('order_status_wc_to_vend')) {
update_option('linksync_sent_order_id', serialize(array_merge($order_id_array, array($orderId))));
$order_no = $order->get_order_number();
if (strpos($order_no, '#') !== false) {
$order_no = str_replace('#', '', $order_no);
}
$get_total = $order->get_total();
$get_user = $order->get_user();
$comments = $order->post->post_excerpt;
$primary_email_address = $get_user->data->user_email;
$currency = $order->get_order_currency();
$shipping_method = $order->get_shipping_method();
$order_total = $order->get_order_item_totals();
$transaction_id = $order->get_transaction_id();
$taxes_included = false;
$total_discount = $order->get_total_discount();
$total_quantity = 0;
$registerDb = get_option('wc_to_vend_register');
$vend_uid = get_option('wc_to_vend_user');
$total_tax = $order->get_total_tax();
// Geting Payment object details
if (isset($order_total['payment_method']['value']) && !empty($order_total['payment_method']['value'])) {
$wc_payment = get_option('wc_to_vend_payment');
if (isset($wc_payment) && !empty($wc_payment)) {
$total_payments = explode(",", $wc_payment);
foreach ($total_payments as $mapped_payment) {
$exploded_mapped_payment = explode("|", $mapped_payment);
if (isset($exploded_mapped_payment[1]) && !empty($exploded_mapped_payment[1]) && isset($exploded_mapped_payment[0]) && !empty($exploded_mapped_payment[0])) {
if ($exploded_mapped_payment[1] == $order_total['payment_method']['value']) {
$vend_payment_data = explode("%%", $exploded_mapped_payment[0]);
if (isset($vend_payment_data[0])) {
$payment_method = $vend_payment_data[0];
}
if (isset($vend_payment_data[1])) {
$payment_method_id = $vend_payment_data[1];
}
break;
}
}
}
}
$payment = array("retailer_payment_type_id" => isset($payment_method_id) ? $payment_method_id : null, "amount" => isset($get_total) ? $get_total : 0, "method" => isset($payment_method) ? $payment_method : null, "transactionNumber" => isset($transaction_id) ? $transaction_id : null);
}
$export_user_details = get_option('wc_to_vend_export');
if (isset($export_user_details) && !empty($export_user_details)) {
if ($export_user_details == 'customer') {
//woocommerce filter
$billingAddress_filter = apply_filters('woocommerce_order_formatted_billing_address', array('firstName' => $order->billing_first_name, 'lastName' => $order->billing_last_name, 'phone' => $order->billing_phone, 'street1' => $order->billing_address_1, 'street2' => $order->billing_address_2, 'city' => $order->billing_city, 'state' => $order->billing_state, 'postalCode' => $order->billing_postcode, 'country' => $order->billing_country, 'company' => $order->billing_company, 'email_address' => $order->billing_email), $order);
$billingAddress = array('firstName' => $billingAddress_filter['firstName'], 'lastName' => $billingAddress_filter['lastName'], 'phone' => $billingAddress_filter['phone'], 'street1' => $billingAddress_filter['street1'], 'street2' => $billingAddress_filter['street2'], 'city' => $billingAddress_filter['city'], 'state' => $billingAddress_filter['state'], 'postalCode' => $billingAddress_filter['postalCode'], 'country' => $billingAddress_filter['country'], 'company' => $billingAddress_filter['company'], 'email_address' => $billingAddress_filter['email_address']);
$deliveryAddress_filter = apply_filters('woocommerce_order_formatted_shipping_address', array('firstName' => $order->shipping_first_name, 'lastName' => $order->shipping_last_name, 'phone' => $order->shipping_phone, 'street1' => $order->shipping_address_1, 'street2' => $order->shipping_address_2, 'city' => $order->shipping_city, 'state' => $order->shipping_state, 'postalCode' => $order->shipping_postcode, 'country' => $order->shipping_country, 'company' => $order->shipping_company), $order);
$deliveryAddress = array('firstName' => $deliveryAddress_filter['firstName'], 'lastName' => $deliveryAddress_filter['lastName'], 'phone' => $deliveryAddress_filter['phone'], 'street1' => $deliveryAddress_filter['street1'], 'street2' => $deliveryAddress_filter['street2'], 'city' => $deliveryAddress_filter['city'], 'state' => $deliveryAddress_filter['state'], 'postalCode' => $deliveryAddress_filter['postalCode'], 'country' => $deliveryAddress_filter['country'], 'company' => $deliveryAddress_filter['company']);
$primary_email = isset($primary_email_address) ? $primary_email_address : $billingAddress['email_address'];
unset($billingAddress['email_address']);
}
}
$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];
//.........这里部分代码省略.........
示例9: do_capture
/**
* Setup the DoCapture request
*
* @link https://developer.paypal.com/webapps/developer/docs/classic/api/merchant/DoCapture_API_Operation_NVP/
* @link https://developer.paypal.com/webapps/developer/docs/classic/admin/auth-capture/
*
* @since 3.0.0
* @param WC_Order $order order object
*/
public function do_capture(WC_Order $order)
{
$this->set_method('DoCapture');
$this->add_parameters(array('AUTHORIZATIONID' => $order->paypal_express_transaction_id, 'AMT' => $order->capture_total, 'CURRENCYCODE' => $order->get_order_currency(), 'COMPLETETYPE' => 'Complete', 'INVNUM' => $order->paypal_express_invoice_prefix . SV_WC_Helper::str_to_ascii(ltrim($order->get_order_number(), _x('#', 'hash before the order number', WC_PayPal_Express::TEXT_DOMAIN))), 'NOTE' => $order->description));
}
示例10: epay_meta_box_payment
public function epay_meta_box_payment()
{
global $post, $woocommerce;
$order = new WC_Order($post->ID);
$transactionId = get_post_meta($order->id, 'Transaction ID', true);
require_once epay_LIB . 'class.epaysoap.php';
if (strlen($transactionId) > 0) {
try {
$webservice = new epaysoap($this->remotepassword);
$transaction = $webservice->gettransaction($this->merchant, $transactionId);
if (!is_wp_error($transaction)) {
echo '<p>';
echo '<strong>' . _e('Transaction ID', 'woocommerce-gateway-epay-dk') . ':</strong> ' . $transaction->transactionInformation->transactionid;
echo '</p>';
echo '<p>';
echo '<strong>' . _e('Authorized amount', 'woocommerce-gateway-epay-dk') . ':</strong> ' . $order->get_order_currency() . ' ' . number_format($transaction->transactionInformation->authamount / 100, 2, ".", "");
echo '</p>';
echo '<p>';
echo '<strong>' . _e('Captured amount', 'woocommerce-gateway-epay-dk') . ':</strong> ' . $order->get_order_currency() . ' ' . number_format($transaction->transactionInformation->capturedamount / 100, 2, ".", "");
echo '</p>';
echo '<p>';
echo '<strong>' . _e('Credited amount', 'woocommerce-gateway-epay-dk') . ':</strong> ' . $order->get_order_currency() . ' ' . number_format($transaction->transactionInformation->creditedamount / 100, 2, ".", "");
echo '</p>';
if ($transaction->transactionInformation->status == "PAYMENT_NEW") {
echo '<ul>';
echo '<li>';
echo '<p>';
echo $order->get_order_currency() . ' <span><input type="text" value="' . number_format(($transaction->transactionInformation->authamount - $transaction->transactionInformation->capturedamount) / 100, 2, ".", "") . '" id="epay_amount" name="epay_amount" /></span>';
echo '</p>';
echo '<a class="button" onclick="javascript:location.href=\'' . admin_url('post.php?post=' . $post->ID . '&action=edit&epay_action=capture') . '&amount=\' + document.getElementById(\'epay_amount\').value">';
echo _e('Capture', 'woocommerce-gateway-epay-dk');
echo '</a>';
echo '</li>';
echo '</ul><br />';
echo '<a class="button" href="' . admin_url('post.php?post=' . $post->ID . '&action=edit&epay_action=delete') . '">';
echo _e('Delete', 'woocommerce-gateway-epay-dk');
echo '</a>';
} elseif ($transaction->transactionInformation->status == "PAYMENT_CAPTURED" && $transaction->transactionInformation->creditedamount == 0) {
echo '<ul>';
echo '<li>';
echo '<p>';
echo $order->get_order_currency() . ' <span><input type="text" value="' . number_format($transaction->transactionInformation->capturedamount / 100, 2, ".", "") . '" id="epay_credit_amount" name="epay_credit_amount" /></span>';
echo '</p>';
echo '<a class="button" onclick="javascript: (confirm(\'' . __('Are you sure you want to credit?', 'woocommerce-gateway-epay-dk') . '\') ? (location.href=\'' . admin_url('post.php?post=' . $post->ID . '&action=edit&epay_action=credit') . '&amount=\' + document.getElementById(\'epay_credit_amount\').value) : (false));">';
echo _e('Credit', 'woocommerce-gateway-epay-dk');
echo '</a>';
echo '</li>';
echo '</ul><br />';
}
echo '<br /><br />';
$historyArray = $transaction->transactionInformation->history->TransactionHistoryInfo;
if (!array_key_exists(0, $transaction->transactionInformation->history->TransactionHistoryInfo)) {
$historyArray = array($transaction->transactionInformation->history->TransactionHistoryInfo);
}
for ($i = 0; $i < count($historyArray); $i++) {
echo str_replace("T", " ", $historyArray[$i]->created) . ": ";
if (strlen($historyArray[$i]->username) > 0) {
echo $historyArray[$i]->username . ": ";
}
echo $historyArray[$i]->eventMsg . "<br />";
}
} else {
foreach ($transaction->get_error_messages() as $error) {
throw new Exception($error->get_error_message());
}
}
} catch (Exception $e) {
echo $this->message("error", $e->getMessage());
}
} else {
echo "No transaction was found.";
}
}
示例11: capture_sale_events
/**
* Capture and log when customer completes checkout
*
* @param int $order_id
* @return void
*/
public function capture_sale_events($order_ids, $historic = false)
{
$products = array();
foreach ($order_ids as $order_id) {
$exported = get_post_meta($order_id, '_wc_graphflow_exported', true);
if ('yes' !== $exported) {
$order = new WC_Order($order_id);
if (!$order) {
return;
}
$order_currency = $order->get_order_currency();
$order_id = $order->id;
$customer_ip_address = $order->customer_ip_address;
$customer_user_agent = $order->customer_user_agent;
// extract order status, different for WC 2.1 vs 2.2
if (defined('WOOCOMMERCE_VERSION') && version_compare(WOOCOMMERCE_VERSION, '2.2', '>=')) {
$order_status = $order->get_status();
} else {
$order_status = $order->status;
}
foreach ($order->get_items() as $order_item_id => $order_item) {
// extract the user id for the order
if ($historic == true) {
$order_user = isset($order->customer_user) ? $order->customer_user : $order->billing_email;
if ($order_user == 0) {
$order_user = $order->billing_email;
}
} else {
$order_user = $this->get_user_id();
}
// check if we can get the product, log an error message if not.
$product = get_product($order_item['product_id']);
if (!$product) {
$this->get_api()->log->add("graphflow", "Failed to get_product for id: " . $order_item['product_id'] . " during order export for order id: " . $order->id);
continue;
}
$this->maybe_capture_product($order_item['product_id']);
// timestamp in UTC
$time = new DateTime($order->order_date);
$time->setTimezone(new DateTimeZone('UTC'));
$timestamp_utc = $time->getTimestamp() * 1000;
$graphflow_order_item = array('fromId' => $order_user, 'toId' => $order_item['product_id'], 'interactionType' => 'purchase', 'price' => $product->get_price(), 'quantity' => $order_item['qty'], 'interactionData' => array('order_currency' => $order_currency, 'transactionId' => $order_id, 'remoteAddr' => $customer_ip_address, 'uaRaw' => $customer_user_agent, 'order_status' => $order_status), 'timestamp' => $timestamp_utc);
$products[] = $graphflow_order_item;
}
// For historical orders, only capture if not already captured
if ($historic == false || 'yes' != get_user_meta($order_user, '_wc_graphflow_exported', true)) {
$this->capture_customer($order_user, $historic);
}
}
}
if (!empty($products)) {
$this->get_api()->add_user_interactions($products);
}
foreach ($order_ids as $order_id) {
// Set a meta field so we do not export again when visiting thanks page for this order
update_post_meta($order_id, '_wc_graphflow_exported', 'yes');
}
}
开发者ID:asafmaoz1234,项目名称:woocommerce-recommendations-by-graphflow,代码行数:64,代码来源:class-wc-graphflow.php
示例12: process_refund
/**
* Process refund
*
* If the gateway declares 'refunds' support, this will allow it to refund
* a passed in amount.
*
* @param int $order_id
* @param float $amount
* @param string $reason
* @return boolean True or false based on success, or a WP_Error object
*/
public function process_refund($order_id, $amount = null, $reason = '')
{
global $woocommerce;
$order = new WC_Order($order_id);
$this->params["amount"] = (int) ($amount * 100);
$this->params["reference"] = $order_id . "-" . time();
// It is not possible to simply refund against the order ID as multiple reunds are permitted...
$this->params["transaction_id"] = get_post_meta($order_id, '_transaction_id', true);
if (empty($this->params['transaction_id'])) {
$this->params["transaction_id"] = $this->fetch_fatzebra_transaction_id($order_id);
}
$this->params["customer_ip"] = $this->get_customer_real_ip();
$this->params["currency"] = $order->get_order_currency();
$test_mode = $this->settings['test_mode'] == 'yes';
$this->params["test"] = $test_mode;
$sandbox_mode = $this->settings["sandbox_mode"] == "yes";
// Yup, the checkbox settings return as 'yes' or 'no'
$order_text = json_encode($this->params);
$url = $sandbox_mode ? $this->sandbox_url : ($url = $this->live_url);
// URL is for /refunds
$url = str_replace('purchases', 'refunds', $url);
$args = array('method' => 'POST', 'body' => $order_text, 'headers' => array('Authorization' => 'Basic ' . base64_encode($this->settings["username"] . ":" . $this->settings["token"]), 'X-Test-Mode' => $test_mode, 'User-Agent' => "WooCommerce Plugin " . $this->version), 'timeout' => 30);
try {
$this->response = (array) wp_remote_request($url, $args);
if ((int) $this->response["response"]["code"] != 200 && (int) $this->response["response"]["code"] != 201) {
wc_add_notice("Refund failed: " . $this->response["response"]["message"], 'error');
return false;
}
$this->response_data = json_decode($this->response['body']);
if (!$this->response_data->successful) {
wc_add_notice('Refund Failed - Gateway Error: ' . implode(",", $this->response_data->errors), 'error');
return false;
}
if (!$this->response_data->response->successful) {
wc_add_notice('Refund Declined: ' . $this->response_data->response->message, 'error');
return false;
}
if ($this->response_data->response->successful) {
wc_add_notice('Refund Approved');
$order->add_order_note('Refund for ' . $amount . ' successful. Refund ID: ' . $this->response_data->response->id);
return true;
}
} catch (Exception $e) {
wc_add_notice("Unknown Refund Error - please see error log", "error");
error_log("Exception caught during refund: " . print_r($e, true));
return false;
}
return false;
}
示例13: set_order
/**
* Sets WooCommerce Order in request
*
* @param WC_Order $order
*
* @return $this
*/
public function set_order(WC_Order $order)
{
$customer = array();
if ($this->check_string_length($order->billing_first_name, 2, 50)) {
$customer['givenName'] = $order->billing_first_name;
}
if ($this->check_string_length($order->billing_last_name, 2, 50)) {
$customer['surname'] = $order->billing_last_name;
}
if ($this->check_string_length($order->billing_company, 1, 40)) {
$customer['companyName'] = $order->billing_company;
}
if ($this->check_string_length($order->billing_phone, 6, 25)) {
$customer['phone'] = $order->billing_phone;
}
if ($this->check_string_length($order->billing_email, 6, 128)) {
$customer['email'] = $order->billing_email;
}
if ($this->check_string_length($order->customer_ip_address, 1, 255)) {
$customer['ip'] = $order->customer_ip_address;
}
$billing = array();
if ($this->check_string_length($order->billing_address_1, 2, 50)) {
$billing['street1'] = $order->billing_address_1;
}
if ($this->check_string_length($order->billing_address_2, 2, 50)) {
$billing['street2'] = $order->billing_address_2;
}
if ($this->check_string_length($order->billing_city, 2, 30)) {
$billing['city'] = $order->billing_city;
}
if ($this->check_string_length($order->billing_state, 2, 50)) {
$billing['state'] = $order->billing_state;
}
if ($this->check_string_length($order->billing_postcode, 1, 10)) {
$billing['postcode'] = $order->billing_postcode;
}
if ($this->check_string_length($order->billing_country, 2, 2)) {
$billing['country'] = $order->billing_country;
}
$shipping = array();
if ($this->check_string_length($order->shipping_first_name, 2, 50)) {
$shipping['givenName'] = $order->shipping_first_name;
}
if ($this->check_string_length($order->shipping_last_name, 2, 50)) {
$shipping['surname'] = $order->shipping_last_name;
}
if ($this->check_string_length($order->shipping_address_1, 2, 50)) {
$shipping['street1'] = $order->shipping_address_1;
}
if ($this->check_string_length($order->shipping_address_2, 2, 50)) {
$shipping['street2'] = $order->shipping_address_2;
}
if ($this->check_string_length($order->shipping_city, 2, 30)) {
$shipping['city'] = $order->shipping_city;
}
if ($this->check_string_length($order->shipping_state, 2, 50)) {
$shipping['state'] = $order->shipping_state;
}
if ($this->check_string_length($order->shipping_postcode, 1, 10)) {
$shipping['postcode'] = $order->shipping_postcode;
}
if ($this->check_string_length($order->shipping_country, 2, 2)) {
$shipping['country'] = $order->shipping_country;
}
$orderItems = $order->get_items();
$i = 0;
foreach ($orderItems as $orderItem) {
if ($orderItem['type'] == 'line_item') {
$this->data['cart.items[' . $i . '].name'] = urlencode($orderItem['name']);
$this->data['cart.items[' . $i . '].quantity'] = $orderItem['qty'];
$i++;
}
}
$this->set_amount(sprintf('%0.2f', $order->get_total()))->set_currency($order->get_order_currency())->set_merchant_transaction_id($this->generate_trans_id($order->id))->add_custom_param('orderId', $order->id)->set_customer($customer)->set_billing($billing)->set_shipping($shipping);
$this->order = $order;
return $this;
}
示例14: sprintf
/**
* PayU IPN Request
*
* @access public
* @param $_POST
* @return void
*/
function payu_ipn_request()
{
$posted = stripslashes_deep($_POST);
if (empty($posted)) {
$this->log->add('payu', sprintf(__('PayU IPN Request Failure. %s', 'wc-payu') . $posted));
wp_die(__('PayU IPN Request Failure.', 'wc-payu'));
}
$order_ref = explode("-", $posted['REFNOEXT']);
$order_id = $order_ref[0];
$order = new WC_Order($order_id);
if ($order) {
// PayU függvények betöltése
require_once 'includes/payu.class.php';
$config = $this->get_payu_config($order->get_order_currency());
$ipn = new PayUIpn($config);
if ($this->debug == 'yes') {
$ipn->logger = true;
$ipn->log_path = WC_LOG_DIR;
}
if ($ipn->validateReceived()) {
/*
[REFNO] => 11186529
[REFNOEXT] => 63
[ORDERSTATUS] => COMPLETE
[PAYMETHOD] => Visa/MasterCard/Eurocard
[PAYMETHOD_CODE] => CCVISAMC
*/
if ($order->status == $this->waiting_payment_status) {
$order->update_status($this->succesfull_payment_status, __('Succesfull payment.', 'wc-payu'));
$order->reduce_order_stock();
$order->add_order_note(sprintf(__('IPN STATUS: %s', 'wc-payu'), $_POST['ORDERSTATUS']));
echo $ipn->confirmReceived();
} else {
echo __('Not waiting status. Not sending email, or not update orders status.', 'wc-payu');
}
exit;
}
} else {
echo __('Can not query data in the orders. Not sending email, or not update orders status.', 'wc-payu');
exit;
}
}
示例15: generate_payment_request
/**
* Generate the request for the payment.
* @param WC_Order $order
* @param object $source
* @return array()
*/
protected function generate_payment_request($order, $source)
{
$post_data = array();
$post_data['currency'] = strtolower($order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency());
$post_data['amount'] = $this->get_stripe_amount($order->get_total(), $post_data['currency']);
$post_data['description'] = sprintf(__('%s - Order %s', 'woocommerce-gateway-stripe'), wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES), $order->get_order_number());
$post_data['capture'] = $this->capture ? 'true' : 'false';
if (!empty($order->billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) {
$post_data['receipt_email'] = $order->billing_email;
}
$post_data['expand[]'] = 'balance_transaction';
if ($source->customer) {
$post_data['customer'] = $source->customer;
}
if ($source->source) {
$post_data['source'] = $source->source;
}
return $post_data;
}