Created
May 22, 2023 23:56
-
-
Save mathvp/4b60588d61bd737cb2b7a06500584885 to your computer and use it in GitHub Desktop.
Peachpay Currency
This file contains hidden or 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 | |
/* | |
Plugin Name: Peachpay Currency Switcher shortcode | |
Description: Custom Peachpay currency switcher shortcode | |
Version: 1.0.0 | |
Author: Matheus Vieira | |
Author URI: https://github.com/mathvp | |
License: GPL2 | |
*/ | |
if (!defined('ABSPATH')) { | |
die; | |
} | |
function peachpay_currency_switcher_register_plugin_scripts () { | |
if ( ! wp_script_is( 'peachpay_currency_widget', 'enqueued' )) { | |
wp_register_script('peachpay_currency_widget', plugins_url( 'peachpay-for-woocommerce/public/dist/currency-switcher-widget.bundle.js' ), array(), '1.92.2', true); | |
} | |
} | |
add_action( 'wp_enqueue_scripts', 'peachpay_currency_switcher_register_plugin_scripts' ); | |
function custom_peachpay_currency_switcher() { | |
$currencies = peachpay_currencies_by_iso( peachpay_get_client_country() ); | |
$active_currency = ( $_COOKIE && isset( $_COOKIE['pp_active_currency'] ) ) ? sanitize_text_field( wp_unslash( $_COOKIE['pp_active_currency'] ) ) : peachpay_best_currency( peachpay_get_client_country() ); | |
$html = '<select id=pp-currency-widget>'; | |
foreach ( $currencies as $currency ) { | |
$html .= '<option value="' . esc_html( $currency ); | |
$html .= $active_currency === $currency ? '" selected>' : '">'; | |
$html .= esc_html( PEACHPAY_SUPPORTED_CURRENCIES[ $currency ] ); | |
$html .= '</option>'; | |
} | |
$html .= '</select>'; | |
return $html; | |
} | |
add_shortcode('custom-peachpay-currency-switcher', 'custom_peachpay_currency_switcher'); | |
// Just use the shortcode: [custom-peachpay-currency-switcher] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment