Handle get_rate_code when no matching rate is found. Prevents notices.
This commit is contained in:
parent
8c7996e5b1
commit
3be6664f05
|
@ -674,16 +674,18 @@ class WC_Cart {
|
|||
|
||||
$code = $this->tax->get_rate_code( $key );
|
||||
|
||||
if ( ! isset( $tax_totals[ $code ] ) ) {
|
||||
$tax_totals[ $code ] = new stdClass();
|
||||
$tax_totals[ $code ]->amount = 0;
|
||||
}
|
||||
if ( $code ) {
|
||||
if ( ! isset( $tax_totals[ $code ] ) ) {
|
||||
$tax_totals[ $code ] = new stdClass();
|
||||
$tax_totals[ $code ]->amount = 0;
|
||||
}
|
||||
|
||||
$tax_totals[ $code ]->tax_rate_id = $key;
|
||||
$tax_totals[ $code ]->is_compound = $this->tax->is_compound( $key );
|
||||
$tax_totals[ $code ]->label = $this->tax->get_rate_label( $key );
|
||||
$tax_totals[ $code ]->amount += wc_round_tax_total( $tax );
|
||||
$tax_totals[ $code ]->formatted_amount = wc_price( wc_round_tax_total( $tax_totals[ $code ]->amount ) );
|
||||
$tax_totals[ $code ]->tax_rate_id = $key;
|
||||
$tax_totals[ $code ]->is_compound = $this->tax->is_compound( $key );
|
||||
$tax_totals[ $code ]->label = $this->tax->get_rate_label( $key );
|
||||
$tax_totals[ $code ]->amount += wc_round_tax_total( $tax );
|
||||
$tax_totals[ $code ]->formatted_amount = wc_price( wc_round_tax_total( $tax_totals[ $code ]->amount ) );
|
||||
}
|
||||
}
|
||||
|
||||
return apply_filters( 'woocommerce_cart_tax_totals', $tax_totals, $this );
|
||||
|
|
|
@ -327,19 +327,22 @@ class WC_Checkout {
|
|||
|
||||
// Store tax rows
|
||||
foreach ( array_keys( WC()->cart->taxes + WC()->cart->shipping_taxes ) as $key ) {
|
||||
$code = WC()->cart->tax->get_rate_code( $key );
|
||||
|
||||
if ( $code ) {
|
||||
$item_id = wc_add_order_item( $order_id, array(
|
||||
'order_item_name' => $code,
|
||||
'order_item_type' => 'tax'
|
||||
) );
|
||||
|
||||
$item_id = wc_add_order_item( $order_id, array(
|
||||
'order_item_name' => WC()->cart->tax->get_rate_code( $key ),
|
||||
'order_item_type' => 'tax'
|
||||
) );
|
||||
|
||||
// Add line item meta
|
||||
if ( $item_id ) {
|
||||
wc_add_order_item_meta( $item_id, 'rate_id', $key );
|
||||
wc_add_order_item_meta( $item_id, 'label', WC()->cart->tax->get_rate_label( $key ) );
|
||||
wc_add_order_item_meta( $item_id, 'compound', absint( WC()->cart->tax->is_compound( $key ) ? 1 : 0 ) );
|
||||
wc_add_order_item_meta( $item_id, 'tax_amount', wc_format_decimal( isset( WC()->cart->taxes[ $key ] ) ? WC()->cart->taxes[ $key ] : 0 ) );
|
||||
wc_add_order_item_meta( $item_id, 'shipping_tax_amount', wc_format_decimal( isset( WC()->cart->shipping_taxes[ $key ] ) ? WC()->cart->shipping_taxes[ $key ] : 0 ) );
|
||||
// Add line item meta
|
||||
if ( $item_id ) {
|
||||
wc_add_order_item_meta( $item_id, 'rate_id', $key );
|
||||
wc_add_order_item_meta( $item_id, 'label', WC()->cart->tax->get_rate_label( $key ) );
|
||||
wc_add_order_item_meta( $item_id, 'compound', absint( WC()->cart->tax->is_compound( $key ) ? 1 : 0 ) );
|
||||
wc_add_order_item_meta( $item_id, 'tax_amount', wc_format_decimal( isset( WC()->cart->taxes[ $key ] ) ? WC()->cart->taxes[ $key ] : 0 ) );
|
||||
wc_add_order_item_meta( $item_id, 'shipping_tax_amount', wc_format_decimal( isset( WC()->cart->shipping_taxes[ $key ] ) ? WC()->cart->shipping_taxes[ $key ] : 0 ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -557,6 +557,10 @@ class WC_Tax {
|
|||
|
||||
$rate = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}woocommerce_tax_rates WHERE tax_rate_id = %s", $key ) );
|
||||
|
||||
if ( ! $rate ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$code = array();
|
||||
|
||||
$code[] = $rate->tax_rate_country;
|
||||
|
|
Loading…
Reference in New Issue