Created
October 8, 2021 04:36
-
-
Save hamidrezayazdani/fd695e33bc352e102fa97723832e3a2c to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
/** | |
* Change min qty to area | |
*/ | |
function ywp_set_min_qty_decimal( $val ) { | |
return 0.1; | |
} | |
add_filter('woocommerce_quantity_input_min', 'ywp_set_min_qty_decimal'); | |
/** | |
* Change qty steps | |
*/ | |
function ywp_change_qty_steps_to_decimal( $val ) { | |
return 0.1; | |
} | |
add_filter('woocommerce_quantity_input_step', 'ywp_change_qty_steps_to_decimal'); | |
/** | |
* Removes wc qty validation | |
*/ | |
remove_filter( 'woocommerce_stock_amount', 'intval' ); | |
/** | |
* Add wc qty float validation | |
*/ | |
add_filter( 'woocommerce_stock_amount', 'floatval' ); | |
/** | |
* Add js to product | |
*/ | |
function ywp_update_product_price_on_qty_change() { | |
global $product; | |
echo '<div id="product-price" style="display:inline-block">قابل پرداخت: <span></span></div>'; | |
$price = $product->get_price(); | |
$currency = get_woocommerce_currency_symbol(); | |
wc_enqueue_js( " | |
jQuery('[name=quantity]').on('input change', function() { | |
let qty = $(this).val(); | |
let price = '" . esc_js( $price ) . "'; | |
let price_string = (price*qty).toFixed(2); | |
jQuery('#product-price > span').html(price_string+' '+" . esc_js( $currency ) . "); | |
}).change(); | |
" ); | |
} | |
add_action( 'woocommerce_after_add_to_cart_button', 'ywp_update_product_price_on_qty_change' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment