/**
  * Output the POS template
  */
 public function template_redirect()
 {
     // check is pos
     if (!is_pos('template')) {
         return;
     }
     // check auth
     if (!is_user_logged_in()) {
         add_filter('login_url', array($this, 'login_url'));
         auth_redirect();
     }
     // check privileges
     if (!current_user_can('access_woocommerce_pos')) {
         /* translators: wordpress */
         wp_die(__('You do not have sufficient permissions to access this page.'));
     }
     // disable cache plugins
     $this->no_cache();
     // last chance before template is rendered
     do_action('woocommerce_pos_template_redirect');
     // add head & footer actions
     add_action('woocommerce_pos_head', array($this, 'head'));
     add_action('woocommerce_pos_footer', array($this, 'footer'));
     // now show the page
     include 'views/template.php';
     exit;
 }
Пример #2
0
 /**
  *
  */
 public function __construct()
 {
     if (!is_pos()) {
         return;
     }
     // support for X-HTTP-Method-Override for WC < 2.4
     if (version_compare(WC()->version, '2.4', '<') && isset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])) {
         $_GET['_method'] = $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'];
     }
     add_filter('woocommerce_api_dispatch_args', array($this, 'dispatch_args'), 10, 2);
     add_filter('woocommerce_api_query_args', array($this, 'woocommerce_api_query_args'), 10, 2);
 }
Пример #3
0
 /**
  *
  */
 public function __construct()
 {
     if (!is_pos()) {
         return;
     }
     // remove wc api authentication
     // - relies on ->api and ->authentication being publicly accessible
     if (isset(WC()->api) && isset(WC()->api->authentication)) {
         remove_filter('woocommerce_api_check_authentication', array(WC()->api->authentication, 'authenticate'), 0);
     }
     // support for X-HTTP-Method-Override for WC < 2.4
     if (version_compare(WC()->version, '2.4', '<') && isset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])) {
         $_GET['_method'] = $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'];
     }
     add_filter('woocommerce_api_check_authentication', array($this, 'wc_api_authentication'), 10, 0);
     add_filter('woocommerce_api_dispatch_args', array($this, 'dispatch_args'), 10, 2);
     add_filter('woocommerce_api_query_args', array($this, 'woocommerce_api_query_args'), 10, 2);
 }
 /**
  * Show/hide POS products
  *
  * @param $where
  * @param $query
  *
  * @return string
  */
 public function posts_where($where, $query)
 {
     global $wpdb;
     // only alter product queries
     if (is_array($query->get('post_type')) && !in_array('product', $query->get('post_type'))) {
         return $where;
     }
     if (!is_array($query->get('post_type')) && $query->get('post_type') !== 'product') {
         return $where;
     }
     // don't alter product queries in the admin
     if (is_admin() && !is_pos()) {
         return $where;
     }
     // hide products
     if (is_pos()) {
         $hide = 'online_only';
     } else {
         $hide = 'pos_only';
     }
     $where .= " AND ID NOT IN (SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = '_pos_visibility' AND meta_value = '{$hide}')";
     return $where;
 }
 /**
  * Constructor
  */
 public function __construct()
 {
     // this should only be init after woocommerce_init
     global $wp_actions;
     if (!isset($wp_actions['woocommerce_init'])) {
         return;
     }
     // common params
     $this->accounting = $this->accounting();
     $this->ajaxurl = admin_url('admin-ajax.php', 'relative');
     $this->customers = $this->customers();
     $this->debug = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG;
     $this->nonce = wp_create_nonce(WC_POS_PLUGIN_NAME);
     $this->wc_api = get_woocommerce_api_url('');
     $this->emulateHTTP = get_option('woocommerce_pos_emulateHTTP') === '1';
     $this->idbVersion = WC_POS_Settings::get_idb_version();
     // frontend params
     if (is_pos()) {
         $this->auto_print = wc_pos_get_option('checkout', 'auto_print_receipt');
         $this->denominations = WC_POS_i18n::currency_denominations();
         $this->discount_keys = wc_pos_get_option('general', 'discount_quick_keys');
         $this->hotkeys = wc_pos_get_option('hotkeys', 'hotkeys');
         $this->menu = $this->menu();
         $this->shipping = $this->shipping_labels();
         $this->store = array('name' => get_bloginfo('name'));
         $this->tabs = $this->product_tabs();
         $this->tax = $this->tax();
         $this->tax_classes = WC_POS_Tax::tax_classes();
         $this->tax_rates = WC_POS_Tax::tax_rates();
         $this->user = $this->user();
     }
     // admin params
     if (is_admin()) {
         $this->search_customers_nonce = wp_create_nonce('search-customers');
     }
 }
Пример #6
0
function mod($num, $div)
{
    // (let [m (rem num div)]
    //   (if (or (zero? m) (= (pos? num) (pos? div)))
    //     m
    //     (+ m div))))
    $m = rem($num, $div);
    if (is_zero($m) || is_pos($num) === is_pos($div)) {
        return $m;
    }
    return $m + $div;
}
Пример #7
0
 /**
  * Bypass authentication for WC REST API
  *
  * @param $user
  *
  * @return WP_User object
  */
 public function wc_api_authentication($user, $wc_api)
 {
     if (is_pos()) {
         global $current_user;
         $user = $current_user;
         if (!user_can($user->ID, 'access_woocommerce_pos')) {
             $user = new WP_Error('woocommerce_pos_authentication_error', __('User not authorized to access WooCommerce POS', 'woocommerce-pos'), array('status' => 401));
         }
     }
     return $user;
 }