/**
  * Output the shortcode.
  *
  * @param array $atts
  */
 public static function output($atts)
 {
     global $wp;
     // Check cart class is loaded or abort
     if (is_null(WC()->cart)) {
         return;
     }
     // Backwards compat with old pay and thanks link arguments
     if (isset($_GET['order']) && isset($_GET['key'])) {
         wc_deprecated_argument(__CLASS__ . '->' . __FUNCTION__, '2.1', '"order" is no longer used to pass an order ID. Use the order-pay or order-received endpoint instead.');
         // Get the order to work out what we are showing
         $order_id = absint($_GET['order']);
         $order = wc_get_order($order_id);
         if ($order && $order->has_status('pending')) {
             $wp->query_vars['order-pay'] = absint($_GET['order']);
         } else {
             $wp->query_vars['order-received'] = absint($_GET['order']);
         }
     }
     // Handle checkout actions
     if (!empty($wp->query_vars['order-pay'])) {
         self::order_pay($wp->query_vars['order-pay']);
     } elseif (isset($wp->query_vars['order-received'])) {
         self::order_received($wp->query_vars['order-received']);
     } else {
         self::checkout();
     }
 }
Пример #2
0
/**
 * Retrieve page ids - used for myaccount, edit_address, shop, cart, checkout, pay, view_order, terms. returns -1 if no page is found.
 *
 * @param string $page
 * @return int
 */
function wc_get_page_id($page)
{
    if ('pay' == $page || 'thanks' == $page) {
        wc_deprecated_argument(__FUNCTION__, '2.1', 'The "pay" and "thanks" pages are no-longer used - an endpoint is added to the checkout instead. To get a valid link use the WC_Order::get_checkout_payment_url() or WC_Order::get_checkout_order_received_url() methods instead.');
        $page = 'checkout';
    }
    if ('change_password' === $page || 'edit_address' === $page || 'lost_password' === $page) {
        wc_deprecated_argument(__FUNCTION__, '2.1', 'The "change_password", "edit_address" and "lost_password" pages are no-longer used - an endpoint is added to the my-account instead. To get a valid link use the wc_customer_edit_account_url() function instead.');
        $page = 'myaccount';
    }
    $page = apply_filters('woocommerce_get_' . $page . '_page_id', get_option('woocommerce_' . $page . '_page_id'));
    return $page ? absint($page) : -1;
}
Пример #3
0
 /**
  * Auto-load in-accessible properties on demand.
  *
  * @param mixed $key
  * @return mixed
  */
 public function __get($key)
 {
     switch ($key) {
         case 'prices_include_tax':
             return wc_prices_include_tax();
             break;
         case 'round_at_subtotal':
             return 'yes' === get_option('woocommerce_tax_round_at_subtotal');
             break;
         case 'tax_display_cart':
             return get_option('woocommerce_tax_display_cart');
             break;
         case 'dp':
             return wc_get_price_decimals();
             break;
         case 'display_totals_ex_tax':
         case 'display_cart_ex_tax':
             return 'excl' === $this->tax_display_cart;
             break;
         case 'cart_contents_weight':
             return $this->get_cart_contents_weight();
             break;
         case 'cart_contents_count':
             return $this->get_cart_contents_count();
             break;
         case 'tax':
             wc_deprecated_argument('WC_Cart->tax', '2.3', 'Use WC_Tax:: directly');
             $this->tax = new WC_Tax();
             return $this->tax;
         case 'discount_total':
             wc_deprecated_argument('WC_Cart->discount_total', '2.3', 'After tax coupons are no longer supported. For more information see: https://woocommerce.wordpress.com/2014/12/upcoming-coupon-changes-in-woocommerce-2-3/');
             return 0;
     }
 }
Пример #4
0
/**
 * WooCommerce Dropdown categories.
 *
 * Stuck with this until a fix for https://core.trac.wordpress.org/ticket/13258.
 * We use a custom walker, just like WordPress does.
 *
 * @param int $deprecated_show_uncategorized (default: 1)
 * @return string
 */
