亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 WooCommerce 中獲取產品稅率的標簽

在 WooCommerce 中獲取產品稅率的標簽

PHP
翻閱古今 2023-05-26 16:13:59
我需要找出 WooCommerce 中的稅率標簽。使用以下代碼,我可以找出稅率:$taxclass = $product_variation->get_tax_class(); $tax_rates = WC_Tax::get_rates( $taxclass );if (!empty($tax_rates)) {    $tax_rate = reset($tax_rates);    $tax_rate_info = (int)$tax_rate['rate'];}else {}不幸的是,我無法獲得該稅率的確切標簽。我嘗試了以下方法: $tax_labels = WC_Tax::get_rate_label( $taxclass );我需要以某種方式找出稅率的 ID 并將該 ID 傳遞給 get_rate_label() 以便它起作用。有人可以幫助如何找到稅率 ID。
查看完整描述

1 回答

?
滄海一幻覺

TA貢獻1824條經驗 獲得超5個贊

您可以使用數組鍵獲取特定稅率的標簽名稱,label如下所示:


$variation_tax_class  = $product_variation->get_tax_class();

$variation_tax_rates  = WC_Tax::get_rates( $variation_tax_class );


foreach( $variation_tax_rates as $rate_id => $rate ) {

    if ( ! empty($rate) ) {

        $rate_percent  = (int) $rate['rate'];

        $rate_label    = $rate['label']; // <== HERE is the label name of the tax rate

        $rate_shipping = $rate['shipping'];

        $rate_compound = $rate['compound'];

    }

}


查看完整回答
反對 回復 2023-05-26
  • 1 回答
  • 0 關注
  • 157 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號