Closed. This question is off-topic. It is not currently accepting answers.admin管理员组文章数量:1430083
Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 5 years ago.
Improve this questionI want ot add + and - button after and before the quantity input on single product page? how is this possible to add using standard method lets say using hooks and fitler?
Closed. This question is off-topic. It is not currently accepting answers.Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 5 years ago.
Improve this questionI want ot add + and - button after and before the quantity input on single product page? how is this possible to add using standard method lets say using hooks and fitler?
Share Improve this question asked May 24, 2019 at 11:21 Sophia WaugeSophia Wauge 31 silver badge3 bronze badges 1- I don't want any plugin to get this functionality done. – Sophia Wauge Commented May 27, 2019 at 4:10
1 Answer
Reset to default -1Below code snippet will display Plus & Minus Quantity Buttons @ WooCommerce Single Product Page. Reference
/**
* @snippet Plus Minus Quantity Buttons @ WooCommerce Single Product Page
* @how-to Watch tutorial @ https://businessbloomer/?p=19055
* @sourcecode https://businessbloomer/?p=90052
* @author Rodolfo Melogli
* @compatible WooCommerce 3.5.1
* @donate $9 https://businessbloomer/bloomer-armada/
*/
// -------------
// 1. Show Buttons
add_action( 'woocommerce_before_add_to_cart_quantity', 'bbloomer_display_quantity_plus' );
function bbloomer_display_quantity_plus() {
echo '<button type="button" class="plus" >+</button>';
}
add_action( 'woocommerce_after_add_to_cart_quantity', 'bbloomer_display_quantity_minus' );
function bbloomer_display_quantity_minus() {
echo '<button type="button" class="minus" >-</button>';
}
// -------------
// 2. Trigger jQuery script
add_action( 'wp_footer', 'bbloomer_add_cart_quantity_plus_minus' );
function bbloomer_add_cart_quantity_plus_minus() {
// Only run this on the single product page
if ( ! is_product() ) return;
?>
<script type="text/javascript">
jQuery(document).ready(function($){
$('form.cart').on( 'click', 'button.plus, button.minus', function() {
// Get current quantity values
var qty = $( this ).closest( 'form.cart' ).find( '.qty' );
var val = parseFloat(qty.val());
var max = parseFloat(qty.attr( 'max' ));
var min = parseFloat(qty.attr( 'min' ));
var step = parseFloat(qty.attr( 'step' ));
// Change the value if plus or minus
if ( $( this ).is( '.plus' ) ) {
if ( max && ( max <= val ) ) {
qty.val( max );
} else {
qty.val( val + step );
}
} else {
if ( min && ( min >= val ) ) {
qty.val( min );
} else if ( val > 1 ) {
qty.val( val - step );
}
}
});
});
</script>
<?php
}
本文标签: pluginsHow to add plus minus button on Input Quantity box Woocommerce
版权声明:本文标题:plugins - How to add plus minus button on Input Quantity box Woocommerce? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745461823a2659358.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论