本文整理汇总了PHP中WC_Order类的典型用法代码示例。如果您正苦于以下问题:PHP WC_Order类的具体用法?PHP WC_Order怎么用?PHP WC_Order使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WC_Order类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: add_edit_address_subscription_action
/**
* Add a "Change Shipping Address" button to the "My Subscriptions" table for those subscriptions
* which require shipping.
*
* @param array $all_actions The $subscription_key => $actions array with all actions that will be displayed for a subscription on the "My Subscriptions" table
* @param array $subscriptions All of a given users subscriptions that will be displayed on the "My Subscriptions" table
* @since 1.3
*/
public static function add_edit_address_subscription_action($all_actions, $subscriptions)
{
foreach ($all_actions as $subscription_key => $actions) {
$order = new WC_Order($subscriptions[$subscription_key]['order_id']);
$needs_shipping = false;
foreach ($order->get_items() as $item) {
if ($item['product_id'] !== $subscriptions[$subscription_key]['product_id']) {
continue;
}
$product = $order->get_product_from_item($item);
if (!is_object($product)) {
// In case a product has been deleted
continue;
}
if ($product->needs_shipping()) {
$needs_shipping = true;
}
}
if ($needs_shipping && in_array($subscriptions[$subscription_key]['status'], array('active', 'on-hold'))) {
// WC 2.1+
if (function_exists('wc_get_endpoint_url')) {
$all_actions[$subscription_key] = array('change_address' => array('url' => add_query_arg(array('subscription' => $subscription_key), wc_get_endpoint_url('edit-address', 'shipping')), 'name' => __('Change Address', 'woocommerce-subscriptions'))) + $all_actions[$subscription_key];
} else {
$all_actions[$subscription_key] = array('change_address' => array('url' => add_query_arg(array('address' => 'shipping', 'subscription' => $subscription_key), get_permalink(woocommerce_get_page_id('edit_address'))), 'name' => __('Change Address', 'woocommerce-subscriptions'))) + $all_actions[$subscription_key];
}
}
}
return $all_actions;
}
示例2: admin_sms_alert
function admin_sms_alert($order_id)
{
global $woocommerce;
$order = new WC_Order($order_id);
$billing_firstname = get_post_meta($order_id, '_billing_first_name', true);
$billing_lastname = get_post_meta($order_id, '_billing_last_name', true);
$billing_phone = get_post_meta($order_id, '_billing_phone', true);
$shipping_address1 = get_post_meta($order_id, '_billing_address_1', true);
$shipping_address2 = get_post_meta($order_id, '_billing_address_2', true);
$medallion = strtoupper(get_user_meta($order->user_id, 'loyalty_status', true));
$order_amount = get_post_meta($order_id, '_order_total', true);
$pay_type = get_post_meta($order_id, '_payment_method', true);
if ($pay_type == 'cod') {
$pay_method = 'Cash on delivery';
} else {
$pay_method = 'Credit card on delivery';
}
$order_item = $order->get_items();
foreach ($order_item as $product) {
$product_meta[] = $product['name'] . ' (' . strtok($product['item_meta']['size'][0], ' ') . ')';
}
$product_list = implode("\n", $product_meta);
$admin_sms = "New Order #{$order_id}\n" . "{$product_list}\n" . "{$medallion}\n" . "Total \${$order_amount}\n" . "{$pay_method}\n" . "{$billing_firstname} {$billing_lastname}\n" . "{$shipping_address1}" . ($shipping_address2 ? " {$shipping_address2}" : '') . "\n" . "{$billing_phone}";
require 'twilio-php/Services/Twilio.php';
$account_sid = 'AC48732db704fe33f0601c8b61bd1519b8';
$auth_token = 'b881c619f25d20143bbbf6ac4d0d3429';
$admin_phone = array('+13109253443', '+18185102424', '+18183392676');
foreach ($admin_phone as $number) {
$client = new Services_Twilio($account_sid, $auth_token);
$client->account->messages->create(array('To' => $number, 'From' => "+13232104996", 'Body' => $admin_sms));
}
}
示例3: custom_order_actions
/**
* Add custom order actions in order list view
*
* @since 1.0.0
* @param array $actions
* @param \WC_Order $order
* @return array
*/
public function custom_order_actions($actions, WC_Order $order)
{
$status = new WC_Order_Status_Manager_Order_Status($order->get_status());
// Sanity check: bail if no status was found.
// This can happen if some statuses are registered late
if (!$status || !$status->get_id()) {
return $actions;
}
$next_statuses = $status->get_next_statuses();
$order_statuses = wc_get_order_statuses();
$custom_actions = array();
// TODO: Change action to `woocommerce_mark_order_status` for 2.3.x compatibility
// TODO: Change nonce_action to `woocommerce-mark-order-status` for 2.3.x compatibility
$action = 'wc_order_status_manager_mark_order_status';
$nonce_action = 'wc-order-status-manager-mark-order-status';
// Add next statuses as actions
if (!empty($next_statuses)) {
foreach ($next_statuses as $next_status) {
$custom_actions[$next_status] = array('url' => wp_nonce_url(admin_url('admin-ajax.php?action=' . $action . '&status=' . $next_status . '&order_id=' . $order->id), $nonce_action), 'name' => $order_statuses['wc-' . $next_status], 'action' => $next_status);
// Remove duplicate built-in complete action
if ('completed' === $next_status) {
unset($actions['complete']);
}
}
}
// Next status actions are prepended to any existing actions
return $custom_actions + $actions;
}
示例4: order_paid
/**
* Triggered when an order is paid
* @param int $order_id
*/
public function order_paid($order_id)
{
// Get the order
$order = new WC_Order($order_id);
if (get_post_meta($order_id, 'wc_paid_listings_packages_processed', true)) {
return;
}
foreach ($order->get_items() as $item) {
$product = wc_get_product($item['product_id']);
if ($product->is_type(array('job_package', 'resume_package', 'job_package_subscription', 'resume_package_subscription')) && $order->customer_user) {
// Give packages to user
for ($i = 0; $i < $item['qty']; $i++) {
$user_package_id = wc_paid_listings_give_user_package($order->customer_user, $product->id, $order_id);
}
// Approve job or resume with new package
if (isset($item['job_id'])) {
$job = get_post($item['job_id']);
if (in_array($job->post_status, array('pending_payment', 'expired'))) {
wc_paid_listings_approve_job_listing_with_package($job->ID, $order->customer_user, $user_package_id);
}
} elseif (isset($item['resume_id'])) {
$resume = get_post($item['resume_id']);
if (in_array($resume->post_status, array('pending_payment', 'expired'))) {
wc_paid_listings_approve_resume_with_package($resume->ID, $order->customer_user, $user_package_id);
}
}
}
}
update_post_meta($order_id, 'wc_paid_listings_packages_processed', true);
}
示例5: add_meta_boxes
public function add_meta_boxes()
{
global $post;
if (isset($_GET['post'])) {
if (get_post_meta($_GET['post'], '_payment_method', true) == 'inicis_escrow_bank') {
$payment_method = get_post_meta($_GET['post'], '_payment_method', true);
$tmp_settings = get_option('woocommerce_' . $payment_method . '_settings', true);
$refund_mypage_status = $tmp_settings['possible_register_delivery_info_status_for_admin'];
//관리자 배송정보 등록/환불 가능 주문상태 지정
$order = new WC_Order($post->ID);
$paid_order = get_post_meta($post->ID, "_paid_date", true);
if (in_array($order->get_status(), $refund_mypage_status) && !empty($paid_order)) {
add_meta_box('ifw-order-escrow-register-delivery-request', __('이니시스 에스크로', 'codem_inicis'), 'IFW_Meta_Box_Escrow_Register_Delivery::output', 'shop_order', 'side', 'default');
}
} else {
if (get_post_meta($_GET['post'], '_payment_method', true) == 'inicis_vbank') {
add_meta_box('ifw-order-vbank-refund-request', __('가상계좌 무통장입금 환불 처리', 'codem_inicis'), 'IFW_Meta_Box_Vbank_Refund::output', 'shop_order', 'side', 'default');
} else {
if (in_array(get_post_meta($_GET['post'], '_payment_method', true), array('inicis_card', 'inicis_bank', 'inicis_hpp', 'inicis_kpay', 'inicis_stdcard'))) {
$order = new WC_Order($_GET['post']);
if (!in_array($order->get_status(), array('pending', 'on-hold'))) {
add_meta_box('ifw-order-refund-request', __('결제내역', 'codem_inicis'), 'IFW_Meta_Box_Refund::output', 'shop_order', 'side', 'default');
}
}
}
}
}
}
示例6: email_instructions
/**
* Add content to the WC emails.
*
* @access public
* @param WC_Order $order
* @param bool $sent_to_admin
* @param bool $plain_text
*
* @return void
*/
public function email_instructions($order, $sent_to_admin, $plain_text = false)
{
if (!$sent_to_admin && 'bKash' === $order->payment_method && $order->has_status('on-hold')) {
if ($this->instructions) {
echo wpautop(wptexturize($this->instructions)) . PHP_EOL;
}
}
}
示例7: get_product_name
/**
* @since 1.0
* @return string Product Name
*/
private function get_product_name($order_id)
{
$order = new WC_Order($order_id);
$items = $order->get_items();
// Get the first ordered item
$item = array_shift($items);
return $item['name'];
}
开发者ID:KevinFairbanks,项目名称:woocommerce-software-activations,代码行数:12,代码来源:class-wc-software-activations.php
示例8: array
/**
* Track custom user properties via the Mixpanel API
*
* This example illustrates how to add/update the "Last Subscription Billing Amount"
* user property when a subscription is renewed.
*
* @param \WC_Order $renewal_order
* @param \WC_Order $original_order
* @param int $product_id the
* @param \WC_Order $new_order_role
*/
function sv_wc_mixpanel_renewed_subscription($renewal_order, $original_order, $product_id, $new_order_role)
{
if (!function_exists('wc_mixpanel')) {
return;
}
$properties = array('Last Subscription Billing Amount' => $renewal_order->get_total());
wc_mixpanel()->get_integration()->custom_user_properties_api($properties, $renewal_order->user_id);
}
示例9: 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
示例10: email_instructions
/**
* Add content to the WC emails.
*
* Note: The difference from WC_Gateway_BACS is that we use __() before
* passing the string through wptexturize() and wpautop().
*
* @param WC_Order $order
* @param bool $sent_to_admin
* @param bool $plain_text
*/
public function email_instructions($order, $sent_to_admin, $plain_text = false)
{
if (!$sent_to_admin && 'bacs' === $order->payment_method && $order->has_status('on-hold')) {
if ($this->instructions) {
echo wpautop(wptexturize(function_exists('pll__') ? pll__($this->instructions) : __($this->instructions, 'woocommerce'))) . PHP_EOL;
}
$this->bank_details($order->id);
}
}
示例11: output
/**
* Output the shortcode.
*
* @access public
* @param array $atts
* @return void
*/
public static function output($atts)
{
global $woocommerce;
$woocommerce->nocache();
if (!is_user_logged_in()) {
return;
}
extract(shortcode_atts(array('order_count' => 10), $atts));
$user_id = get_current_user_id();
$order_id = isset($_GET['order']) ? $_GET['order'] : 0;
$order = new WC_Order($order_id);
if ($order_id == 0) {
woocommerce_get_template('myaccount/my-orders.php', array('order_count' => 'all' == $order_count ? -1 : $order_count));
return;
}
if ($order->user_id != $user_id) {
echo '<div class="woocommerce-error">' . __('Invalid order.', 'woocommerce') . ' <a href="' . get_permalink(woocommerce_get_page_id('myaccount')) . '">' . __('My Account →', 'woocommerce') . '</a>' . '</div>';
return;
}
$status = get_term_by('slug', $order->status, 'shop_order_status');
echo '<p class="order-info">' . sprintf(__('Order <mark class="order-number">%s</mark> made on <mark class="order-date">%s</mark>', 'woocommerce'), $order->get_order_number(), date_i18n(get_option('date_format'), strtotime($order->order_date))) . '. ' . sprintf(__('Order status: <mark class="order-status">%s</mark>', 'woocommerce'), __($status->name, 'woocommerce')) . '.</p>';
$notes = $order->get_customer_order_notes();
if ($notes) {
?>
<h2><?php
_e('Order Updates', 'woocommerce');
?>
</h2>
<ol class="commentlist notes">
<?php
foreach ($notes as $note) {
?>
<li class="comment note">
<div class="comment_container">
<div class="comment-text">
<p class="meta"><?php
echo date_i18n(__('l jS \\of F Y, h:ia', 'woocommerce'), strtotime($note->comment_date));
?>
</p>
<div class="description">
<?php
echo wpautop(wptexturize($note->comment_content));
?>
</div>
<div class="clear"></div>
</div>
<div class="clear"></div>
</div>
</li>
<?php
}
?>
</ol>
<?php
}
do_action('woocommerce_view_order', $order_id);
}
示例12: get_transaction_url
/**
* Get a link to the transaction on the 3rd party gateway size (if applicable)
*
* @param WC_Order $order the order object
* @return string transaction URL, or empty string
*/
public function get_transaction_url($order)
{
$return_url = '';
$transaction_id = $order->get_transaction_id();
if (!empty($this->view_transaction_url) && !empty($transaction_id)) {
$return_url = sprintf($this->view_transaction_url, $transaction_id);
}
return apply_filters('woocommerce_get_transaction_url', $return_url, $order, $this);
}
示例13: 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);
}
}
}
}
示例14: get_order
/**
* Retrieve an order.
*
* @param int $order_id
* @return WC_Order or null
*/
public static function get_order($order_id = '')
{
$result = null;
$order = new WC_Order($order_id);
if ($order->get_order($order_id)) {
$result = $order;
}
return $result;
}
示例15: thankyou_page
/**
* Output for the order received page.
*/
public function thankyou_page($order_id)
{
$order = new WC_Order($order_id);
if ('completed' == $order->get_status()) {
echo '<p>' . __('Your booking has been confirmed. Thank you.', 'woocommerce-bookings') . '</p>';
} else {
echo '<p>' . __('Your booking is awaiting confirmation. You will be notified by email as soon as we\'ve confirmed availability.', 'woocommerce-bookings') . '</p>';
}
}