本文整理汇总了PHP中WC_Tax::init方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Tax::init方法的具体用法?PHP WC_Tax::init怎么用?PHP WC_Tax::init使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WC_Tax
的用法示例。
在下文中一共展示了WC_Tax::init方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_rates_for_tax_class
* @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();