当前位置: 首页>>代码示例>>PHP>>正文


PHP WC_Checkout类代码示例

本文整理汇总了PHP中WC_Checkout的典型用法代码示例。如果您正苦于以下问题:PHP WC_Checkout类的具体用法?PHP WC_Checkout怎么用?PHP WC_Checkout使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了WC_Checkout类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: instance

 /**
  * Gets the main WC_Checkout Instance.
  *
  * @since 2.1
  * @static
  * @return WC_Checkout Main instance
  */
 public static function instance()
 {
     if (is_null(self::$instance)) {
         self::$instance = new self();
         // Hook in actions once.
         add_action('woocommerce_checkout_billing', array(self::$instance, 'checkout_form_billing'));
         add_action('woocommerce_checkout_shipping', array(self::$instance, 'checkout_form_shipping'));
         // woocommerce_checkout_init action is ran once when the class is first constructed.
         do_action('woocommerce_checkout_init', self::$instance);
     }
     return self::$instance;
 }
开发者ID:woocommerce,项目名称:woocommerce,代码行数:19,代码来源:class-wc-checkout.php

示例2: checkout

 /**
  * Get Checkout Class.
  * @return WC_Checkout
  */
 public function checkout()
 {
     return WC_Checkout::instance();
 }
开发者ID:nghieptovan,项目名称:newproject,代码行数:8,代码来源:woocommerce.php

示例3: payment_widget

    /**
     * Output the payment method widget HTML
     */
    public function payment_widget()
    {
        $checkout = WC_Checkout::instance();
        ?>
			<div class="col-2">
				<h3><?php 
        _e('Payment Method', 'woocommerce');
        ?>
</h3>
				<div id="amazon_wallet_widget"></div>
				<input type="hidden" name="amazon_reference_id" value="<?php 
        echo $this->reference_id;
        ?>
" />
			</div>
		</div>

		<?php 
        if (!is_user_logged_in() && $checkout->enable_signup) {
            ?>

			<?php 
            if ($checkout->enable_guest_checkout) {
                ?>

				<p class="form-row form-row-wide create-account">
					<input class="input-checkbox" id="createaccount" <?php 
                checked(true === $checkout->get_value('createaccount') || true === apply_filters('woocommerce_create_account_default_checked', false), true);
                ?>
 type="checkbox" name="createaccount" value="1" /> <label for="createaccount" class="checkbox"><?php 
                _e('Create an account?', 'woocommerce-gateway-amazon-payments-advanced');
                ?>
</label>
				</p>

			<?php 
            }
            ?>

			<?php 
            do_action('woocommerce_before_checkout_registration_form', $checkout);
            ?>

			<?php 
            if (!empty($checkout->checkout_fields['account'])) {
                ?>

				<div class="create-account">

					<h3><?php 
                _e('Create Account', 'woocommerce-gateway-amazon-payments-advanced');
                ?>
</h3>
					<p><?php 
                _e('Create an account by entering the information below. If you are a returning customer please login at the top of the page.', 'woocommerce-gateway-amazon-payments-advanced');
                ?>
</p>

					<?php 
                foreach ($checkout->checkout_fields['account'] as $key => $field) {
                    ?>

						<?php 
                    woocommerce_form_field($key, $field, $checkout->get_value($key));
                    ?>

					<?php 
                }
                ?>

					<div class="clear"></div>

				</div>

			<?php 
            }
            ?>

			<?php 
            do_action('woocommerce_after_checkout_registration_form', $checkout);
            ?>

		<?php 
        }
        ?>
		<?php 
    }
开发者ID:pantelicnevena,项目名称:hanan,代码行数:90,代码来源:amazon-payments-advanced.php

示例4: __construct

 public function __construct()
 {
     _deprecated_function('woocommerce_checkout', '1.4', 'WC_Checkout()');
     parent::__construct();
 }
开发者ID:rosslavery,项目名称:woocommerce,代码行数:5,代码来源:class-wc-checkout.php

