Skip to content

Instantly share code, notes, and snippets.

@namncn
Created June 23, 2020 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save namncn/fbee5117640b0c46aadac8908dd38b25 to your computer and use it in GitHub Desktop.
Save namncn/fbee5117640b0c46aadac8908dd38b25 to your computer and use it in GitHub Desktop.
Adjust the quantity input values
<?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