本文整理汇总了PHP中wc_get_order函数的典型用法代码示例。如果您正苦于以下问题:PHP wc_get_order函数的具体用法?PHP wc_get_order怎么用?PHP wc_get_order使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wc_get_order函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create_order
/**
* Create a order.
*
* @since 2.4
*
* @return WC_Order Order object.
*/
public static function create_order()
{
// Create product
$product = WC_Helper_Product::create_simple_product();
WC_Helper_Shipping::create_simple_flat_rate();
$order_data = array('status' => 'pending', 'customer_id' => 1, 'customer_note' => '', 'total' => '');
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
// Required, else wc_create_order throws an exception
$order = wc_create_order($order_data);
// Add order products
$item_id = $order->add_product($product, 4);
// Set billing address
$billing_address = array('country' => 'US', 'first_name' => 'Jeroen', 'last_name' => 'Sormani', 'company' => 'WooCompany', 'address_1' => 'WooAddress', 'address_2' => '', 'postcode' => '123456', 'city' => 'WooCity', 'state' => 'NY', 'email' => 'admin@example.org', 'phone' => '555-32123');
$order->set_address($billing_address, 'billing');
// Add shipping costs
$shipping_taxes = WC_Tax::calc_shipping_tax('10', WC_Tax::get_shipping_tax_rates());
$order->add_shipping(new WC_Shipping_Rate('flat_rate_shipping', 'Flat rate shipping', '10', $shipping_taxes, 'flat_rate'));
// Set payment gateway
$payment_gateways = WC()->payment_gateways->payment_gateways();
$order->set_payment_method($payment_gateways['bacs']);
// Set totals
$order->set_total(10, 'shipping');
$order->set_total(0, 'cart_discount');
$order->set_total(0, 'cart_discount_tax');
$order->set_total(0, 'tax');
$order->set_total(0, 'shipping_tax');
$order->set_total(40, 'total');
// 4 x $10 simple helper product
return wc_get_order($order->id);
}
示例2: process_refund
/**
* Process a refund if supported
* @param int $order_id
* @param float $amount
* @param string $reason
* @return bool|wp_error True or false based on success, or a WP_Error object
*/
public function process_refund($order_id, $amount = null, $reason = '')
{
$order = wc_get_order($order_id);
$transaction_id = null;
$args = array('post_id' => $order->id, 'approve' => 'approve', 'type' => '');
remove_filter('comments_clauses', array('WC_Comments', 'exclude_order_comments'));
$comments = get_comments($args);
foreach ($comments as $comment) {
if (strpos($comment->comment_content, 'Transaction ID: ') !== false) {
$exploded_comment = explode(": ", $comment->comment_content);
$transaction_id = $exploded_comment[1];
}
}
add_filter('comments_clauses', array('WC_Comments', 'exclude_order_comments'));
if (!$order || !$transaction_id) {
return false;
}
// Add transaction-specific details to the request
$transaction_details = array('username' => $this->username, 'password' => $this->password, 'type' => 'refund', 'transactionid' => $transaction_id, 'ipaddress' => $_SERVER['REMOTE_ADDR']);
if (!is_null($amount)) {
$transaction_details['amount'] = number_format($amount, 2, '.', '');
}
// Send request and get response from server
$response = $this->post_and_get_response($transaction_details);
// Check response
if ($response['response'] == 1) {
// Success
$order->add_order_note(__('Inspire Commerce refund completed. Refund Transaction ID: ', 'woocommerce') . $response['transactionid']);
return true;
} else {
// Failure
$order->add_order_note(__('Inspire Commerce refund error. Response data: ', 'woocommerce') . http_build_query($response));
return false;
}
}
示例3: admin_order_item_values
public function admin_order_item_values($_product, $item, $item_id)
{
if (is_object($_product)) {
global $post_id;
$wc_order = wc_get_order($post_id);
if ($wc_order !== false) {
$fpd_data = $wc_order->get_item_meta($item_id, 'fpd_data', true);
if (!empty($fpd_data)) {
?>
<td class="fancy-product" width="100px">
<button class='button button-secondary fpd-show-order-item' data-order_id='<?php
echo $post_id;
?>
' data-order_item_id='<?php
echo $item_id;
?>
'><?php
_e('Load in Order Viewer', 'radykal');
?>
</button>
</td>
<?php
}
}
}
}
示例4: bank_details
/**
* Get bank details and place into a list format.
*
* Note: Since this is declared as a private function in WC_Gateway_BACS, it needs
* to be copied here 1:1
*
* @param int $order_id
*/
private function bank_details($order_id = '')
{
if (empty($this->account_details)) {
return;
}
// Get order and store in $order
$order = wc_get_order($order_id);
// Get the order country and country $locale
$country = $order->billing_country;
$locale = $this->get_country_locale();
// Get sortcode label in the $locale array and use appropriate one
$sortcode = isset($locale[$country]['sortcode']['label']) ? $locale[$country]['sortcode']['label'] : __('Sort Code', 'woocommerce');
$bacs_accounts = apply_filters('woocommerce_bacs_accounts', $this->account_details);
if (!empty($bacs_accounts)) {
echo '<h2>' . __('Our Bank Details', 'woocommerce') . '</h2>' . PHP_EOL;
foreach ($bacs_accounts as $bacs_account) {
$bacs_account = (object) $bacs_account;
if ($bacs_account->account_name || $bacs_account->bank_name) {
echo '<h3>' . wp_unslash(implode(' - ', array_filter(array($bacs_account->account_name, $bacs_account->bank_name)))) . '</h3>' . PHP_EOL;
}
echo '<ul class="order_details bacs_details">' . PHP_EOL;
// BACS account fields shown on the thanks page and in emails
$account_fields = apply_filters('woocommerce_bacs_account_fields', array('account_number' => array('label' => __('Account Number', 'woocommerce'), 'value' => $bacs_account->account_number), 'sort_code' => array('label' => $sortcode, 'value' => $bacs_account->sort_code), 'iban' => array('label' => __('IBAN', 'woocommerce'), 'value' => $bacs_account->iban), 'bic' => array('label' => __('BIC', 'woocommerce'), 'value' => $bacs_account->bic)), $order_id);
foreach ($account_fields as $field_key => $field) {
if (!empty($field['value'])) {
echo '<li class="' . esc_attr($field_key) . '">' . esc_attr($field['label']) . ': <strong>' . wptexturize($field['value']) . '</strong></li>' . PHP_EOL;
}
}
echo '</ul>';
}
}
}
示例5: _add_recipient_partner
function _add_recipient_partner($emails, $objects)
{
$order_id = isset($objects->id) ? $objects->id : false;
if ($order_id) {
// change order currency
if ($currency = get_post_meta($order_id, '_order_currency', true)) {
TravelHelper::change_current_currency($currency);
}
$order = wc_get_order($order_id);
if (sizeof($order->get_items()) > 0) {
$partner_email_array = array();
foreach ($order->get_items() as $item_id => $item) {
if (!empty($item['item_meta']['_st_st_booking_id'][0]) and $st_booking_id = $item['item_meta']['_st_st_booking_id'][0]) {
$post_type = !empty($item['item_meta']['_st_st_booking_post_type']) ? $item['item_meta']['_st_st_booking_post_type'] : false;
$post_type = st_wc_parse_order_item_meta($post_type);
$partner_email = apply_filters('st_get_owner_email_' . $post_type, $st_booking_id);
if ($partner_email != $st_booking_id) {
if (!in_array($partner_email, $partner_email_array)) {
$partner_email_array[] = $partner_email;
}
}
}
}
if (!empty($partner_email_array)) {
$emails .= ',' . implode(',', $partner_email_array);
}
}
}
return $emails;
}
示例6: complete_order_if_admin
public function complete_order_if_admin($order_id)
{
if (current_user_can('manage_options')) {
$order = wc_get_order($order_id);
$order->payment_complete();
}
}
示例7: get_endpoint_title
/**
* Get page title for an endpoint.
* @param string
* @return string
*/
public function get_endpoint_title($endpoint)
{
global $wp;
switch ($endpoint) {
case 'order-pay':
$title = __('Pay for Order', 'woocommerce');
break;
case 'order-received':
$title = __('Order Received', 'woocommerce');
break;
case 'view-order':
$order = wc_get_order($wp->query_vars['view-order']);
$title = $order ? sprintf(__('Order #%s', 'woocommerce'), $order->get_order_number()) : '';
break;
case 'edit-account':
$title = __('Edit Account Details', 'woocommerce');
break;
case 'edit-address':
$title = __('Edit Address', 'woocommerce');
break;
case 'add-payment-method':
$title = __('Add Payment Method', 'woocommerce');
break;
case 'lost-password':
$title = __('Lost Password', 'woocommerce');
break;
default:
$title = '';
break;
}
return $title;
}
示例8: save_downloadable_product_permissions
/**
* Save the download permissions on the individual subscriptions as well as the order. Hooked into
* 'woocommerce_grant_product_download_permissions', which is strictly after the order received all the info
* it needed, so we don't need to play with priorities.
*
* @param integer $order_id the ID of the order. At this point it is guaranteed that it has files in it and that it hasn't been granted permissions before
*/
public static function save_downloadable_product_permissions($order_id)
{
global $wpdb;
$order = wc_get_order($order_id);
if (wcs_order_contains_subscription($order, 'any')) {
$subscriptions = wcs_get_subscriptions_for_order($order, array('order_type' => array('any')));
} else {
return;
}
foreach ($subscriptions as $subscription) {
if (sizeof($subscription->get_items()) > 0) {
foreach ($subscription->get_items() as $item) {
$_product = $subscription->get_product_from_item($item);
if ($_product && $_product->exists() && $_product->is_downloadable()) {
$downloads = $_product->get_files();
$product_id = wcs_get_canonical_product_id($item);
foreach (array_keys($downloads) as $download_id) {
// grant access on subscription if it does not already exist
if (!$wpdb->get_var($wpdb->prepare("SELECT download_id FROM {$wpdb->prefix}woocommerce_downloadable_product_permissions WHERE `order_id` = %d AND `product_id` = %d AND `download_id` = '%s'", $subscription->id, $product_id, $download_id))) {
wc_downloadable_file_permission($download_id, $product_id, $subscription, $item['qty']);
}
self::revoke_downloadable_file_permission($product_id, $order_id, $order->user_id);
}
}
}
}
update_post_meta($subscription->id, '_download_permissions_granted', 1);
}
}
示例9: output
/**
* Output the shortcode.
*
* @param array $atts
*/
public static function output($atts)
{
// Check cart class is loaded or abort
if (is_null(WC()->cart)) {
return;
}
extract(shortcode_atts(array(), $atts));
global $post;
if (!empty($_REQUEST['orderid']) && isset($_POST['_wpnonce']) && wp_verify_nonce($_POST['_wpnonce'], 'woocommerce-order_tracking')) {
$order_id = empty($_REQUEST['orderid']) ? 0 : esc_attr($_REQUEST['orderid']);
$order_email = empty($_REQUEST['order_email']) ? '' : esc_attr($_REQUEST['order_email']);
if (!$order_id) {
echo '<p class="woocommerce-error">' . __('Please enter a valid order ID', 'woocommerce') . '</p>';
} elseif (!$order_email) {
echo '<p class="woocommerce-error">' . __('Please enter a valid order email', 'woocommerce') . '</p>';
} else {
$order = wc_get_order(apply_filters('woocommerce_shortcode_order_tracking_order_id', $order_id));
if ($order && $order->get_id() && $order_email) {
if (strtolower($order->get_billing_email()) == strtolower($order_email)) {
do_action('woocommerce_track_order', $order->get_id());
wc_get_template('order/tracking.php', array('order' => $order));
return;
}
} else {
echo '<p class="woocommerce-error">' . sprintf(__('Sorry, we could not find that order ID in our database.', 'woocommerce'), get_permalink($post->ID)) . '</p>';
}
}
}
wc_get_template('order/form-tracking.php');
}
示例10: create_export_customers_tool
/**
* create_export_customers_tool.
*
* @version 2.3.9
* @since 2.3.9
*/
function create_export_customers_tool()
{
$html = '';
$html .= '<pre>';
$html .= __('Nr.', 'woocommerce-jetpack') . ',' . __('Email', 'woocommerce-jetpack') . ',' . __('First Name', 'woocommerce-jetpack') . ',' . __('Last Name', 'woocommerce-jetpack') . ',' . __('Order Date', 'woocommerce-jetpack') . PHP_EOL;
$total_customers = 0;
$orders = array();
$offset = 0;
$block_size = 96;
while (true) {
$args_orders = array('post_type' => 'shop_order', 'post_status' => 'any', 'posts_per_page' => $block_size, 'orderby' => 'date', 'order' => 'DESC', 'offset' => $offset);
$loop_orders = new WP_Query($args_orders);
if (!$loop_orders->have_posts()) {
break;
}
while ($loop_orders->have_posts()) {
$loop_orders->the_post();
$order_id = $loop_orders->post->ID;
$order = wc_get_order($order_id);
if (isset($order->billing_email) && '' != $order->billing_email && !in_array($order->billing_email, $orders)) {
$emails_to_skip = array();
if (!in_array($order->billing_email, $emails_to_skip)) {
$total_customers++;
$html .= $total_customers . ',' . $order->billing_email . ',' . $order->billing_first_name . ',' . $order->billing_last_name . ',' . get_the_date('Y/m/d') . PHP_EOL;
$orders[] = $order->billing_email;
}
}
}
$offset += $block_size;
}
$html .= '</pre>';
echo $html;
}
示例11: wc_reduce_stock_levels
/**
* Reduce stock levels for items within an order.
* @since 2.7.0
* @param int $order_id
*/
function wc_reduce_stock_levels($order_id)
{
$order = wc_get_order($order_id);
if ('yes' === get_option('woocommerce_manage_stock') && $order && apply_filters('woocommerce_can_reduce_order_stock', true, $order) && sizeof($order->get_items()) > 0) {
foreach ($order->get_items() as $item) {
if ($item->is_type('line_item') && ($product = $item->get_product()) && $product->managing_stock()) {
$qty = apply_filters('woocommerce_order_item_quantity', $item->get_quantity(), $order, $item);
$item_name = $product->get_formatted_name();
$new_stock = wc_update_product_stock($product, $qty, 'decrease');
if (!is_wp_error($new_stock)) {
/* translators: 1: item name 2: old stock quantity 3: new stock quantity */
$order->add_order_note(sprintf(__('%1$s stock reduced from %2$s to %3$s.', 'woocommerce'), $item_name, $new_stock + $qty, $new_stock));
if ('' !== get_option('woocommerce_notify_no_stock_amount') && $new_stock <= get_option('woocommerce_notify_no_stock_amount')) {
do_action('woocommerce_no_stock', $product);
} elseif ('' !== get_option('woocommerce_notify_low_stock_amount') && $new_stock <= get_option('woocommerce_notify_low_stock_amount')) {
do_action('woocommerce_low_stock', $product);
}
if ($new_stock < 0) {
do_action('woocommerce_product_on_backorder', array('product' => $product, 'order_id' => $order_id, 'quantity' => $qty_ordered));
}
}
}
}
do_action('woocommerce_reduce_order_stock', $order);
}
}
示例12: trigger
/**
* Trigger.
*
* @version 2.4.0
*/
function trigger($order_id)
{
if ($order_id) {
$this->object = wc_get_order($order_id);
if ($this->customer_email) {
$this->recipient = $this->object->billing_email;
}
$this->find['order-date'] = '{order_date}';
$this->find['order-number'] = '{order_number}';
$this->replace['order-date'] = date_i18n(wc_date_format(), strtotime($this->object->order_date));
$this->replace['order-number'] = $this->object->get_order_number();
}
if (!$this->is_enabled() || !$this->get_recipient()) {
return;
}
if ($order_id) {
global $post;
$order = wc_get_order($order_id);
$post = $order->post;
setup_postdata($post);
}
$this->send($this->get_recipient(), $this->get_subject(), do_shortcode($this->get_content()), $this->get_headers(), $this->get_attachments());
if ($order_id) {
wp_reset_postdata();
}
}
示例13: get_paypal_order
/**
* Get the order from the PayPal 'Custom' variable
*
* @param string $raw_custom JSON Data passed back by PayPal
* @return bool|WC_Order object
*/
protected function get_paypal_order($raw_custom)
{
// We have the data in the correct format, so get the order
if (($custom = json_decode($raw_custom)) && is_object($custom)) {
$order_id = $custom->order_id;
$order_key = $custom->order_key;
// Fallback to serialized data if safe. This is @deprecated in 2.3.11
} elseif (preg_match('/^a:2:{/', $raw_custom) && !preg_match('/[CO]:\\+?[0-9]+:"/', $raw_custom) && ($custom = maybe_unserialize($raw_custom))) {
$order_id = $custom[0];
$order_key = $custom[1];
// Nothing was found
} else {
WC_Gateway_Paypal::log('Error: Order ID and key were not found in "custom".');
return false;
}
if (!($order = wc_get_order($order_id))) {
// We have an invalid $order_id, probably because invoice_prefix has changed
$order_id = wc_get_order_id_by_order_key($order_key);
$order = wc_get_order($order_id);
}
if (!$order || $order->order_key !== $order_key) {
WC_Gateway_Paypal::log('Error: Order Keys do not match.');
return false;
}
return $order;
}
示例14: render_order_columns
/**
* Output custom columns for orders
*
* @param string $column
* @version 2.2.6
* @since 2.2.4
*/
public function render_order_columns($column)
{
if ('profit' === $column) {
$total_profit = 0;
$the_order = wc_get_order(get_the_ID());
if ('completed' === $the_order->get_status()) {
$is_forecasted = false;
foreach ($the_order->get_items() as $item_id => $item) {
// $product = $this->get_product_from_item( $item );
$the_profit = 0;
if (0 != ($purchase_price = wc_get_product_purchase_price($item['product_id']))) {
$the_profit = $item['line_total'] + $item['line_tax'] - $purchase_price * $item['qty'];
// $total_profit += $the_profit;
// echo $item['line_total'] . ' ~ ' . $purchase_price . ' ~ ' . $item['qty'];
} else {
//$the_profit = ( $item['line_total'] + $item['line_tax'] ) * 0.2;
$is_forecasted = true;
}
$total_profit += $the_profit;
}
}
if (0 != $total_profit) {
if (!$is_forecasted) {
echo '<span style="color:green;">';
}
echo wc_price($total_profit);
if (!$is_forecasted) {
echo '</span>';
}
}
}
}
示例15: get_order
/**
* Get parent order object.
* @return int
*/
public function get_order()
{
if (!$this->_order) {
$this->_order = wc_get_order($this->get_order_id());
}
return $this->_order;
}