示例5: new_order

    /**
     * Prepare recurring amounts, taxes etc for subscription items
     * 
     * @access public
     * @param int $order_id
     * @return void
     */
    public function new_order($order_id)
    {
        global $woocommerce;

        // Iterate over real cart and work with subscription products (if any)
        foreach ($woocommerce->cart->cart_contents as $cart_item_key => $cart_item) {

            $id = !empty($cart_item['variation_id']) ? $cart_item['variation_id'] : $cart_item['product_id'];

            if (Subscriptio_Subscription_Product::is_subscription($id)) {

                $product = new WC_Product($id);

                // Store all required renewal order fields here
                $renewal_order = array(
                    'taxes'     => array(),
                    'shipping'  => array(),
                );

                // Create fake cart to mimic renewal order
                $renewal_cart = new WC_Cart();

                // Add product to cart
                $renewal_cart->add_to_cart(
                    $cart_item['product_id'],
                    $cart_item['quantity'],
                    (isset($cart_item['variation_id']) ? $cart_item['variation_id'] : ''),
                    (isset($cart_item['variation']) ? $cart_item['variation'] : '')
                );

                // Get fake cart item key
                $renewal_cart_item_keys = array_keys($renewal_cart->cart_contents);
                $renewal_cart_item_key = array_shift($renewal_cart_item_keys);

                // Set renewal price
                $renewal_cart->cart_contents[$renewal_cart_item_key]['data']->price = Subscriptio_Subscription_Product::get_recurring_price($id);

                // Add shipping
                if ($product->needs_shipping() && $renewal_cart->needs_shipping()) {

                    // Get instance of checkout object to retrieve shipping options
                    $wc_checkout = WC_Checkout::instance();

                    // Iterate over shipping packages
                    foreach ($woocommerce->shipping->get_packages() as $package_key => $package) {

                        // Check if this rate was selected
                        if (isset($package['rates'][$wc_checkout->shipping_methods[$package_key]])) {

                            // Check if it contains current subscription
                            if (isset($package['contents'][$cart_item_key])) {

                                // Save shipping details for further calculation
                                $shipping_details = array(
                                    'shipping_method'   => $wc_checkout->shipping_methods[$package_key],
                                    'destination'       => $package['destination'],
                                );

                                // Save shipping address
                                $renewal_order['shipping_address'] = array(
                                    // First three lines may need to be changed to make this compatible with shipping extensions that allow multiple shipping addresses
                                    '_shipping_first_name'  => $wc_checkout->posted['ship_to_different_address'] ? $wc_checkout->posted['shipping_first_name'] : $wc_checkout->posted['billing_first_name'],
                                    '_shipping_last_name'   => $wc_checkout->posted['ship_to_different_address'] ? $wc_checkout->posted['shipping_last_name'] : $wc_checkout->posted['billing_last_name'],
                                    '_shipping_company'     => $wc_checkout->posted['ship_to_different_address'] ? $wc_checkout->posted['shipping_company'] : $wc_checkout->posted['billing_company'],
                                    '_shipping_address_1'   => $shipping_details['destination']['address'],
                                    '_shipping_address_2'   => $shipping_details['destination']['address_2'],
                                    '_shipping_city'        => $shipping_details['destination']['city'],
                                    '_shipping_state'       => $shipping_details['destination']['state'],
                                    '_shipping_postcode'    => $shipping_details['destination']['postcode'],
                                    '_shipping_country'     => $shipping_details['destination']['country'],
                                );

                                break;
                            }
                        }
                    }

                    // Got the shipping method and address for the package that contains current subscription?
                    if (!isset($shipping_details)) {
                        continue;
                    }

                    // Get packages based on renewal order details
                    $packages = apply_filters('woocommerce_cart_shipping_packages', array(
                        0 => array(
                            'contents'          => $renewal_cart->get_cart(),
                            'contents_cost'     => isset($renewal_cart->cart_contents[$renewal_cart_item_key]['line_total']) ? $renewal_cart->cart_contents[$renewal_cart_item_key]['line_total'] : 0,
                            'applied_coupons'   => $renewal_cart->applied_coupons,
                            'destination'       => $shipping_details['destination'],
                        ),
                    ));

                    // Now we need to calculate shipping costs but this requires overwriting session variables
//.........这里部分代码省略.........
开发者ID:qhuit,项目名称:dcosta,代码行数:101,代码来源:subscriptio-order-handler.class.php

示例6: create_orders

 public function create_orders()
 {
     global $wpdb, $woocommerce;
     if (empty($this->settings['orders_per_hour'])) {
         return;
     }
     set_time_limit(0);
     $woocommerce->init();
     $woocommerce->frontend_includes();
     $session_class = apply_filters('woocommerce_session_handler', 'WC_Session_Handler');
     // Class instances
     require_once WC()->plugin_path() . '/includes/abstracts/abstract-wc-session.php';
     $woocommerce->session = new WC_Session_Handler();
     $woocommerce->cart = new WC_Cart();
     // Cart class, stores the cart contents
     $woocommerce->customer = new WC_Customer();
     // Customer class, handles data such as customer location
     $woocommerce->countries = new WC_Countries();
     $woocommerce->checkout = new WC_Checkout();
     //$woocommerce->product_factory = new WC_Product_Factory();                      // Product Factory to create new product instances
     $woocommerce->order_factory = new WC_Order_Factory();
     // Order Factory to create new order instances
     $woocommerce->integrations = new WC_Integrations();
     // Integrations class
     // clear cart
     if (!defined('WOOCOMMERCE_CHECKOUT')) {
         define('WOOCOMMERCE_CHECKOUT', true);
     }
     $woocommerce->cart->empty_cart();
     $product_ids = $this->settings['products'];
     if (empty($product_ids)) {
         $products = $wpdb->get_col("SELECT ID FROM {$wpdb->prefix}posts WHERE post_type = 'product'");
         foreach ($products as $product_id) {
             $product_ids[] = $product_id;
         }
     }
     for ($x = 0; $x < $this->settings['orders_per_hour']; $x++) {
         $cart = array();
         $num_products = rand($this->settings['min_order_products'], $this->settings['max_order_products']);
         $create_user = false;
         if ($this->settings['create_users']) {
             $create_user = rand(1, 100) <= 50 ? true : false;
         }
         if ($create_user) {
             $user_id = self::create_user();
         } else {
             $user_id = self::get_random_user();
         }
         // add random products to cart
         for ($i = 0; $i < $num_products; $i++) {
             $idx = rand(0, count($product_ids) - 1);
             $product_id = $product_ids[$idx];
             $woocommerce->cart->add_to_cart($product_id, 1);
         }
         // process checkout
         $data = array('billing_country' => get_user_meta($user_id, 'billing_country', true), 'billing_first_name' => get_user_meta($user_id, 'billing_first_name', true), 'billing_last_name' => get_user_meta($user_id, 'billing_last_name', true), 'billing_company' => '', 'billing_address_1' => get_user_meta($user_id, 'billing_address_1', true), 'billing_address_2' => '', 'billing_city' => get_user_meta($user_id, 'billing_city', true), 'billing_state' => get_user_meta($user_id, 'billing_state', true), 'billing_postcode' => get_user_meta($user_id, 'billing_postcode', true), 'billing_email' => get_user_meta($user_id, 'billing_email', true), 'billing_phone' => get_user_meta($user_id, 'billing_phone', true), 'shipping_country' => get_user_meta($user_id, 'shipping_country', true), 'shipping_first_name' => get_user_meta($user_id, 'shipping_first_name', true), 'shipping_last_name' => get_user_meta($user_id, 'shipping_last_name', true), 'shipping_company' => '', 'shipping_address_1' => get_user_meta($user_id, 'shipping_address_1', true), 'shipping_address_2' => '', 'shipping_city' => get_user_meta($user_id, 'shipping_city', true), 'shipping_state' => get_user_meta($user_id, 'shipping_state', true), 'shipping_postcode' => get_user_meta($user_id, 'shipping_postcode', true), 'shipping_email' => get_user_meta($user_id, 'shipping_email', true), 'shipping_phone' => get_user_meta($user_id, 'shipping_phone', true));
         $checkout = new WC_Checkout();
         $woocommerce->cart->calculate_totals();
         $order_id = $checkout->create_order();
         if ($order_id) {
             update_post_meta($order_id, '_payment_method', 'bacs');
             update_post_meta($order_id, '_payment_method_title', 'Bacs');
             update_post_meta($order_id, '_shipping_method', 'free_shipping');
             update_post_meta($order_id, '_shipping_method_title', 'Free Shipping');
             update_post_meta($order_id, '_customer_user', absint($user_id));
             foreach ($data as $key => $value) {
                 update_post_meta($order_id, '_' . $key, $value);
             }
             do_action('woocommerce_checkout_order_processed', $order_id, $data);
             $order = new WC_Order($order_id);
             // figure out the order status
             $status = 'completed';
             $rand = mt_rand(1, 100);
             $completed_pct = $this->settings['order_completed_pct'];
             // e.g. 90
             $processing_pct = $completed_pct + $this->settings['order_processing_pct'];
             // e.g. 90 + 5
             $failed_pct = $processing_pct + $this->settings['order_failed_pct'];
             // e.g. 95 + 5
             if ($this->settings['order_completed_pct'] > 0 && $rand <= $completed_pct) {
                 $status = 'completed';
             } elseif ($this->settings['order_processing_pct'] > 0 && $rand <= $processing_pct) {
                 $status = 'processing';
             } elseif ($this->settings['order_failed_pct'] > 0 && $rand <= $failed_pct) {
                 $status = 'failed';
             }
             if ($status == 'failed') {
                 $order->update_status($status);
             } else {
                 $order->payment_complete();
                 $order->update_status($status);
             }
         }
         // clear cart
         $woocommerce->cart->empty_cart();
     }
 }
开发者ID:75nineteen,项目名称:order-simulator-woocommerce,代码行数:97,代码来源:woocommerce-order-simulator.php

示例7: instance

 /**
  * Main WooCommerce Instance
  *
  * Ensures only one instance of WooCommerce is loaded or can be loaded.
  *
  * @since 2.1
  * @static
  * @see WC()
  * @return Main WooCommerce instance
  */
 public static function instance()
 {
     if (is_null(self::$_instance)) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
开发者ID:Joaquinsemp,项目名称:patriestausado,代码行数:17,代码来源:class-wc-checkout.php


注:本文中的WC_Checkout类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。