/**
Tadd_filter( 'woocommerce_available_payment_gateways', 'filter_gateways_by_shipping_method' );

function filter_gateways_by_shipping_method( $available_gateways ) {
    // 如果是在後台或是沒有選擇運送方式，不執行
    if ( is_admin() || is_checkout() === false ) return $available_gateways;
    
    // 取得目前選擇的運送方式
    $chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
    $chosen_shipping = isset( $chosen_methods[0] ) ? $chosen_methods[0] : '';

    // 規則 1：選擇「黑貓宅配」時，只顯示「郵局ATM」與「綠界信用卡」
    // 根據截圖，黑貓宅配的 ID 應為 'flat_rate:2'
    if ( strpos( $chosen_shipping, 'flat_rate:2' ) !== false ) {
        // 請確認您的付款 ID：'bacs' 通常是銀行轉帳，'ecpay_jbc' 可能是綠界信用卡
        $keep_gateways = array( 'bacs', 'ecpay_jbc' ); 
        foreach ( $available_gateways as $gateway_id => $gateway ) {
            if ( ! in_array( $gateway_id, $keep_gateways ) ) {
                unset( $available_gateways[ $gateway_id ] );
            }
        }
    }

    // 規則 2：選擇「超商取貨」時，只顯示「貨到付款」
    // 綠界物流 7-11 通常 ID 包含 'ecpay_shipping_711'，全家包含 'ecpay_shipping_fami'
    if ( strpos( $chosen_shipping, 'ecpay_shipping_711' ) !== false || 
         strpos( $chosen_shipping, 'ecpay_shipping_fami' ) !== false ) {
        
        $keep_gateways = array( 'cod' ); // 'cod' 是 WooCommerce 預設的貨到付款 ID
        foreach ( $available_gateways as $gateway_id => $gateway ) {
            if ( ! in_array( $gateway_id, $keep_gateways ) ) {
                unset( $available_gateways[ $gateway_id ] );
            }
        }
    }

    return $available_gateways;
}heme Name: Astra Child
Author: Brainstorm Force
Author URI: http://wpastra.com/about/
Description: Astra is the fastest, fully customizable & beautiful theme suitable for blogs, personal portfolios and business websites. It is very lightweight (less than 50KB on frontend) and offers unparalleled speed. Built with SEO in mind, Astra comes with schema.org code integrated so search engines will love your site. Astra offers plenty of sidebar options and widget areas giving you a full control for customizations. Furthermore, we have included special features and templates so feel free to choose any of your favorite page builder plugin to create pages flexibly. Some of the other features: # WooCommerce Ready # Responsive # Compatible with major plugins # Translation Ready # Extendible with premium addons # Regularly updated # Designed, Developed, Maintained & Supported by Brainstorm Force. Looking for a perfect base theme? Look no further. Astra is fast, fully customizable and beautiful theme!
Version: 1.0.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Text Domain: astra-child
Template: astra
*/