How to force minimum charge in Woocommerce, yet not restrict checkout? -
i'm wondering how force minimum charge in woocommerce, e-commerce system wordpress. if minimum $100, , items in cart total $23, person can checkout, paying $100. needs reflect not in checkout, order invoice , other relevant fields.
i'm okay php, i'm not familiar woocommerce system. logic-wise, predict can mod total calculator... if $total >= 100 { proceed regularly } else { $total = 100 }. or maybe dynamically add item cart based on difference between minimum charge , current cart total. i'm concerned may mess things not putting in enough consideration how entire site may need modding because total amount shows in many places.
note: not talking not letting people checkout if don't meet minimum order amount. there plugins or can use javascript disable checkout button.
i answering own question:
to force minimum charge, have tap couple of woocommerce parts. first ability add additional line (like surcharge) total. second subtotal amount.
in themes function.php, add snippet (original on github consonr @ github)
//add custom fee function woo_add_cart_fee() { global $woocommerce; $subt = $woocommerce->cart->subtotal; if ($subt < 100 ) { $surcharge = 100 - $subt; } else { $surcharge = 0; } $woocommerce->cart->add_fee( __('surcharge', 'woocommerce'), $surcharge ); } add_action( 'woocommerce_cart_calculate_fees', 'woo_add_cart_fee' );
my minimum charge 100. 100 has met subtotal, meaning before delivery fees. $woocommerce->cart->subtotal subtotal amount stored.
the above snippet add additional line cart in checkout. value of "surcharge" can fixed amount or can make variable. in case, made variable ($surcharge). since snippet uses subtotal variable, dynamic change -- each time update cart, surcharge re-calculate.
the surcharge minimum charge minus subtotal. happen when subtotal less minimum charge, otherwise end negative surcharge.
in terms of followup design, should have cart message notify people of surcharge. consider using javascript hide surcharge part entirely if subtotal meets minimum charge.
for woocommerce version 2.2.
Comments
Post a Comment