get the tax rate of a product的几种方法搜集

本文介绍了三种在Magento中获取产品税率的方法,包括直接通过产品税类ID获取税率、使用Tax Calculation单例请求税率以及结合商店信息设置税率请求等。
1、获取产品加上税之后的价格:
$_finalPriceInclTax = Mage::helper(’tax’)->getPrice($_product, $_product->getFinalPrice(), true); 

2、获取产品的税率方法一:


// Get the product's tax class' ID
        $taxClassId = $_product->getData("tax_class_id");
        // Get the tax rates of each tax class in an associative array
        $taxClasses = $this->helper("core")->jsonDecode( $this->helper("tax")->getAllRatesByProductClass() );
        // Extract the tax rate from the array
        $taxRate = $taxClasses["value_" . $taxClassId];

3、获取产品的税率方法二:
 /**
		 * @var $tax_helper Mage_Tax_Model_Calculation
		 */
		$tax_helper = Mage::getSingleton('tax/calculation');
		$tax_request = $tax_helper->getRateOriginRequest();
		$tax_request->setProductClassId($product->getTaxClassId());

		$tax = $tax_helper->getRate($tax_request);

4、获取产品的税率方法三:
 $store = Mage::app()->getStore('default');
		$request = Mage::getSingleton('tax/calculation')->getRateRequest(null, null, null, $store);
		$taxclassid = $product->getData('tax_class_id')
		$percent = Mage::getSingleton('tax/calculation')->getRate($request->setProductClassId($taxclassid));


