admin管理员组文章数量:1122826
I found some code here: / that prevents wholesale customers from putting in an order unless they satisfy a minimum cart amount. The problem is that if I change my site's currency from USD to CAD, for example, the threshold in CAD is lower than the USD equivalent because $250 CAD is only ~$183 USD. The opposite would be true for EUR. $250 USD would be ~267 EUR.
This is the cart page code for cart-totals.php file:
<div class="wc-proceed-to-checkout"> <?php
//Get current user and check the user role.
$current_screen_user = wp_get_current_user();
// In my scenario “wholesale_buyer” is the user role for which I want this validation. You can add your user roles.
if( in_array( 'wholesale_buyer', $current_screen_user->roles ) ) {
$minimum = 50; // Set the minimum amt.
$cart_amt = WC()->cart->subtotal; // cart sub_total, this is actual total excluding discounts and shipping.
if ( $cart_amt < $minimum ) {
if( is_cart() ) {
//Added notices for cart page.
wc_print_notice(
sprintf( 'You must have an order with a minimum of %s to place your order, your current order total is %s.' ,
wc_price( $minimum ),
wc_price( $cart_amt )
), 'error'
);
} else {
//Added notice msg for checkout page.
wc_add_notice(
sprintf( 'You must have an order with a minimum of %s to place your order, your current order total is %s.' ,
wc_price( $minimum ),
wc_price( $cart_amt)
), 'error'
);
}
} else {
do_action( 'woocommerce_proceed_to_checkout' );
}
} else {
do_action( 'woocommerce_proceed_to_checkout' );
}
?>
</div>
This is the checkout page code that goes into function.php or in my case gets added to my snippets plugin:
<?php
add_action( 'woocommerce_checkout_process', 'wdm_wu_minimum_order_amount' );
function wdm_wu_minimum_order_amount() {
$current_screen_user = wp_get_current_user();
if( in_array( 'wholesale_buyer', $current_screen_user->roles ) ) {
$minimum = 50;
if ( WC()->cart->subtotal < $minimum ) {
if( is_cart() ) {
wc_print_notice(
sprintf( 'You must have an order with a minimum of %s to place your order, your current order total is %s.' ,
wc_price( $minimum ),
wc_price( WC()->cart->subtotal )
), 'error'
);
} else {
wc_add_notice(
sprintf( 'You must have an order with a minimum of %s to place your order, your current order total is %s.' ,
wc_price( $minimum ),
wc_price( WC()->cart->subtotal )
), 'error'
);
} } } }
本文标签: functionsNeed help adding currency conversion to this code
版权声明:本文标题:functions - Need help adding currency conversion to this code 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736302474a1931546.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论