Exemplo n.º 1
0
 /**
  * Main WooCommerce Instance
  *
  * Ensures only one instance of WooCommerce is loaded or can be loaded.
  *
  * @since 2.1
  * @static
  * @see WC()
  * @return WooCommerce - Main instance
  */
 public static function instance()
 {
     if (is_null(self::$_instance)) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
Exemplo n.º 2
0
 /**
  * @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];
     }
 }
Exemplo n.º 3
0
 /**
  * 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;
 }
Exemplo n.º 4
0
 /**
  * @return string
  */
 public function getWooCommerceVersion()
 {
     return WooCommerce::instance()->version;
 }
Exemplo n.º 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;
 }
Exemplo n.º 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;
         }
     }
 }
Exemplo n.º 8
0
 /**
  * Get the WooCommerce instance without using the $wocommerce global variable
  * @return WooCommerce
  */
 function WC()
 {
     return WooCommerce::instance();
 }
Exemplo n.º 9
0
        url
      FROM woo
      ORDER by woo_id ASC';
        $res = $this->sqlite->query($woo_api_stores);
        while ($row = $res->fetchArray()) {
            echo "{$row['woo_id']}: {$row['url']}\n";
        }
    }
}
function usage()
{
    global $argv;
    echo "Usage: {$argv[0]} COMMAND\n\nCOMMAND can be one of:\nID: Numeric ID of store\nlist: List stores\n";
}
try {
    $wc = new WooCommerce();
    if (2 > count($argv)) {
        usage();
    } else {
        if ('list' == $argv[1]) {
            $wc->list_stores();
        } else {
            if (true == is_numeric($argv[1])) {
                $wc->sync((int) $argv[1]);
            } else {
                usage();
            }
        }
    }
} catch (Exception $e) {
    die("An error occurred: " . $e->getMessage());
Exemplo n.º 10
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;