Created
June 23, 2020 14:59
-
-
Save namncn/fbee5117640b0c46aadac8908dd38b25 to your computer and use it in GitHub Desktop.
Adjust the quantity input values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Adjust the quantity input values | |
*/ | |
function pixelplus_woocommerce_quantity_input_args( $args, $product ) { | |
$args['step'] = '0.01'; | |
return $args; | |
} | |
add_filter( 'woocommerce_quantity_input_args', 'pixelplus_woocommerce_quantity_input_args', 10, 2 ); | |
remove_filter( 'woocommerce_stock_amount', 'intval' ); | |
add_filter( 'woocommerce_stock_amount', 'floatval' ); | |
function pixelplus_unit_price_fix( $price, $order, $item, $inc_tax = false, $round = true ) { | |
$qty = ( ! empty( $item['qty'] ) && $item['qty'] != 0 ) ? $item['qty'] : 1; | |
if ( $inc_tax ) { | |
$price = ( $item['line_total'] + $item['line_tax'] ) / $qty; | |
} else { | |
$price = $item['line_total'] / $qty; | |
} | |
$price = $round ? round( $price, 2 ) : $price; | |
return $price; | |
} | |
add_filter( 'woocommerce_order_amount_item_total', 'pixelplus_unit_price_fix', 10, 5 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment