[英]Remove "proceed to checkout" button based on WooCommerce cart total
[英]Change order button text on checkout based on user role and cart total in WooCommerce
如果用户角色是customer,我们需要查看下面的function。
如果订单总数为0,下面的function会更改下订单按钮的文本,我们需要它来检查用户角色是否也是客户并且总数为0。
到目前为止我们使用的代码
function mishaa_custom_button_text($button_text) {
global $woocommerce;
$total = $woocommerce->cart->total;
if ($total == 0 ) {
$button_text = "Submit Registration";
}
return $button_text;
}
add_filter( 'woocommerce_order_button_text', 'mishaa_custom_button_text' );
https://github.com/woocommerce/woocommerce/blob/4.1.0/includes/wc-template-functions.php#L2240
- Output 结帐时的付款方式。
function filter_woocommerce_order_button_text( $button_text ) {
// Get cart total
$cart_total = WC()->cart->get_cart_contents_total();
// Get current user role
$user = wp_get_current_user();
$roles = ( array ) $user->roles;
// Check
if ( $cart_total == 0 && in_array( 'customer', $roles ) ) {
$button_text = __('Submit Registration', 'woocommerce');
}
return $button_text;
}
add_filter( 'woocommerce_order_button_text', 'filter_woocommerce_order_button_text', 10, 1 );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.