Skip to content

Instantly share code, notes, and snippets.

@xlplugins
Created September 14, 2023 14:53
Show Gist options
  • Save xlplugins/c7969b42f70639d82f363146df6871db to your computer and use it in GitHub Desktop.
Save xlplugins/c7969b42f70639d82f363146df6871db to your computer and use it in GitHub Desktop.
Allow stripe keys to dynamically change
function is_CH_Country() {
if ( is_null( WC() ) || is_null( WC()->customer ) ) {
return false;
}
return WC()->customer->get_shipping_country() == "CH";
}
add_filter( 'fkwcs_api_client_public_key', 'bbloomer_conditional_publishable_key_fkwcs', 9999 );
function bbloomer_conditional_publishable_key_fkwcs( $public_key ) {
if ( ! is_CH_Country() ) {
return $public_key;
}
return 'pk_live_xxxxxxxxxxxxxxxxxxxx';
}
add_filter( 'fkwcs_api_client_secret', 'bbloomer_conditional_private_key_headers_fkwcs', 9999 );
function bbloomer_conditional_private_key_headers_fkwcs( $client_secret ) {
if ( ! is_CH_Country() ) {
return $client_secret;
}
// STRIPE Live Secret Key HERE
return 'sk_live_xxxxxxxxxxxxxxxxxxx';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment