Last active
June 17, 2019 18:48
-
-
Save nczz/55c4d34674fde5cb98324ef337821902 to your computer and use it in GitHub Desktop.
[WooCommerce] 付款方法項目的排序控制(訂單滿額、變更順序) https://www.mxp.tw/8513/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//較早觸發、無法改變付款方式順序 | |
function mxp_woocommerce_payment_gateways($payment_gateways) { | |
// 判斷付款方式的 Class 名稱後根據邏輯比對取消註冊 | |
foreach ($payment_gateways as $key => $gateways) { | |
if ($gateways == "WC_Gateway_COD") { | |
unset($payment_gateways[$key]); | |
} | |
} | |
return $payment_gateways; | |
} | |
add_filter('woocommerce_payment_gateways', 'mxp_woocommerce_payment_gateways', 11, 1); | |
//較晚觸發、可以用來改變付款方式順序 | |
function mxp_woocommerce_available_payment_gateways($available_gateways) { | |
// 訂單金額小於 1000 元就取消某個付款方式 | |
if (intval(WC()->cart->get_totals()['subtotal']) < 1000) { | |
unset($available_gateways['bacs']); | |
} | |
//回傳倒序過的付款方式 | |
return array_reverse($available_gateways); | |
}; | |
add_filter('woocommerce_available_payment_gateways', 'mxp_woocommerce_available_payment_gateways', 11, 1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment