gpt4 book ai didi

php - 使用 sprintf 显示 WooCommerce 付款方式费用的不同文本标签

转载 作者:行者123 更新时间:2023-12-04 08:23:33 25 4
gpt4 key购买 nike

这是基于 Assign a percentage fee to WooCommerce payment methods based on user roles .我想扩展它以在 sprintf 函数中的“卡费”标签之前显示另一个自定义描述。我想显示 $description 然后显示“卡费”然后(百分比费用)。

add_action('woocommerce_cart_calculate_fees', 'sm_credit_card_fee_role_gateway' );
function sm_credit_card_fee_role_gateway( $cart ){
if ( is_admin() && !defined('DOING_AJAX') )
return;

// Only on checkout page and logged in users
if ( ! ( is_checkout() && ! is_wc_endpoint_url() ) || ! is_user_logged_in() )
return;

$wpuser_object = wp_get_current_user();
$allowed_roles = array('administrator', 'default_wholesaler', 'wholesaler-non-vat-registered', 'shop_manager');

if ( array_intersect($allowed_roles, $wpuser_object->roles) ){
$payment_method = WC()->session->get('chosen_payment_method');

if ( 'cardgatecreditcard' === $payment_method ){
$percentage = 8.25;
$description = 'Credit';
}
elseif ( 'cardgatesofortbanking' === $payment_method ){
$percentage = 6;
$description = 'SofortBanking';
}
elseif ( 'cardgategiropay' === $payment_method ){
$percentage = 3.15;
$description = 'GiroPay';
}
elseif ( 'cardgateideal' === $payment_method ){
$percentage = 2.1;
$description = 'iDeal';
}
}
if ( isset($percentage) ) {
$surcharge = ($cart->cart_contents_total + $cart->shipping_total) * $percentage / 100;
$cart->add_fee( sprintf( __(' $description Card Fee (%s)', 'woocommerce'), $percentage . '%' ), $surcharge, true );
}
}

最佳答案

只需替换以下代码行:

$cart->add_fee( sprintf( __(' $description Card Fee (%s)', 'woocommerce'), $percentage . '%' ), $surcharge, true );
和:
$cart->add_fee( sprintf( __('%s Card Fee (%s)', 'woocommerce'), $description, $percentage . '%' ), $surcharge, true );
测试和工作

关于php - 使用 sprintf 显示 WooCommerce 付款方式费用的不同文本标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65384428/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com