我目前正在使用此代码来计算我的某个表单上的税,但我还想要另一个表单来计算税,而且我不确定如何编辑此代码以使其生效2形式,或者如果有更好的东西,我可以做?
// update the "78" to the ID of your form add_filter('gform_pre_render_78', 'add_total_script'); function add_total_script($form) { ?> function gform_product_total(formId, total){ var tax = ((5 * total) / 100); // update the "20" to the desired tax percentage; tax = Math.round(tax*100)/100; //rounding tax to 2 decimal digits return total + tax; } 'Tax', // name that will appear in PayPal and pricing summary tables 'price' => $tax, // amount of total tax 'quantity' => 1 ); return $product_info; } function get_total($products) { $total = 0; foreach($products["products"] as $product){ $price = GFCommon::to_number($product["price"]); if(is_array($product["options"])){ foreach($product["options"] as $option){ $price += GFCommon::to_number($option["price"]); } } $subtotal = floatval($product["quantity"]) * $price; $total += $subtotal; } $total += floatval($products["shipping"]["price"]); return $total; }
答案 0 :(得分:0)
由于在重力形式中引入了“计算”(不记得是什么版本),只有在税收计算非常复杂的情况下才需要这种计算税的方法。看起来您的税收很简单。
这篇文章演示了为Gravity表单添加税的最佳方法(并且还提供了用于生成当前小计的合并标记):
http://gravitywiz.com/subtotal-merge-tag-for-calculations/
请确保 check out the demo 看到这一点。
答案 1 :(得分:0)
请检查以下代码。添加javascript以查看前端税收
<script type="text/javascript">
gform.addFilter( 'gform_product_total', function(total, formId){
var tax = 10,
newtax = ( total * tax ) / 100 ;
return total + newtax;
} );
</script>
现在让我们将税收更新为数据库。
function saiful_gf_remove_money_symbol($s) {
return GFCommon::to_number( $s );
}
add_filter( 'saiful_gf_remove_money_symbol', 'saiful_gf_remove_money_symbol' );
function saiful_gf_to_money($s) {
return GFCommon::to_money( $s );
}
add_filter( 'saiful_gf_to_money', 'saiful_gf_to_money' );
add_filter( 'gform_product_info', 'add_fee', 10, 3 );
function add_fee( $product_info, $form, $lead ) {
$tax = 10;
$loop_price = 0;
if( isset($product_info['products']) && count($product_info['products']) > 0 ){
foreach ($product_info['products'] as $data){
if( isset($data['options']) && count($data['options']) > 0 ){
foreach ( $data['options'] as $key => $option ) {
$loop_price += floatval( $option['price'] );
}
}
$new_price = apply_filters( 'saiful_gf_remove_money_symbol',$data['price']) + $loop_price ;
$new_price = ( ( $new_price * $tax ) / 100 ) + apply_filters( 'saiful_gf_remove_money_symbol',$data['price']);
$data['price'] = apply_filters( 'saiful_gf_to_money', $new_price );
$product_info['products'] = $data;
}
}
return $product_info;
}
由于