我在产品页面上找到了显示数量小计的代码片段:
add_filter( 'woocommerce_available_variation', 'variable_product_total_amount_qty_change', 10, 3 );
function variable_product_total_amount_qty_change( $data, $product, $variation ) {
$data['price_html'] .= '<div id="product_total_price" class="total-price-qty variable_products">Product Total: <span class="price">'.$data['display_price'].'</span></div>';
?>
<script>
jQuery(function($){
jQuery( '.variations_form' ).each( function() {
jQuery(this).on( 'found_variation', function( event, variation ) {
console.log(variation);//all details here
var price = variation.display_price;//selectedprice
console.log(price);
var currency = '<?php echo get_woocommerce_currency_symbol(); ?>';
$('[name=quantity]').change(function(){
if ((this.value > 1)) {
var product_total = parseFloat(price * this.value);
$('#product_total_price').fadeIn();
$('#product_total_price .price').html( currency + product_total.toFixed(2));
} else {
$('#product_total_price').fadeOut();
}
});
});
});
});
</script>
<?php
return $data;
}
结果显示:产品合计: zł100
如何修改代码te get:产品总数: 100 złBRUTTO
发布于 2021-08-17 23:52:30
看起来这一行包含了您的结果HTML:
$('#product_total_price .price').html( currency + product_total.toFixed(2));
你只需要改变变量的顺序并连接你想要的字符串。
$('#product_total_price .price').html( product_total.toFixed(2) + ' ' + currency + 'BRUTTO');
请测试一下。
编辑:此行是一个jQuery命令,用于更改标签的内部HTML,标签的类为'price‘,父标签的id为'product_total_price’。我不知道是否有副作用(例如,如果程序从那里获得值用于其他方面)。可能不会,因为它已经有了currency和product_total变量,但无论如何都应该进行测试。
https://stackoverflow.com/questions/68825137
复制相似问题