Return a given rates percent.
public static get_rate_percent ( mixed $key_or_rate ) : string | ||
$key_or_rate | mixed | Tax rate ID, or the db row itself in object format |
Результат | string |
<th><?php _e('Rate %', 'woocommerce'); ?> </th> </tr> </thead> <?php $rates = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}woocommerce_tax_rates ORDER BY tax_rate_name LIMIT 100"); foreach ($rates as $rate) { echo ' <tr> <td><input type="radio" id="add_order_tax_' . absint($rate->tax_rate_id) . '" name="add_order_tax" value="' . absint($rate->tax_rate_id) . '" /></td> <td><label for="add_order_tax_' . absint($rate->tax_rate_id) . '">' . WC_Tax::get_rate_label($rate) . '</label></td> <td>' . (isset($classes_options[$rate->tax_rate_class]) ? $classes_options[$rate->tax_rate_class] : '-') . '</td> <td>' . WC_Tax::get_rate_code($rate) . '</td> <td>' . WC_Tax::get_rate_percent($rate) . '</td> </tr> '; } ?> </table> <?php if (absint($wpdb->get_var("SELECT COUNT(tax_rate_id) FROM {$wpdb->prefix}woocommerce_tax_rates;")) > 100) { ?> <p> <label for="manual_tax_rate_id"><?php _e('Or, enter tax rate ID:', 'woocommerce'); ?> </label><br/> <input type="number" name="manual_tax_rate_id" id="manual_tax_rate_id" step="1" placeholder="<?php esc_attr_e('Optional', 'woocommerce');
/** * Test rate percent. */ public function test_get_rate_percent() { global $wpdb; $tax_rate = array('tax_rate_country' => 'GB', 'tax_rate_state' => '', 'tax_rate' => '20.0000', 'tax_rate_name' => 'VAT', 'tax_rate_priority' => '1', 'tax_rate_compound' => '1', 'tax_rate_shipping' => '1', 'tax_rate_order' => '1', 'tax_rate_class' => ''); $tax_rate_id = WC_Tax::_insert_tax_rate($tax_rate); $this->assertEquals(WC_Tax::get_rate_percent($tax_rate_id), '20%'); WC_Tax::_delete_tax_rate($tax_rate_id); }
function wc_gzdp_get_tax_label($rate_id) { return sprintf(__('VAT %s', 'woocommerce-germanized-pro'), WC_Tax::get_rate_percent($rate_id)); }
'order' => $order, 'item_id' => $item_id, 'item' => $item, 'product' => apply_filters( 'woocommerce_order_item_product', $order->get_product_from_item( $item ), $item ) ) ); } ?> <?php do_action( 'woocommerce_order_items_table', $order ); ?> </tbody> <tfoot> <?php global $woocommerce; if ( 'itemized' == get_option( 'woocommerce_tax_total_display' ) ) { foreach ( $order->get_tax_totals() as $code => $tax ) { $tax->rate = WC_Tax::get_rate_percent( $tax->rate_id ); if ( ! isset( $tax_array[ 'tax_rate'] ) ) $tax_array[ 'tax_rate' ] = array( 'tax' => $tax, 'amount' => $tax->amount, 'contains' => array( $tax ) ); else { array_push( $tax_array[ 'tax_rate' ][ 'contains' ], $tax ); $tax_array[ 'tax_rate' ][ 'amount' ] += $tax->amount; } } //$tax_label='<span class="include_tax">(inkl. '.$tax_array['tax_rate']['tax']->rate.' '..')</span>'; } /*echo '<pre>'; print_r($order); echo '</pre>'; $coupon=$order->get_used_coupons();
/** * Improve tax display within order totals * * @param array $order_totals * @param object $order * @return array */ public function order_item_totals($order_totals, $order) { // Set to formatted total without displaying tax info behind the price $order_totals['order_total']['value'] = $order->get_formatted_order_total(); // Tax for inclusive prices if ('yes' == get_option('woocommerce_calc_taxes') && 'incl' == $order->tax_display_cart) { $tax_array = array(); if ('itemized' == get_option('woocommerce_tax_total_display')) { foreach ($order->get_tax_totals() as $code => $tax) { $tax->rate = WC_Tax::get_rate_percent($tax->rate_id); if (!isset($tax_array[$tax->rate])) { $tax_array[$tax->rate] = array('tax' => $tax, 'amount' => $tax->amount, 'contains' => array($tax)); } else { array_push($tax_array[$tax->rate]['contains'], $tax); $tax_array[$tax->rate]['amount'] += $tax->amount; } } } else { $base_rate = array_values(WC_Tax::get_shop_base_rate()); $base_rate = (object) $base_rate[0]; $base_rate->rate = $base_rate->rate; $tax_array[] = array('tax' => $base_rate, 'contains' => array($base_rate), 'amount' => $order->get_total_tax()); } if (!empty($tax_array)) { foreach ($tax_array as $tax) { $order_totals['tax_' . $tax['tax']->label] = array('label' => '<span class="tax small tax-label">' . (get_option('woocommerce_tax_total_display') == 'itemized' ? sprintf(__('incl. %s%% VAT', 'woocommerce-germanized'), wc_gzd_format_tax_rate_percentage($tax['tax']->rate)) : __('incl. VAT', 'woocommerce-germanized')) . '</span>', 'value' => '<span class="tax small tax-value">' . wc_price($tax['amount']) . '</span>'); } } } return $order_totals; }
function get_order_item_totals1( $tax_display = '' ) { if(is_wc_endpoint_url( 'order-received' )) { $order_id=wc_get_order_id_by_order_key( $_GET['key']); $order=new WC_Order($order_id); /*echo '<pre>'; print_r($order); echo '</pre>';*/ $coupons=$order->get_used_coupons(); $coupon_code=$coupons[0]; $coupon_data=new WC_Coupon($coupon_code); $discount = get_post_meta($coupon_data->id,'coupon_amount',true); $type = get_post_meta($coupon_data->id,'discount_type',true); if($type=='percent'){ $coupon_label=$discount.'% Rabatt'; } else{ $coupon_label='Rabatt'; } if ( ! $tax_display ) { $tax_display = $order->tax_display_cart; } if ( 'itemized' == get_option( 'woocommerce_tax_total_display' ) ) { foreach ( $order->get_tax_totals() as $code => $tax ) { $tax->rate = WC_Tax::get_rate_percent( $tax->rate_id ); if ( ! isset( $tax_array[ 'tax_rate'] ) ) $tax_array[ 'tax_rate' ] = array( 'tax' => $tax, 'amount' => $tax->amount, 'contains' => array( $tax ) ); else { array_push( $tax_array[ 'tax_rate' ][ 'contains' ], $tax ); $tax_array[ 'tax_rate' ][ 'amount' ] += $tax->amount; } } if(isset($tax_array['tax_rate']['tax']->rate)) $tax_label='<span class="include_tax">(inkl. '.$tax_array['tax_rate']['tax']->rate.' '.$tax_array['tax_rate']['tax']->label.')</span>'; } $total_rows = array(); $shippingcost='0 '.get_woocommerce_currency_symbol(); if ( $order->get_total_discount() > 0 ) { $total_rows['discount'] = array( 'label' => __( $coupon_label, 'woocommerce' ), 'value' => '-' . $order->get_discount_to_display( $tax_display ) ); } $total_rows['shipping'] = array( 'label' => __( 'Versandkosten', 'woocommerce' ), 'value' =>$shippingcost ); $total_rows['order_total'] = array( 'label' => __( 'Gesamtsumme '.$tax_label, 'woocommerce' ), 'value' => $order->get_formatted_order_total( $tax_display ) ); return $total_rows; } }