WC_Tax::get_rate_code( mixed $key_or_rate )

Get a rates code. Code is made up of COUNTRY-STATE-NAME-Priority. E.g GB-VAT-1, US-AL-TAX-1.


Description Description


Parameters Parameters

$key_or_rate

(Required) Tax rate ID, or the db row itself in object format.


Top ↑

Return Return

(string)


Top ↑

Source Source

File: includes/class-wc-tax.php

723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
public static function get_rate_code( $key_or_rate ) {
    global $wpdb;
 
    if ( is_object( $key_or_rate ) ) {
        $key  = $key_or_rate->tax_rate_id;
        $rate = $key_or_rate;
    } else {
        $key  = $key_or_rate;
        $rate = $wpdb->get_row( $wpdb->prepare( "SELECT tax_rate_country, tax_rate_state, tax_rate_name, tax_rate_priority FROM {$wpdb->prefix}woocommerce_tax_rates WHERE tax_rate_id = %s", $key ) );
    }
 
    $code_string = '';
 
    if ( null !== $rate ) {
        $code        = array();
        $code[]      = $rate->tax_rate_country;
        $code[]      = $rate->tax_rate_state;
        $code[]      = $rate->tax_rate_name ? $rate->tax_rate_name : 'TAX';
        $code[]      = absint( $rate->tax_rate_priority );
        $code_string = strtoupper( implode( '-', array_filter( $code ) ) );
    }
 
    return apply_filters( 'woocommerce_rate_code', $code_string, $key );
}


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.