instance() public static méthode

Ensures only one instance of WooCommerce is loaded or can be loaded.
See also: WC()
Since: 2.1
public static instance ( ) : WooCommerce
Résultat WooCommerce - Main instance.
 /**
  * @param \ET_Order $paymentType
  */
 function __construct($paymentType)
 {
     $this->_payment_type = $paymentType;
     $this->gatewayType = $paymentType;
     $available_payment_gateways = WooCommerce::instance()->payment_gateways()->get_available_payment_gateways();
     // $paymentType_lower = strtolower($paymentType);
     if (array_key_exists($paymentType, $available_payment_gateways)) {
         $this->gateway = $available_payment_gateways[$paymentType];
     }
 }
/**
 * Returns the main instance of WC to prevent the need to use globals.
 *
 * @since  2.1
 * @return WooCommerce
 */
function WC()
{
    return WooCommerce::instance();
}
 /**
  * Determine the total number of the specified ticket contained in orders which have
  * progressed to a "completed" or "incomplete" status.
  *
  * Essentially this returns the total quantity of tickets held within orders that are
  * complete or incomplete (incomplete are: "pending", "on hold" or "processing").
  *
  * @param int $ticket_id
  * @param string $status Types of orders: incomplete or complete
  * @return int
  */
 protected function count_order_items_by_status($ticket_id, $status = 'incomplete')
 {
     $totals = array('total' => 0, 'recorded_sales' => 0, 'reduced_stock' => 0);
     $incomplete_orders = version_compare('2.2', WooCommerce::instance()->version, '<=') ? $this->get_orders_by_status($ticket_id, $status) : $this->backcompat_get_orders_by_status($ticket_id, $status);
     foreach ($incomplete_orders as $order_id) {
         $order = new WC_Order($order_id);
         $has_recorded_sales = 'yes' === get_post_meta($order_id, '_recorded_sales', true);
         $has_reduced_stock = (bool) get_post_meta($order_id, '_order_stock_reduced', true);
         foreach ((array) $order->get_items() as $order_item) {
             if ($order_item['product_id'] == $ticket_id) {
                 $totals['total'] += (int) $order_item['qty'];
                 if ($has_recorded_sales) {
                     $totals['recorded_sales'] += (int) $order_item['qty'];
                 }
                 if ($has_reduced_stock) {
                     $totals['reduced_stock'] += (int) $order_item['qty'];
                 }
             }
         }
     }
     return $totals;
 }
Exemple #4
0
 /**
  * @return string
  */
 public function getWooCommerceVersion()
 {
     return WooCommerce::instance()->version;
 }
Exemple #5
0
 /**
  * Determine the total number of the specified ticket contained in orders which have not
  * progressed to a "completed" status.
  *
  * Essentially this returns the total quantity of tickets held within orders that are
  * "pending", "on hold" or "processing".
  *
  * @param $ticket_id
  * @return int
  */
 protected function count_incomplete_order_items($ticket_id)
 {
     $total = 0;
     $incomplete_orders = version_compare('2.2', WooCommerce::instance()->version, '<=') ? $this->get_incomplete_orders($ticket_id) : $this->backcompat_get_incomplete_orders($ticket_id);
     foreach ($incomplete_orders as $order_id) {
         $order = new WC_Order($order_id);
         foreach ((array) $order->get_items() as $order_item) {
             if ($order_item['product_id'] == $ticket_id) {
                 $total += (int) $order_item['qty'];
             }
         }
     }
     return $total;
 }
 /**
  *
  * Build the visistor
  *
  * @author : Nguyễn Văn Được
  *
  * @param $class
  * @param $paymentType
  * @param $order
  *
  * @return \WC_Integrate_Visitor
  */
 function build_payment_visitor($class, $paymentType, $order)
 {
     if ($class instanceof ET_InvalidVisitor) {
         if (class_exists("WooCommerce")) {
             $available_payment_gateways = WooCommerce::instance()->payment_gateways()->get_available_payment_gateways();
             $paymentType_lower = strtolower($paymentType);
             if (array_key_exists($paymentType_lower, $available_payment_gateways)) {
                 $class = new WC_Integrate_Visitor($paymentType);
             }
         }
     }
     return $class;
 }
Exemple #7
0
 /**
  * Add a WooCommerce notification message
  *
  * @param string $message Notification message
  * @param string $type One of notice, error or success (default notice)
  * @return $this
  */
 public static function addNotice($message, $type = 'notice')
 {
     $type = in_array($type, array('notice', 'error', 'success')) ? $type : 'notice';
     // Check for existence of new notification api (WooCommerce >= 2.1)
     if (function_exists('wc_add_notice')) {
         wc_add_notice($message, $type);
     } else {
         $woocommerce = WooCommerce::instance();
         switch ($type) {
             case 'error':
                 $woocommerce->add_error($message);
                 break;
             default:
                 $woocommerce->add_message($message);
                 break;
         }
     }
 }
Exemple #8
0
<?php

global $woocommerce, $king;
if (empty($woocommerce)) {
    if (class_exists('WooCommerce')) {
        $woocommerce = WooCommerce::instance();
    }
    if (class_exists('Woocommerce')) {
        $woocommerce = new Woocommerce();
    }
    if (empty($woocommerce)) {
        return;
    }
}
$king->woo = (int) substr(str_replace('.', '', $woocommerce->version . '000'), 0, 3);
if ($king->woo >= 210) {
    add_theme_support('woocommerce');
    include 'woo-functions.php';
}
function woo_gate($f, $no = false)
{
    global $woocommerce, $king;
    if ($king->woo < 210) {
        if ($no == true) {
            $theme = wp_get_theme();
            echo '<div class="alert alert-warning" role="alert">';
            echo esc_html($theme->name) . ' Theme Does not support this woocommerce\'s version, Please upgrade to newest version of Woocommerce plugin!</div>';
        }
        $baseName = substr($f, strpos($f, 'woocommerce') + 12);
        include $woocommerce->plugin_path() . DS . 'templates' . DS . $baseName;
        return false;