WC_Tax::init PHP Méthode

init() public static méthode

Load options.
public static init ( )
    public static function init()
    {
        self::$precision = wc_get_rounding_precision();
        self::$round_at_subtotal = 'yes' === get_option('woocommerce_tax_round_at_subtotal');
        add_action('update_option_woocommerce_tax_classes', array(__CLASS__, 'maybe_remove_tax_class_rates'), 10, 2);
    }

Usage Example

     * @param string $tax_class
     *
     * @return array|null|object
     */
    public static function get_rates_for_tax_class($tax_class)
    {
        global $wpdb;
        // Get all the rates and locations. Snagging all at once should significantly cut down on the number of queries.
        $rates = self::sort_rates($wpdb->get_results($wpdb->prepare("SELECT * FROM `{$wpdb->prefix}woocommerce_tax_rates` WHERE `tax_rate_class` = %s;", sanitize_title($tax_class))));
        $locations = $wpdb->get_results("SELECT * FROM `{$wpdb->prefix}woocommerce_tax_rate_locations`");
        if (!empty($rates)) {
            // Set the rates keys equal to their ids.
            $rates = array_combine(wp_list_pluck($rates, 'tax_rate_id'), $rates);
        }
        // Drop the locations into the rates array.
        foreach ($locations as $location) {
            // Don't set them for unexistent rates.
            if (!isset($rates[$location->tax_rate_id])) {
                continue;
            }
            // If the rate exists, initialize the array before appending to it.
            if (!isset($rates[$location->tax_rate_id]->{$location->location_type})) {
                $rates[$location->tax_rate_id]->{$location->location_type} = array();
            }
            $rates[$location->tax_rate_id]->{$location->location_type}[] = $location->location_code;
        }
        return $rates;
    }
}
WC_Tax::init();