gpt-4-0314· OpenAI
WildChat-4.8M (AI2)
woocommerce,使用代码实现在产品页的价格下方显示税金
- User
woocommerce,使用代码实现在产品页的价格下方显示税金
- Assistant
要在WooCommerce产品页面的价格下方显示税金,您需要将以下代码添加到WordPress主题的functions.php文件中:
phpadd_filter( 'woocommerce_get_price_html', 'display_tax_information_below_product_price', 10, 2 ); function display_tax_information_below_product_price( $price_html, $product ) { if ( ! wc_tax_enabled() || 'excl' !== get_option( 'woocommerce_tax_display_shop' ) ) { return $price_html; } $tax_rates = WC_Tax::get_rates( $product->get_tax_class() ); $tax_rate_string = ''; foreach ( $tax_rates as $tax_rate ) { if ( $tax_rate['name'] ) { $tax_rate_string .= $tax_rate['name'] . ': '; } $tax_rate_string .= $tax_rate['rate'] . '%<br>'; } if ( $tax_rate_string ) { // 添加样式(如果需要) $tax_info_html = '<span class="woocommerce-tax-info">' . $tax_rate_string . '</span>'; $price_html .= $tax_info_html; } return $price_html; }