Skip to content

Instantly share code, notes, and snippets.

@nczz
Last active June 17, 2019 18:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nczz/55c4d34674fde5cb98324ef337821902 to your computer and use it in GitHub Desktop.
Save nczz/55c4d34674fde5cb98324ef337821902 to your computer and use it in GitHub Desktop.
[WooCommerce] 付款方法項目的排序控制(訂單滿額、變更順序) https://www.mxp.tw/8513/
<?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