簡體   English   中英

在 WooCommerce 中根據用戶角色和購物車總數更改結帳時的訂單按鈕文本

[英]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 結帳時的付款方式。

您可以使用wp_get_current_user();

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM