本文整理汇总了PHP中WC_Tax::format_tax_rate_class方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Tax::format_tax_rate_class方法的具体用法?PHP WC_Tax::format_tax_rate_class怎么用?PHP WC_Tax::format_tax_rate_class使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WC_Tax
的用法示例。
在下文中一共展示了WC_Tax::format_tax_rate_class方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save_tax_rate_hidden_status
/**
* Whenever a WooCommerce tax rate is saved, also save the tax rate's hidden status.
*
* Executed whenever a WooCommerce tax rate is added, updated or deleted.
*
* @param int $tax_rate_id The WooCommerce Tax Rate ID.
*/
public function save_tax_rate_hidden_status()
{
// nonce and cap checks are copied from WC_AJAX::tax_rates_save_changes()
// Use return instead of exit so that WooCommerce core will handle the AJAX error messages
if (!isset($_POST['wc_tax_nonce'], $_POST['changes'])) {
return;
}
$current_class = !empty($_POST['current_class']) ? $_POST['current_class'] : '';
// This is sanitized seven lines later.
if (!wp_verify_nonce($_POST['wc_tax_nonce'], 'wc_tax_nonce-class:' . $current_class)) {
return;
}
// Check User Caps
if (!current_user_can('manage_woocommerce')) {
return;
}
$hidden_rates = array();
$current_class = WC_Tax::format_tax_rate_class($current_class);
$rates = WC_Tax::get_rates_for_tax_class($current_class);
foreach ($rates as $tax_rate_id => $rate) {
if (isset($_POST['tax_rate_hidden'][$tax_rate_id])) {
// @codingStandardsIgnoreEnd
$hidden_rates[$tax_rate_id] = true;
} else {
if (isset($hidden_rates[$tax_rate_id])) {
unset($hidden_rates[$tax_rate_id]);
}
}
}
wc_hidden_taxes()->set_option('hidden_rates', $hidden_rates);
}
示例2: tax_rates_save_changes
/**
* Handle submissions from assets/js/settings-views-html-settings-tax.js Backbone model.
*/
public static function tax_rates_save_changes()
{
if (!isset($_POST['current_class'], $_POST['wc_tax_nonce'], $_POST['changes'])) {
wp_send_json_error('missing_fields');
exit;
}
$current_class = $_POST['current_class'];
// This is sanitized seven lines later.
if (!wp_verify_nonce($_POST['wc_tax_nonce'], 'wc_tax_nonce-class:' . $current_class)) {
wp_send_json_error('bad_nonce');
exit;
}
$current_class = WC_Tax::format_tax_rate_class($current_class);
// Check User Caps
if (!current_user_can('manage_woocommerce')) {
wp_send_json_error('missing_capabilities');
exit;
}
$changes = $_POST['changes'];
foreach ($changes as $tax_rate_id => $data) {
if (isset($data['deleted'])) {
if (isset($data['newRow'])) {
// So the user added and deleted a new row.
// That's fine, it's not in the database anyways. NEXT!
continue;
}
WC_Tax::_delete_tax_rate($tax_rate_id);
}
$tax_rate = array_intersect_key($data, array('tax_rate_country' => 1, 'tax_rate_state' => 1, 'tax_rate' => 1, 'tax_rate_name' => 1, 'tax_rate_priority' => 1, 'tax_rate_compound' => 1, 'tax_rate_shipping' => 1, 'tax_rate_order' => 1));
if (isset($data['newRow'])) {
// Hurrah, shiny and new!
$tax_rate['tax_rate_class'] = $current_class;
$tax_rate_id = WC_Tax::_insert_tax_rate($tax_rate);
} else {
// Updating an existing rate ...
if (!empty($tax_rate)) {
WC_Tax::_update_tax_rate($tax_rate_id, $tax_rate);
}
}
if (isset($data['postcode'])) {
WC_Tax::_update_tax_rate_postcodes($tax_rate_id, array_map('wc_clean', $data['postcode']));
}
if (isset($data['city'])) {
WC_Tax::_update_tax_rate_cities($tax_rate_id, array_map('wc_clean', $data['city']));
}
}
wp_send_json_success(array('rates' => WC_Tax::get_rates_for_tax_class($current_class)));
}