本文整理汇总了PHP中WC_Subscriptions_Order::order_contains_subscription方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Subscriptions_Order::order_contains_subscription方法的具体用法?PHP WC_Subscriptions_Order::order_contains_subscription怎么用?PHP WC_Subscriptions_Order::order_contains_subscription使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WC_Subscriptions_Order
的用法示例。
在下文中一共展示了WC_Subscriptions_Order::order_contains_subscription方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: add_order_meta
/**
* When a new order is inserted, add the subscriptions period to the order.
*
* It's important that the period is tied to the order so that changing the products
* period does not change the past.
*
* @since 1.0
*/
public static function add_order_meta($order_id)
{
global $woocommerce;
if (WC_Subscriptions_Order::order_contains_subscription($order_id)) {
$order = new WC_Order($order_id);
$order_subscription_periods = array();
$order_subscription_intervals = array();
$order_subscription_lengths = array();
$order_subscription_trial_lengths = array();
foreach ($order->get_items() as $item) {
$period = WC_Subscriptions_Product::get_period($item['id']);
if (!empty($period)) {
$order_subscription_periods[$item['id']] = $period;
}
$interval = WC_Subscriptions_Product::get_interval($item['id']);
if (!empty($interval)) {
$order_subscription_intervals[$item['id']] = $interval;
}
$length = WC_Subscriptions_Product::get_length($item['id']);
if (!empty($length)) {
$order_subscription_lengths[$item['id']] = $length;
}
$trial_length = WC_Subscriptions_Product::get_trial_length($item['id']);
if (!empty($trial_length)) {
$order_subscription_trial_lengths[$item['id']] = $trial_length;
}
}
update_post_meta($order_id, '_order_subscription_periods', $order_subscription_periods);
update_post_meta($order_id, '_order_subscription_intervals', $order_subscription_intervals);
update_post_meta($order_id, '_order_subscription_lengths', $order_subscription_lengths);
update_post_meta($order_id, '_order_subscription_trial_lengths', $order_subscription_trial_lengths);
// Store sign-up fee details
foreach (WC_Subscriptions_Cart::get_sign_up_fee_fields() as $field_name) {
update_post_meta($order_id, "_{$field_name}", $woocommerce->cart->{$field_name});
}
// Prepare sign up fee taxes to store in same format as order taxes
$sign_up_fee_taxes = array();
foreach (array_keys($woocommerce->cart->sign_up_fee_taxes) as $key) {
$is_compound = $woocommerce->cart->tax->is_compound($key) ? 1 : 0;
$sign_up_fee_taxes[] = array('label' => $woocommerce->cart->tax->get_rate_label($key), 'compound' => $is_compound, 'cart_tax' => number_format($woocommerce->cart->sign_up_fee_taxes[$key], 2, '.', ''));
}
update_post_meta($order_id, '_sign_up_fee_taxes', $sign_up_fee_taxes);
}
}
示例2: process_payment
/**
* Process payment for an order:
* 1) If the order contains a subscription, process the initial subscription payment (could be $0 if a free trial exists)
* 2) If the order contains a pre-order, process the pre-order total (could be $0 if the pre-order is charged upon release)
* 3) Otherwise use the parent::process_payment() method for regular product purchases
*
* @since 2.0
* @param int $order_id
* @return array
*/
public function process_payment($order_id)
{
global $wc_braintree;
$order = $this->get_order($order_id);
try {
/* processing subscription */
if ($wc_braintree->is_subscriptions_active() && WC_Subscriptions_Order::order_contains_subscription($order_id)) {
return $this->process_subscription_payment($order);
/* processing pre-order */
} elseif ($wc_braintree->is_pre_orders_active() && WC_Pre_Orders_Order::order_contains_pre_order($order_id)) {
return $this->process_pre_order_payment($order);
/* processing regular product */
} else {
return parent::process_payment($order_id);
}
} catch (WC_Gateway_Braintree_Exception $e) {
// mark order as failed, which adds an order note for the admin and displays a generic "payment error" to the customer
$this->mark_order_as_failed($order, $e->getMessage());
// add detailed debugging information
$this->add_debug_message($e->getErrors());
} catch (Braintree_Exception_Authorization $e) {
$this->mark_order_as_failed($order, __('Authorization failed, ensure that your API key is correct and has permissions to create transactions.', WC_Braintree::TEXT_DOMAIN));
} catch (Exception $e) {
$this->mark_order_as_failed($order, sprintf(__('Error Type %s', WC_Braintree::TEXT_DOMAIN), get_class($e)));
}
}
示例3: maybe_remove_customer_processing_order
/**
* Removes a couple of notifications that are less relevant for Subscription orders.
*
* @since 1.0
*/
public static function maybe_remove_customer_processing_order($order_id)
{
if (WC_Subscriptions_Order::order_contains_subscription($order_id)) {
remove_action('woocommerce_order_status_pending_to_processing_notification', array(self::$woocommerce_email, 'customer_processing_order'));
remove_action('woocommerce_order_status_pending_to_on-hold_notification', array(self::$woocommerce_email, 'customer_processing_order'));
}
}
示例4: add_order_meta
/**
* When a new order is inserted, add the subscriptions period to the order.
*
* It's important that the period is tied to the order so that changing the products
* period does not change the past.
*
* @since 1.0
*/
public static function add_order_meta($order_id, $posted)
{
global $woocommerce;
if (WC_Subscriptions_Order::order_contains_subscription($order_id)) {
// This works because the 'new_order_item' runs before the 'woocommerce_checkout_update_order_meta' hook
// Set the recurring totals so totals display correctly on order page
update_post_meta($order_id, '_order_recurring_discount_cart', WC_Subscriptions_Cart::get_recurring_discount_cart());
update_post_meta($order_id, '_order_recurring_discount_total', WC_Subscriptions_Cart::get_recurring_discount_total());
update_post_meta($order_id, '_order_recurring_shipping_tax_total', WC_Subscriptions_Cart::get_recurring_shipping_tax_total());
update_post_meta($order_id, '_order_recurring_tax_total', WC_Subscriptions_Cart::get_recurring_total_tax());
update_post_meta($order_id, '_order_recurring_total', WC_Subscriptions_Cart::get_recurring_total());
// Get recurring taxes into same format as _order_taxes
$order_recurring_taxes = array();
foreach (WC_Subscriptions_Cart::get_recurring_taxes() as $tax_key => $tax_amount) {
$is_compound = $woocommerce->cart->tax->is_compound($tax_key) ? 1 : 0;
if (isset($woocommerce->cart->taxes[$tax_key])) {
$cart_tax = $tax_amount;
$shipping_tax = 0;
} else {
$cart_tax = 0;
$shipping_tax = $tax_amount;
}
$order_recurring_taxes[] = array('label' => $woocommerce->cart->tax->get_rate_label($tax_key), 'compound' => $is_compound, 'cart_tax' => woocommerce_format_total($cart_tax), 'shipping_tax' => woocommerce_format_total($shipping_tax));
}
update_post_meta($order_id, '_order_recurring_taxes', $order_recurring_taxes);
$payment_gateways = $woocommerce->payment_gateways->payment_gateways();
if (!$payment_gateways[$posted['payment_method']]->supports('subscriptions')) {
update_post_meta($order_id, '_wcs_requires_manual_renewal', 'true');
}
}
}
示例5: process_payment
/**
* Process the payment
*/
function process_payment($order_id)
{
global $woocommerce;
if (class_exists('WC_Subscriptions_Order') && WC_Subscriptions_Order::order_contains_subscription($order_id)) {
$order = new WC_Order($order_id);
$stripe_token = isset($_POST['stripe_token']) ? woocommerce_clean($_POST['stripe_token']) : '';
// Use Stripe CURL API for payment
try {
$post_data = array();
$customer_id = 0;
// Check if paying via customer ID
if (isset($_POST['stripe_customer_id']) && $_POST['stripe_customer_id'] !== 'new' && is_user_logged_in()) {
$customer_ids = get_user_meta(get_current_user_id(), '_stripe_customer_id', false);
if (isset($customer_ids[$_POST['stripe_customer_id']]['customer_id'])) {
$customer_id = $customer_ids[$_POST['stripe_customer_id']]['customer_id'];
} else {
throw new Exception(__('Invalid card.', 'wc_stripe'));
}
} elseif (empty($stripe_token)) {
throw new Exception(__('Please make sure your card details have been entered correctly and that your browser supports JavaScript.', 'wc_stripe'));
}
if (method_exists('WC_Subscriptions_Order', 'get_total_initial_payment')) {
$initial_payment = WC_Subscriptions_Order::get_total_initial_payment($order);
} else {
$initial_payment = WC_Subscriptions_Order::get_sign_up_fee($order) + WC_Subscriptions_Order::get_price_per_period($order);
}
$customer_response = $this->add_customer_to_order($order, $customer_id, $stripe_token);
if ($initial_payment > 0) {
$payment_response = $this->process_subscription_payment($order, $initial_payment);
}
if (is_wp_error($customer_response)) {
throw new Exception($customer_response->get_error_message());
} else {
if (isset($payment_response) && is_wp_error($payment_response)) {
throw new Exception($payment_response->get_error_message());
} else {
// Payment complete
$order->payment_complete();
// Remove cart
$woocommerce->cart->empty_cart();
// Activate subscriptions
WC_Subscriptions_Manager::activate_subscriptions_for_order($order);
// Store token
if ($stripe_token) {
update_post_meta($order->id, '_stripe_token', $stripe_token);
}
// Return thank you page redirect
return array('result' => 'success', 'redirect' => $this->get_return_url($order));
}
}
} catch (Exception $e) {
$woocommerce->add_error(__('Error:', 'wc_stripe') . ' "' . $e->getMessage() . '"');
return;
}
} else {
return parent::process_payment($order_id);
}
}
示例6: process_payment
/**
* Process the payment
*
* @param int $order_id
* @return array
*/
public function process_payment($order_id, $retry = true)
{
// Processing subscription
if (class_exists('WC_Subscriptions_Order') && WC_Subscriptions_Order::order_contains_subscription($order_id)) {
return $this->process_subscription($order_id, $retry);
// Processing pre-order or standard ordre
} else {
return parent::process_payment($order_id, $retry);
}
}
示例7: get_available_payment_gateways
/**
* Only display the gateways which support subscriptions if manual payments are not allowed.
*
* @since 1.0
*/
public static function get_available_payment_gateways($available_gateways)
{
$accept_manual_payment = get_option(WC_Subscriptions_Admin::$option_prefix . '_accept_manual_renewals', 'no');
if ('no' == $accept_manual_payment && (WC_Subscriptions_Cart::cart_contains_subscription() || isset($_GET['order_id']) && WC_Subscriptions_Order::order_contains_subscription($_GET['order_id']))) {
foreach ($available_gateways as $gateway_id => $gateway) {
if (!method_exists($gateway, 'supports') || $gateway->supports('subscriptions') !== true) {
unset($available_gateways[$gateway_id]);
}
}
}
return $available_gateways;
}
示例8: get_available_payment_gateways
/**
* Only displays the gateways which support subscriptions.
*
* @since 1.0
*/
public static function get_available_payment_gateways($available_gateways)
{
if (WC_Subscriptions_Cart::cart_contains_subscription() || isset($_GET['order_id']) && WC_Subscriptions_Order::order_contains_subscription($_GET['order_id'])) {
// || WC_Subscriptions_Order::order_contains_subscription( $order_id )
foreach ($available_gateways as $gateway_id => $gateway) {
if (!method_exists($gateway, 'supports') || $gateway->supports('subscriptions') !== true) {
unset($available_gateways[$gateway_id]);
}
}
}
return $available_gateways;
}
示例9: process_payment
/**
* Process the payment and return the result
*
* @access public
* @param int $order_id
* @return array
*/
public function process_payment($order_id)
{
if (WC_Subscriptions_Order::order_contains_subscription($order_id)) {
if ($this->send_to_stripe($order_id)) {
$this->order_complete();
WC_Subscriptions_Manager::activate_subscriptions_for_order($this->order);
$result = array('result' => 'success', 'redirect' => $this->get_return_url($this->order));
return $result;
} else {
$this->payment_failed();
// Add a generic error message if we don't currently have any others
if (wc_notice_count('error') == 0) {
wc_add_notice(__('Transaction Error: Could not complete your subscription payment.', 'stripe-for-woocommerce'), 'error');
}
}
} else {
return parent::process_payment($order_id);
}
}
示例10: process_payment
/**
* Process an initial subscription payment if the order contains a
* subscription, otherwise use the parent::process_payment() method
*
* @since 1.4
* @param int $order_id the order identifier
* @return array
*/
public function process_payment($order_id)
{
require_once 'class-wc-realex-api.php';
// processing subscription (which means we are ineligible for 3DSecure for now)
if (SV_WC_Plugin_Compatibility::is_wc_subscriptions_version_gte_2_0() ? wcs_order_contains_subscription($order_id) : WC_Subscriptions_Order::order_contains_subscription($order_id)) {
$order = wc_get_order($order_id);
// redirect to payment page for payment if 3D secure is enabled
if ($this->get_threedsecure()->is_3dsecure_available() && !SV_WC_Helper::get_post('woocommerce_pay_page')) {
// empty cart before redirecting from Checkout page
WC()->cart->empty_cart();
// redirect to payment page to continue payment
return array('result' => 'success', 'redirect' => $order->get_checkout_payment_url(true));
}
$order->payment_total = SV_WC_Helper::number_format(SV_WC_Plugin_Compatibility::is_wc_subscriptions_version_gte_2_0() ? $order->get_total() : WC_Subscriptions_Order::get_total_initial_payment($order));
// create the realex api client
$realex_client = new Realex_API($this->get_endpoint_url(), $this->get_realvault_endpoint_url(), $this->get_shared_secret());
// create the customer/cc tokens, and authorize the initial payment amount, if any
$result = $this->authorize($realex_client, $order);
// subscription with initial payment, everything is now taken care of
if (is_array($result)) {
// for Subscriptions 2.0.x, save payment token to subscription object
if (SV_WC_Plugin_Compatibility::is_wc_subscriptions_version_gte_2_0()) {
// a single order can contain multiple subscriptions
foreach (wcs_get_subscriptions_for_order($order->id) as $subscription) {
// payment token
update_post_meta($subscription->id, '_realex_cardref', get_post_meta($order->id, '_realex_cardref', true));
}
}
return $result;
}
// otherwise there was no initial payment, so we mark the order as complete, etc
if ($order->payment_total == 0) {
// mark order as having received payment
$order->payment_complete();
WC()->cart->empty_cart();
return array('result' => 'success', 'redirect' => $this->get_return_url($order));
}
} else {
// processing regular product
return parent::process_payment($order_id);
}
}
示例11: request_access_code
public function request_access_code($order, $method = 'ProcessPayment', $trx_type = 'Purchase')
{
$customer_ip = get_post_meta($order->id, '_customer_ip_address', true);
// Check if order is for a subscription, if it is check for fee and charge that
if (class_exists('WC_Subscriptions_Order') && WC_Subscriptions_Order::order_contains_subscription($order->id)) {
if (0 == WC_Subscriptions_Order::get_total_initial_payment($order)) {
$method = 'CreateTokenCustomer';
} else {
$method = 'TokenPayment';
}
$trx_type = 'Recurring';
$order_total = WC_Subscriptions_Order::get_total_initial_payment($order) * 100;
} else {
$order_total = $order->get_total() * 100.0;
}
// set up request object
$request = array('Method' => $method, 'TransactionType' => $trx_type, 'RedirectUrl' => str_replace('https:', 'http:', add_query_arg(array('wc-api' => 'WC_Gateway_EWAY', 'order_id' => $order->id, 'order_key' => $order->order_key, 'sig_key' => md5($order->order_key . 'WOO' . $order->id)), home_url('/'))), 'IPAddress' => $customer_ip, 'DeviceID' => '0b38ae7c3c5b466f8b234a8955f62bdd', 'PartnerID' => '0b38ae7c3c5b466f8b234a8955f62bdd', 'Payment' => array('TotalAmount' => $order_total, 'CurrencyCode' => get_woocommerce_currency(), 'InvoiceDescription' => apply_filters('woocommerce_eway_description', '', $order), 'InvoiceNumber' => ltrim($order->get_order_number(), _x('#', 'hash before order number', 'woocommerce')), 'InvoiceReference' => $order->id), 'Customer' => array('FirstName' => $order->billing_first_name, 'LastName' => $order->billing_last_name, 'CompanyName' => substr($order->billing_company, 0, 50), '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, 'Email' => $order->billing_email, 'Phone' => $order->billing_phone));
// Add customer ID if logged in
if (is_user_logged_in()) {
$request['Options'][] = array('customerID' => get_current_user_id());
}
return $this->perform_request('/CreateAccessCode.json', json_encode($request));
}
示例12: process_payment
/**
* Process the payment and return the result
**/
function process_payment($order_id)
{
global $woocommerce;
$order = new WC_Order($order_id);
if (class_exists("WC_Subscriptions_Order") && WC_Subscriptions_Order::order_contains_subscription($order)) {
// Charge sign up fee + first period here..
// Periodic charging should happen via scheduled_subscription_payment_fatzebra
$amount = (int) (WC_Subscriptions_Order::get_total_initial_payment($order) * 100);
} else {
$amount = (int) ($order->order_total * 100);
}
$page_url = $this->parent_settings["sandbox_mode"] == "yes" ? $this->sandbox_paynow_url : $this->live_paynow_url;
$_SESSION['masterpass_order_id'] = $order_id;
$username = $this->parent_settings["username"];
$currency = $order->get_order_currency();
$reference = (string) $order_id;
$return_args = array('wc-api' => 'WC_FatZebra_MasterPass', "echo[order_id]" => $order_id);
if ($amount === 0) {
$return_args["echo[tokenize]"] = true;
}
$return_path = str_replace('https:', 'http:', add_query_arg($return_args, home_url('/')));
$verification_string = implode(":", array($reference, $amount, $currency, $return_path));
$verification_value = hash_hmac("md5", $verification_string, $this->settings["shared_secret"]);
$redirect = "{$page_url}/{$username}/{$reference}/{$currency}/{$amount}/{$verification_value}?masterpass=true&iframe=true&return_path=" . urlencode($return_path);
if ($amount === 0) {
$redirect .= "&tokenize_only=true";
}
$result = array('result' => 'success', 'redirect' => $redirect);
return $result;
}
示例13: paypal_standard_subscription_args
/**
* Override the default PayPal standard args in WooCommerce for subscription purchases.
*
* @since 1.0
*/
public static function paypal_standard_subscription_args($paypal_args)
{
extract(self::get_order_id_and_key($paypal_args));
if (WC_Subscriptions_Order::order_contains_subscription($order_id)) {
$order = new WC_Order($order_id);
$order_items = $order->get_items();
// Only one subscription allowed in the cart when PayPal Standard is active
$product = $order->get_product_from_item($order_items[0]);
// It's a subscription
$paypal_args['cmd'] = '_xclick-subscriptions';
if (count($order->get_items()) > 1) {
foreach ($order->get_items() as $item) {
if ($item['qty'] > 1) {
$item_names[] = $item['qty'] . ' x ' . $item['name'];
} else {
if ($item['qty'] > 0) {
$item_names[] = $item['name'];
}
}
}
$paypal_args['item_name'] = sprintf(__('Order %s', WC_Subscriptions::$text_domain), $order->get_order_number());
} else {
$paypal_args['item_name'] = $product->get_title();
}
// Subscription unit of duration
switch (strtolower(WC_Subscriptions_Order::get_subscription_period($order))) {
case 'day':
$subscription_period = 'D';
break;
case 'week':
$subscription_period = 'W';
break;
case 'year':
$subscription_period = 'Y';
break;
case 'month':
default:
$subscription_period = 'M';
break;
}
$sign_up_fee = WC_Subscriptions_Order::get_sign_up_fee($order);
$price_per_period = WC_Subscriptions_Order::get_price_per_period($order);
$subscription_interval = WC_Subscriptions_Order::get_subscription_interval($order);
$subscription_length = WC_Subscriptions_Order::get_subscription_length($order);
$subscription_trial_length = WC_Subscriptions_Order::get_subscription_trial_length($order);
if ($subscription_trial_length > 0) {
// Specify a free trial period
$paypal_args['a1'] = $sign_up_fee > 0 ? $sign_up_fee : 0;
// Add the sign up fee to the free trial period
// Sign Up interval
$paypal_args['p1'] = $subscription_trial_length;
// Sign Up unit of duration
$paypal_args['t1'] = $subscription_period;
} elseif ($sign_up_fee > 0) {
// No trial period, so charge sign up fee and per period price for the first period
if ($subscription_length == 1) {
$param_number = 3;
} else {
$param_number = 1;
}
$paypal_args['a' . $param_number] = $price_per_period + $sign_up_fee;
// Sign Up interval
$paypal_args['p' . $param_number] = $subscription_interval;
// Sign Up unit of duration
$paypal_args['t' . $param_number] = $subscription_period;
}
// We have a recurring payment
if (!isset($param_number) || $param_number == 1) {
// Subscription price
$paypal_args['a3'] = $price_per_period;
// Subscription duration
$paypal_args['p3'] = $subscription_interval;
// Subscription period
$paypal_args['t3'] = $subscription_period;
}
// Recurring payments
if ($subscription_length == 1 || $sign_up_fee > 0 && $subscription_trial_length == 0 && $subscription_length == 2) {
// Non-recurring payments
$paypal_args['src'] = 0;
} else {
$paypal_args['src'] = 1;
if ($subscription_length > 0) {
if ($sign_up_fee > 0 && $subscription_trial_length == 0) {
// An initial period is being used to charge a sign-up fee
$subscription_length--;
}
$paypal_args['srt'] = $subscription_length / $subscription_interval;
}
}
// Force return URL so that order description & instructions display
$paypal_args['rm'] = 2;
}
return $paypal_args;
}
示例14: order_contains_subscription
/**
* Check if order contains subscriptions.
*
* @param int $order_id
* @return bool
*/
protected function order_contains_subscription($order_id)
{
return class_exists('WC_Subscriptions_Order') && (WC_Subscriptions_Order::order_contains_subscription($order_id) || WC_Subscriptions_Renewal_Order::is_renewal($order_id));
}
开发者ID:bitoncoin,项目名称:woocommerce,代码行数:10,代码来源:class-wc-addons-gateway-simplify-commerce-deprecated.php
示例15: add_related_orders_meta_box
/**
* Registers the "Renewal Orders" meta box for the "Edit Order" page.
*/
public static function add_related_orders_meta_box()
{
global $current_screen, $post_id;
// Only display the meta box if an order relates to a subscription
if ('shop_order' == $current_screen->id && (WC_Subscriptions_Renewal_Order::is_renewal($post_id, array('order_role' => 'child')) || WC_Subscriptions_Order::order_contains_subscription($post_id))) {
add_meta_box('subscription_renewal_orders', __('Related Subscription Orders', WC_Subscriptions::$text_domain), __CLASS__ . '::related_orders_meta_box', 'shop_order');
}
}