/** * ===== Additional custom shortcodes and product utilities (kept intact) ===== */ // Display product stock quantity function product_stock_quantity_shortcode($atts) { if (!class_exists('WooCommerce')) { return 'WooCommerce not active'; } $atts = shortcode_atts( array('id' => null), $atts, 'product_stock_quantity' ); if (is_null($atts['id']) && is_product()) { global $product; if (!$product) { return 'No product found'; } $product_id = $product->get_id(); } else { $product_id = intval($atts['id']); } $product = wc_get_product($product_id); if (!$product) { return 'Product not found'; } $stock_quantity = $product->get_stock_quantity(); if ($stock_quantity > 10) { $message = '<span class="stock-label" style="font-size: 15px;">庫存</span><span class="greater-than-symbol" style="font-size: 15px;">></span><span style="color: #FD010C; font-weight: 800; font-size: 15px;">10</span>'; } elseif ($stock_quantity > 0) { $message = '<span class="stock-label" style="font-size: 15px;">庫存僅剩 </span><span style="color: #fd010c; font-weight: 600; font-size: 15px;">' . esc_html($stock_quantity) . '</span>'; } else { $message = '<span class="out-of-stock" style="font-size: 15px;">商品缺貨中</span>'; } return '<div class="stock-quantity" style="font-size: 16px;">' . $message . '</div>'; } add_shortcode('product_stock_quantity', 'product_stock_quantity_shortcode'); // Auto-update prices based on retail price function update_prices_based_on_retail_price($post_id) { if (get_post_type($post_id) !== 'product') { return; } $retail_price_ntd = get_field('retail_price_ntd', $post_id); if (!empty($retail_price_ntd)) { $regular_price_rate = 0.18; $market_price_rate = 0.2; $regular_price = $retail_price_ntd * $regular_price_rate; $market_price_myr = $retail_price_ntd * $market_price_rate; update_post_meta($post_id, '_regular_price', $regular_price); update_post_meta($post_id, '_price', $regular_price); $market_price_myr_with_rm = 'RM' . number_format($market_price_myr, 2); update_field('market_price_myr', $market_price_myr_with_rm, $post_id); } } add_action('save_post', 'update_prices_based_on_retail_price'); add_filter('acf/update_value/name=outofprint_market_price_myr', 'complete_market_price_myr', 10, 3); function complete_market_price_myr($value, $post_id, $field) { $conversion_rate = 0.2; if (is_numeric($value)) { $myr_value = $value * $conversion_rate; $value = $value . "台幣 / 大約RM" . number_format($myr_value, 2); } return $value; } add_filter('acf/update_value/name=retail_price_ntd', 'append_yuan_symbol', 10, 3); function append_yuan_symbol($value, $post_id, $field) { if (is_numeric($value)) { $value = $value . '元'; } return $value; } function display_ebook_status_shortcode($atts) { $ebook_status = get_field('ebook_status'); if ($ebook_status === '有电子书') { return '<span style="color: #da3800;">(2)</span>'; } elseif ($ebook_status === '沒有電子書') { return '<span style="color: #da3800;">(1)</span>'; } return ''; } add_shortcode('ebook_status', 'display_ebook_status_shortcode'); add_action('save_post', function ($post_id) { if (get_post_type($post_id) !== 'product') { return; } $current_episode = get_field('current_episode', $post_id); if (!$current_episode) { return; } $series_terms = get_the_terms($post_id, 'series'); if (!empty($series_terms) && !is_wp_error($series_terms)) { foreach ($series_terms as $term) { $existing_episode = (int) get_field('current_episode', 'series_' . $term->term_id); if ($current_episode > $existing_episode) { update_field('current_episode', $current_episode, 'series_' . $term->term_id); } } } }); // Series with episode and stock count function display_series_with_current_episode_and_stock_shortcode() { $post_id = get_the_ID(); $series_terms = get_the_terms($post_id, 'series'); if (!empty($series_terms) && !is_wp_error($series_terms)) { $output = ''; foreach ($series_terms as $term) { $current_episode = get_field('current_episode', 'series_' . $term->term_id); $query_args = [ 'post_type' => 'product', 'post_status' => 'publish', 'posts_per_page' => -1, 'tax_query' => [[ 'taxonomy' => 'series', 'field' => 'term_id', 'terms' => $term->term_id, ]], 'meta_query' => [[ 'key' => '_stock_status', 'value' => 'instock', 'compare' => '=', ]], ]; $products_query = new WP_Query($query_args); $in_stock_count = $products_query->found_posts; wp_reset_postdata(); $series_link = get_term_link($term); if (!is_wp_error($series_link)) { $output .= '<p style="color: #F28900; font-size: 14px; margin: 0;">'; $output .= '<a href="' . esc_url($series_link) . '" style="color: #F28900; text-decoration: none;">'; $output .= esc_html($term->name) . ' - 本系列共' . esc_html($current_episode) . '集,可购买商品种类为' . esc_html($in_stock_count) . '样'; $output .= '</a>。</p>'; } } return $output; } return '<p style="color: #F28900; font-size: 13px; margin: 0;">未找到本商品的系列信息.</p>'; } add_shortcode('series_with_current_episode_and_stock', 'display_series_with_current_episode_and_stock_shortcode'); // Simpler series stock count function zipbag_series_display_shortcode() { $post_id = get_the_ID(); $series_terms = get_the_terms($post_id, 'series'); if (!empty($series_terms) && !is_wp_error($series_terms)) { $output = ''; foreach ($series_terms as $term) { $query_args = [ 'post_type' => 'product', 'post_status' => 'publish', 'posts_per_page' => -1, 'tax_query' => [[ 'taxonomy' => 'series', 'field' => 'term_id', 'terms' => $term->term_id, ]], 'meta_query' => [[ 'key' => '_stock_status', 'value' => 'instock', 'compare' => '=', ]], ]; $products_query = new WP_Query($query_args); $in_stock_count = $products_query->found_posts; wp_reset_postdata(); $series_link = get_term_link($term); if (!is_wp_error($series_link)) { $output .= '<p style="color: #F28900; font-size: 14px; margin: 0;">'; $output .= '<a href="' . esc_url($series_link) . '" style="color: #F28900; text-decoration: none;">'; $output .= esc_html($term->name) . ' - 可购买商品种类为 ' . esc_html($in_stock_count) . ' 样'; $output .= '</a>。</p>'; } } return $output; } return '<p style="color: #F28900; font-size: 13px; margin: 0;">未找到本商品的系列信息。</p>'; } add_shortcode('zipbag_series_display', 'zipbag_series_display_shortcode'); // Availability text customization function custom_woocommerce_get_availability_text($availability, $product) { $stock_quantity = $product->get_stock_quantity(); if ($stock_quantity > 10) { return '庫存>10'; } elseif ($stock_quantity >= 1 && $stock_quantity <= 9) { return '庫存僅剩 ' . $stock_quantity; } else { return '商品缺貨中'; } } add_filter('woocommerce_get_availability_text', 'custom_woocommerce_get_availability_text', 10, 2); // Book specifications shortcode function display_book_specifications() { $binding_type = get_field('binding_type'); $number_of_pages = get_field('number_of_pages'); $printing_size = get_field('printing_size'); $content_rate = get_field('content_rate'); $printing_colour = get_field('printing_colour'); $edition = get_field('edition'); $specifications = array(); if (!empty($binding_type)) $specifications[] = $binding_type; if (!empty($number_of_pages)) $specifications[] = $number_of_pages; if (!empty($printing_size)) $specifications[] = $printing_size; if (!empty($content_rate)) $specifications[] = $content_rate; if (!empty($printing_colour)) $specifications[] = $printing_colour; if (!empty($edition)) $specifications[] = $edition; $output = "規格:" . implode(" / ", $specifications); return $output; } add_shortcode('book_specifications', 'display_book_specifications'); // Force qty 1 on product page add_filter('woocommerce_quantity_input_min', 'hide_woocommerce_quantity_input', 10, 2); add_filter('woocommerce_quantity_input_max', 'hide_woocommerce_quantity_input', 10, 2); function hide_woocommerce_quantity_input($quantity, $product) { if (!is_product()) { return $quantity; } return 1; } currently, for my Regular price, it is set through key in number in 定價, then 定價 * 0.2 = 市場價格 , and regular price is set by multiplying 市場價格 with 0.9. Howeverm currently the outcome will be in 3 decimal place. I want to limit it to only 2 decimal places and round up the 3rd decimal places. Is it possible to set it? because now even tho the displayed price is 2 digit, but it charges customer the price of 3 digit. The difference is obvious when theres high in quantity.
最新发布
09-14
用于安卓手自我的一个好友偷摸搬运过来、刷机精灵、甜辣椒什么的有时对机型支持并不是那么完善的、关键时刻还的需要通用的adb命令自己动手、把adb完整工具包放在系统system32下、打开cmd、输入adb shell测试通过即可、当然了、在这些之前驱动安装什么的都是必须的哦~~】 adb devices 查看连接在电脑上的设备及其sn码 adb shell 进入手机的超级终端Terminal(远程登陆到手机上的android系统) 在shell中的命令: su 以root权限进行操作 mount * 挂载对应分区 rm * 删除对应文件 ls 例出当前的文件目录 映射出目录 mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system exit 退出 重新挂载文件系统 adb remount adb reboot 重启 adb reboot-bootloader 重启到bootloader adb reboot recovery 重启到recovery 安装软件 adb install apk文件名称.apk 重新安装该软件 adb install -r apk文件名称.apk 卸载apk软件 adb uninstall apk包名.apk 查看手机上的运行日志,此项可以用来查错 adb logcat A为手机路径,B为电脑路径,意思为:把文件从手机中复制到电脑上 adb pull A为手机路径,B为电脑路径,意思为:把文件从电脑复制到手机上 adb push 重启手机 adb reboot 重启到Recovery界面 adb reboot recovery 重启到bootloader界面 adb reboot bootloader 增加flash_image文件到手机上 adb push flash_image.zip /system/bin/flash_image recovery先复制到卡上 adb push *.img /sdcard 修改文件属性 chmod 0755 /system/bin/flash_image fastboot getvar all 获取手机所有信息 fastboot getvar product 获取手机内部版本号(一般为vle或villec2) fastboot getvar cid 获取cid (刷RUU必备啊) fastboot oem get_identifier_token 获取用户标识码(官解用) fastboot flash boot boot.img 刷boot(boot文件放在同目录下) fastboot boot boot.superboot.img s3获取root(root文件boot.superboot.img放在同目录下) fastboot flash unlocktoken Unlock_code.bin(解锁文件Unlock_code.bin放在同目录下) fastboot flash recovery * 刷入rec(rec文件放在同目录下) fastboot oem writecid 11111111 刷入超级cid,soff后使用 HTC解锁 (LZ就是火腿肠用户没办法~) http://www.htcdev.com/注册账号 http://www.htcdev.com/bootloader/unlock-instructions/page-3 登陆,使用用户标识码获取Unlock_code.bin fastboot flash unlocktoken Unlock_code.bin 刷入Unlock_code.bin 手机上按音量上后电源键 线刷zip版的ruu(慎用) 打开任意ruu 打开%temp% 找到以{*}的几个文件夹 找到有rom.zip文件的文件夹 把zip包改名为rom.zip,复制到对应文件夹中,解压android-info.txt到同样的文件夹中 操作同刷普通ruu一样 rec操作(以twrp为准) install 刷入zip格式的卡刷包 wipe 清除对应分区内的文件: cache 缓存 factory reset 恢复出厂设置 以上为刷机必须 internal storage 内部储存 external storage 外部储存 mount 挂载对应分区 sdcard sd卡分区(外部储存) data data分区(外部储存) system 系统分区 cache 缓存分区 机与
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值