function wc_product_dropdown_categories($args = array(), $deprecated_hierarchical = 1, $deprecated_show_uncategorized = 1, $deprecated_orderby = '')
{
    global $wp_query;
    if (!is_array($args)) {
        wc_deprecated_argument('wc_product_dropdown_categories()', '2.1', 'show_counts, hierarchical, show_uncategorized and orderby arguments are invalid - pass a single array of values instead.');
        $args['show_count'] = $args;
        $args['hierarchical'] = $deprecated_hierarchical;
        $args['show_uncategorized'] = $deprecated_show_uncategorized;
        $args['orderby'] = $deprecated_orderby;
    }
    $current_product_cat = isset($wp_query->query_vars['product_cat']) ? $wp_query->query_vars['product_cat'] : '';
    $defaults = array('pad_counts' => 1, 'show_count' => 1, 'hierarchical' => 1, 'hide_empty' => 1, 'show_uncategorized' => 1, 'orderby' => 'name', 'selected' => $current_product_cat, 'menu_order' => false);
    $args = wp_parse_args($args, $defaults);
    if ('order' === $args['orderby']) {
        $args['menu_order'] = 'asc';
        $args['orderby'] = 'name';
    }
    $terms = get_terms('product_cat', apply_filters('wc_product_dropdown_categories_get_terms_args', $args));
    if (empty($terms)) {
        return;
    }
    $output = "<select name='product_cat' class='dropdown_product_cat'>";
    $output .= '<option value="" ' . selected($current_product_cat, '', false) . '>' . __('Select a category', 'woocommerce') . '</option>';
    $output .= wc_walk_category_dropdown_tree($terms, 0, $args);
    if ($args['show_uncategorized']) {
        $output .= '<option value="0" ' . selected($current_product_cat, '0', false) . '>' . __('Uncategorized', 'woocommerce') . '</option>';
    }
    $output .= "</select>";
    echo $output;
}
 /**
  * Save downloadable files.
  *
  * @param WC_Product $product    Product instance.
  * @param array      $downloads  Downloads data.
  * @param int        $deprecated Deprecated since 2.7.
  * @return WC_Product
  */
 private function save_downloadable_files($product, $downloads, $deprecated = 0)
 {
     if ($deprecated) {
         wc_deprecated_argument('variation_id', '2.7', 'save_downloadable_files() not requires a variation_id anymore.');
     }
     $files = array();
     foreach ($downloads as $key => $file) {
         if (empty($file['file'])) {
             continue;
         }
         $download = new WC_Product_Download();
         $download->set_id($key);
         $download->set_name($file['name'] ? $file['name'] : wc_get_filename_from_url($file['file']));
         $download->set_file(apply_filters('woocommerce_file_download_path', $file['file'], $product, $key));
         $files[] = $download;
     }
     $product->set_downloads($files);
     return $product;
 }
 /**
  * Get an array of all sale and regular prices from all variations. This is used for example when displaying the price range at variable product level or seeing if the variable product is on sale.
  *
  * @param  string $context
  * @return array() Array of RAW prices, regular prices, and sale prices with keys set to variation ID.
  */
 public function get_variation_prices($context = 'view')
 {
     if (is_bool($context)) {
         wc_deprecated_argument('display', '2.7', 'Use WC_Product_Variable::get_variation_prices_including_taxes');
         return $context ? $this->get_variation_prices_including_taxes() : $this->get_variation_prices();
     }
     return $this->get_prop('variation_prices', $context);
 }
 /**
  * Returns formatted dimensions.
  *
  * @param  $formatted True by default for legacy support - will be false/not set in future versions to return the array only. Use wc_format_dimensions for formatted versions instead.
  * @return string|array
  */
 public function get_dimensions($formatted = true)
 {
     if ($formatted) {
         wc_deprecated_argument('WC_Product::get_dimensions', '2.7', 'By default, get_dimensions has an argument set to true so that HTML is returned. This is to support the legacy version of the method. To get HTML dimensions, instead use wc_format_dimensions() function. Pass false to this method to return an array of dimensions. This will be the new default behavior in future versions.');
         return apply_filters('woocommerce_product_dimensions', wc_format_dimensions($this->get_dimensions(false)), $this);
     }
     return array('length' => $this->get_length(), 'width' => $this->get_width(), 'height' => $this->get_height());
 }
Пример #8
0
 /**
  * Set total.
  *
  * @param string $value
  * @param string $deprecated Function used to set different totals based on this.
  * @throws WC_Data_Exception
  */
 public function set_total($value, $deprecated = '')
 {
     if ($deprecated) {
         wc_deprecated_argument('total_type', '2.7', 'Use dedicated total setter methods instead.');
         return $this->legacy_set_total($value, $deprecated);
     }
     $this->set_prop('total', wc_format_decimal($value, wc_get_price_decimals()));
 }