如何使用多个过滤选项会影响Woocommerce简单产品的价格? [英] How to use multiple filtering options that will affect the price in Woocommerce simple products?
本文介绍了如何使用多个过滤选项会影响Woocommerce简单产品的价格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用"答案代码.它仅使用单个选择字段进行过滤.我想使用 jQuery 扩展此代码,以便能够使用多个字段进行过滤.
I am using "Add a select field that will change price in Woocommerce simple products" answer code. It only uses a single selection field for filtering. I want to extend this code using jQuery to be able to use multiple fields for filtering.
示例:2个选择字段,一个文本,一个复选框和一些单选按钮,这些都将确定最终的计算价格.
Example: 2 select fields, one text, a checkbox and some radio buttons that will all determine the final calculated price.
// Select field
woocommerce_form_field('materials_pack', array(
'type' => 'select',
'class' => array('material-field form-row-wide'),
'label' => __('Select Materials:', $domain),
'required' => true,
'options' => $options,
),'');
<script>
jQuery(function($){
var a = <?php echo json_encode($prices); ?>,
b = 'p.price',
c = 'select[name="materials_pack"]';
$(c).on( 'change', function(){
$.each( a, function( key, value ){
if( $(c).val() == key )
$(b).html(value);
});
});
});
</script>
如何将其用于多个字段?以及如何执行jquery脚本?
How to use it for multi fields? and how do the jquery script?
推荐答案
Ok i found my answer here now i just need to how to do it in this code?
add_action('woocommerce_before_calculate_totals', 'set_cutom_cart_item_price', 20, 1);
foreach ( $cart->get_cart() as $cart_item ) {
if ( isset( $cart_item['material_data']['new_price'] ) ){
$cart_item['data']->set_price( $cart_item['material_data']['new_price'] );
}
}
这篇关于如何使用多个过滤选项会影响Woocommerce简单产品的价格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文