FOX - Currency Switcher for WooCommerce

So erzwingen Sie eine Währung auf der WooCommerce-Kassenseite

Manchmal ist es notwendig, basierend auf der Geschäftslogik eine bestimmte Währung auf der Checkout-Seite zu erzwingen.

Einfachste Methode:

  • Öffnen Sie die functions.php Ihres aktuellen WordPress-Themes und fügen Sie den folgenden Code hinzu:
  • add_filter('wp_head', function(){    
        if(is_checkout()){
            global $WOOCS;
            $WOOCS->set_currency('USD');
        }
    });
  • Ändern Sie 'USD' in eine beliebige benötigte Währung...
Hinweis: Dies funktioniert nur, wenn die Option "Is multiple allowed" aktiviert ist (Ja).

Erweiterte Methode:

// Define forced currency once to avoid repetition
define('WOOCS_FORCED_CHECKOUT_CURRENCY', 'USD'); // Change to your currency

// Method 1: Force on page load
add_action('template_redirect', 'woocs_force_checkout_currency', 999);

// Method 2: Force during checkout process (after WOOCS hooks)
add_action('woocommerce_checkout_process', 'woocs_force_checkout_currency', 999);

function woocs_force_checkout_currency() {
    if (!is_checkout()) {
        return;
    }
    
    global $WOOCS;
    
    if (!isset($WOOCS) || !is_object($WOOCS)) {
        return;
    }
    
    $WOOCS->set_currency(WOOCS_FORCED_CHECKOUT_CURRENCY);
    
    // Also set in storage to prevent reset
    if (isset($WOOCS->storage)) {
        $WOOCS->storage->set_val('woocs_current_currency', WOOCS_FORCED_CHECKOUT_CURRENCY);
    }
}

// Method 3: Force on AJAX updates
add_filter('woocommerce_checkout_update_order_review', 'woocs_force_currency_ajax', 10000);

function woocs_force_currency_ajax($post_data) {
    global $WOOCS;
    
    if (!isset($WOOCS) || !is_object($WOOCS)) {
        return $post_data;
    }
    
    $WOOCS->set_currency(WOOCS_FORCED_CHECKOUT_CURRENCY);
    
    if (isset($WOOCS->storage)) {
        $WOOCS->storage->set_val('woocs_current_currency', WOOCS_FORCED_CHECKOUT_CURRENCY);
    }
    
    return $post_data;
}

// Prevent GeoIP override
add_filter('woocs_force_pay_bygeoip_rules', '__return_false');
Quelle: https://wordpress.org/support/topic/how-to-force-any-currency-on-the-checkout-page/