PHP Classes

How to Implement a PHP Price Calculator That Automatically Adjusts Prices According to the User Location Using the Class Auto-Price: Adjust prices based on the current user location

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-07-13 (1 month ago) RSS 2.0 feedNot yet rated by the usersTotal: 25 This week: 2All time: 11,198 This week: 27Up
Version License PHP version Categories
autoprice 1.0MIT/X Consortium ...5PHP 5, E-Commerce, User Management, F...
Description 

Author

This class can adjust prices based on the current user location.

It uses a Web service to determine the user country based on the IP address of the computer that the user is using to access the current site Web pages.

The class returns a factor number that determines the factor that the prices of products should be multiplied to adjust those prices according to the user country.

Innovation Award
PHP Programming Innovation award nominee
July 2024
Nominee
Vote
Companies that sell products and services may need to adjust prices according to the location of the custom to consider factors like physical shipping costs or payment method fees.

This package provides a simple solution based on a class that returns a multiplying factor for prices according to the user country automatically detected from the user's computer IP address.

Manuel Lemos
Picture of The Algoslingers
  Performance   Level  
Name: The Algoslingers <contact>
Classes: 9 packages by
Country: Ghana Ghana
Innovation award
Innovation award
Nominee: 5x

Winner: 1x

Example

<?php
require 'vendor/autoload.php';

use
thealgoslingers\AutoPrice;

// Usage example
$api_key = 'your_api_key_here'; // api key from ip2location.io

// the default base price is approximately
// or same as 1 USD. So we assume price is
// being converted from USD
$base_price = 100.0;//base price to be converted from

$dp = new AutoPrice($api_key, $base_price);
$user_ip = '8.8.8.8';// ip of the user

echo $dp->calculatePrice($user_ip);


Details

Leverage real-time data and advanced algorithms to calculate prices bases on the user's location with Autoprice.

<h1>Requirements</h1> Please obtain Api Key from <a href="https://www.ip2location.io/">IP2LOCATION.IO</a>

<h1>Installation</h1>

composer require thealgoslingers/autoprice

<h1>Usage</h1> <strong>NOTE: </strong><p>Autoprice returns the (converted) currency with it's associated currency code. So it will not be necessary to manually add the currency(it's) code again at the end. For instance, "10" from USD to Ghanaian cedis, Autoprice will return "GHS15.152" instead of just "15.532".</p> <p>Some Api plans do not include the country's currency code. In this case, the raw figures will be returned. I.e. Amount without a currency code.</p> <p>See <a href="https://www.ip2location.io/pricing">ip2location</a> for more details.</p>

<?php
require 'vendor/autoload.php';

use thealgoslingers\AutoPrice;

// Usage example
$api_key = 'your_api_key_here'; // api key from ip2location.io

// the default base price is approximately
// or same as 1 USD. So we assume price is 
// being converted from USD 
$base_price = 100.0;//base price to be converted from

$dp = new AutoPrice($api_key, $base_price);
$user_ip = '8.8.8.8';// ip of the user 

echo $dp->calculatePrice($user_ip);


  Files folder image Files (5)  
File Role Description
Files folder imagesrc (1 file, 1 directory)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file ReadMe.md Doc. Read me

  Files folder image Files (5)  /  src  
File Role Description
Files folder imageexamples (1 file)
  Plain text file AutoPrice.php Class Class source

  Files folder image Files (5)  /  src  /  examples  
File Role Description
  Accessible without login Plain text file test.php Example Example script

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:25
This week:2
All time:11,198
This week:27Up