From 854bc5d744360c65bb56ca84c968835b14f97527 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Tue, 9 Feb 2016 23:14:38 +0000 Subject: [PATCH] Don't auto load options for cart - reduce queries --- includes/class-wc-cart.php | 65 ++++++++++---------------------------- 1 file changed, 16 insertions(+), 49 deletions(-) diff --git a/includes/class-wc-cart.php b/includes/class-wc-cart.php index 01ae23847e8..c287d52c31b 100644 --- a/includes/class-wc-cart.php +++ b/includes/class-wc-cart.php @@ -101,59 +101,10 @@ class WC_Cart { */ public $fees = array(); - /** - * Prices include tax. - * - * @var bool - */ - public $prices_include_tax; - - /** - * Round at subtotal. - * - * @var bool - */ - public $round_at_subtotal; - - /** - * Tax display cart. - * - * @var string - */ - public $tax_display_cart; - - /** - * Prices inc tax. - * - * @var int - */ - public $dp; - - /** - * Display totals excluding tax. - * - * @var bool - */ - public $display_totals_ex_tax; - - /** - * Display cart excluding tax. - * - * @var bool - */ - public $display_cart_ex_tax; - /** * Constructor for the cart class. Loads options and hooks in the init method. */ public function __construct() { - $this->prices_include_tax = wc_prices_include_tax(); - $this->round_at_subtotal = get_option( 'woocommerce_tax_round_at_subtotal' ) == 'yes'; - $this->tax_display_cart = get_option( 'woocommerce_tax_display_cart' ); - $this->dp = wc_get_price_decimals(); - $this->display_totals_ex_tax = $this->tax_display_cart == 'excl'; - $this->display_cart_ex_tax = $this->tax_display_cart == 'excl'; - add_action( 'wp_loaded', array( $this, 'init' ) ); // Get cart after WP and plugins are loaded. add_action( 'wp', array( $this, 'maybe_set_cart_cookies' ), 99 ); // Set cookies add_action( 'shutdown', array( $this, 'maybe_set_cart_cookies' ), 0 ); // Set cookies before shutdown and ob flushing @@ -169,6 +120,22 @@ class WC_Cart { */ 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 $this->tax_display_cart === 'excl'; + break; case 'cart_contents_weight' : return $this->get_cart_contents_weight(); break;