Skip to content

Instantly share code, notes, and snippets.

@moxet
Created March 14, 2023 05:51
Show Gist options
  • Save moxet/fe2f301355802814ee857e2588b4d4cb to your computer and use it in GitHub Desktop.
Save moxet/fe2f301355802814ee857e2588b4d4cb to your computer and use it in GitHub Desktop.
<?php
/**
* Plugin Name: Auto Pricing
* Plugin URI: https://www.softemblems.com
* Description: Display auto convert currency for woocommerce products based on user location.
* Version: 0.1
* Text Domain: auto-pricing
* Author: Moxet Khan
* Author URI: https://www.moxetkhan.com
*/
function auto_pricing($atts) {
$product = wc_get_product(get_the_ID());
$thePrice = $product->get_price();
$geoPlugin_array = unserialize( file_get_contents('http://www.geoplugin.net/php.gp?ip=' . $_SERVER['REMOTE_ADDR']) );
echo "Estimate Price for ".$geoPlugin_array["geoplugin_countryName"]. " is <b>".$geoPlugin_array["geoplugin_currencyCode"]." ".round($geoPlugin_array["geoplugin_currencyConverter"]*$thePrice)."</b>";
}
add_shortcode('auto-pricing', 'auto_pricing');
add_action( 'woocommerce_single_product_summary', 'custom_text', 15 );
function custom_text() {
$product = wc_get_product(get_the_ID());
$thePrice = $product->get_price();
$geoPlugin_array = unserialize( file_get_contents('http://www.geoplugin.net/php.gp?ip=' . $_SERVER['REMOTE_ADDR']) );
echo "Estimate Price for ".$geoPlugin_array["geoplugin_countryName"]. " is <b>".$geoPlugin_array["geoplugin_currencyCode"]." ".round($geoPlugin_array["geoplugin_currencyConverter"]*$thePrice)."</b><br/><br/>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment