1 回答

TA貢獻1895條經驗 獲得超7個贊
也許您需要的是找出 Mercado pago 啟用的付款方式 ID。
以下代碼將在結帳頁面上向管理員顯示結帳可用付款方式上付款方式標題附近的付款 ID:
add_filter( 'woocommerce_gateway_title', 'display_payment_method_id_for_admins_on_checkout', 100, 2 );
function display_payment_method_id_for_admins_on_checkout( $title, $payment_id ){
? ? if( is_checkout() && ( current_user_can( 'administrator') || current_user_can( 'shop_manager') ) ) {
? ? ? ? $title .= ' <code style="border:solid 1px #ccc;padding:2px 5px;color:red;">' . $payment_id . '</code>';
? ? }
? ? return $title;
}
代碼位于活動子主題(或活動主題)的functions.php 文件中。
找到您要查找的相關付款方式 ID 后,請刪除此代碼。
我重新訪問了檢查 WooCommerce 用戶角色和支付網關,如果它們匹配 - 應用費用答案代碼,處理多個支付 ID:
add_action( 'woocommerce_cart_calculate_fees', 'add_custom_fee' );
function add_custom_fee( $cart ) {
? ? if ( is_admin() && ! defined( 'DOING_AJAX' ) )
? ? ? ? return;
? ? if ( ! is_user_logged_in() )
? ? ? ? return;
? ? ## SETTINGS:
? ? $user_roles? = array( 'vendor', 'administrator' ); // Defined? user roles
? ? // Targeted payment method Ids
? ? $payment_ids = array('cod', 'paypal');?
? ? $percentage? = 5; // Fee percentage
? ? $user? ? ? ? ? ?= wp_get_current_user();? // Get current WP_User Object
? ? $chosen_payment = WC()->session->get('chosen_payment_method'); // Choosen payment method
? ? $cart_subtotal? = $cart->subtotal; // Including taxes - to exclude taxes use $cart->get_subtotal()
? ? // For matched payment Ids and user roles
? ? if ( in_array( $chosen_payment, $payment_ids ) && array_intersect( $user->roles, $user_roles ) ) {?
? ? ? ? $fee_cost = $percentage * $cart_subtotal / 100;? // Calculation
? ? ? ? $cart->add_fee( __('Payment Fee'), $fee_cost, true ); // Add fee (incl taxes)
? ? }
}
現在缺少一些內容:以下內容將刷新付款方式選擇的結帳:
// jQuery - Update checkout on payment method change
add_action( 'wp_footer', 'custom_checkout_jquery_script' );
function custom_checkout_jquery_script() {
? ? if ( is_checkout() && ! is_wc_endpoint_url() ) :
? ? ?>
? ? <script type="text/javascript">
? ? jQuery( function($){
? ? ? ? $('form.checkout').on('change', 'input[name="payment_method"]', function(){
? ? ? ? ? ? $(document.body).trigger('update_checkout');
? ? ? ? });
? ? });
? ? </script>
? ? <?php
? ? endif;
}
代碼位于活動子主題(或活動主題)的functions.php 文件中。經過測試并有效。
顯然 Mercado pago 支付插件不接受費用。
- 1 回答
- 0 關注
- 100 瀏覽
添加回答
舉報