feat: Add WooCommerce store settings (currency, formatting) to standalone mode

This commit is contained in:
dwindown
2025-11-04 23:43:07 +07:00
parent 0fbe35f198
commit 8960ee1149

View File

@@ -72,6 +72,9 @@ class StandaloneAdmin {
]; ];
} }
// Get WooCommerce store settings
$store_settings = self::get_store_settings();
// Get asset URLs // Get asset URLs
$plugin_url = plugins_url( '', dirname( dirname( __FILE__ ) ) ); $plugin_url = plugins_url( '', dirname( dirname( __FILE__ ) ) );
$asset_url = $plugin_url . '/admin-spa/dist'; $asset_url = $plugin_url . '/admin-spa/dist';
@@ -117,6 +120,9 @@ class StandaloneAdmin {
nonce: <?php echo wp_json_encode( $nonce ); ?>, nonce: <?php echo wp_json_encode( $nonce ); ?>,
isDev: <?php echo ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ? 'true' : 'false'; ?> isDev: <?php echo ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ? 'true' : 'false'; ?>
}; };
// WooCommerce store settings (currency, formatting, etc.)
window.WNW_STORE = <?php echo wp_json_encode( $store_settings ); ?>;
</script> </script>
<script type="module" src="<?php echo esc_url( $js_url ); ?>"></script> <script type="module" src="<?php echo esc_url( $js_url ); ?>"></script>
@@ -128,4 +134,28 @@ class StandaloneAdmin {
</html> </html>
<?php <?php
} }
/**
* Get WooCommerce store settings for frontend
*
* @return array Store settings (currency, decimals, separators, etc.)
*/
private static function get_store_settings(): array {
// Get WooCommerce settings with fallbacks
$currency = function_exists( 'get_woocommerce_currency' ) ? get_woocommerce_currency() : 'USD';
$currency_sym = function_exists( 'get_woocommerce_currency_symbol' ) ? get_woocommerce_currency_symbol( $currency ) : '$';
$decimals = function_exists( 'wc_get_price_decimals' ) ? wc_get_price_decimals() : 2;
$thousand_sep = function_exists( 'wc_get_price_thousand_separator' ) ? wc_get_price_thousand_separator() : ',';
$decimal_sep = function_exists( 'wc_get_price_decimal_separator' ) ? wc_get_price_decimal_separator() : '.';
$currency_pos = get_option( 'woocommerce_currency_pos', 'left' );
return [
'currency' => $currency,
'currency_symbol' => $currency_sym,
'decimals' => (int) $decimals,
'thousand_sep' => (string) $thousand_sep,
'decimal_sep' => (string) $decimal_sep,
'currency_pos' => (string) $currency_pos,
];
}
} }