Simple Gold Rates
Display gold prices from Google Sheets with real-time volatility animation and mobile-responsive design Goto settings > Gold Rates to configure.
by Tiran Chanuka · github.com/tiranchanuka/simple-gold-rates
★ 0stars
0forks
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/tiranchanuka/simple-gold-rates/archive/refs/heads/main.zipSimple Gold Rates Plugin
Version 2.0.0 - Complete Refactored Edition
📁 Folder Structure
simple-gold-rates/
├── simple-gold-rates.php # Main plugin file (OOP structure)
├── index.php # Security file
├── assets/
│ ├── css/
│ │ └── frontend.css # Responsive styles with animations
│ └── js/
│ └── frontend.js # Volatility animation system
└── README.md # This file
✨ Features
- Google Sheets Integration: Fetch gold prices automatically
- Real-time Volatility: Prices fluctuate randomly like trading charts
- Mobile Responsive: Works perfectly on all devices
- Smooth Animations: Modern hover effects and price updates
- Clean Code: Object-oriented, well-structured, maintainable
- Admin Dashboard: Beautiful UI to view current rates
🚀 Usage
- Admin Settings: Go to
Settings > Gold Rates - Configure:
- Google Apps Script URL
- Volatility Interval (default: 2000ms)
- Volatility Range (default: ±2000 LKR)
- Display: Use shortcode
[gold_price_table]on any page
📊 Data Format
Expected JSON from Google Sheets:
{
"18": { "buying": 274000, "selling": 281000, "active": 1 },
"21": { "buying": 322000, "selling": 327000, "active": 1 },
"22": { "buying": 336000, "selling": 342000, "active": 1 },
"24": { "buying": 366000, "selling": 374000, "active": 1 }
}
📋 Google Apps Script Setup
Step 1: Create the Script
- Open your Google Sheet with gold prices
- Go to Extensions > Apps Script
- Delete any existing code and paste this:
function doGet() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");
var data = {
24: {
buying: sheet.getRange("C4").getValue(),
selling: sheet.getRange("D4").getValue(),
active: sheet.getRange("E4").getValue(),
},
22: {
buying: sheet.getRange("C5").getValue(),
selling: sheet.getRange("D5").getValue(),
active: sheet.getRange("E5").getValue(),
},
21: {
buying: sheet.getRange("C6").getValue(),
selling: sheet.getRange("D6").getValue(),
active: sheet.getRange("E6").getValue(),
},
18: {
buying: sheet.getRange("C7").getValue(),
selling: sheet.getRange("D7").getValue(),
active: sheet.getRange("E7").getValue(),
},
};
return ContentService.createTextOutput(JSON.stringify(data)).setMimeType(
ContentService.MimeType.JSON,
);
}
Step 2: Adjust Cell References
⚠️ IMPORTANT: Make sure your Google Sheet columns match:
- Column C: Buying prices
- Column D: Selling prices
- Column E: Active status (1 for active, 0 for inactive)
- Row 4: 24K gold data
- Row 5: 22K gold data
- Row 6: 21K gold data
- Row 7: 18K gold data
Example Sheet Layout:
| A | B | C | D | E |
|-------|-----|---------|---------|---|
| Karat | % | Buying | Selling | Active |
| 24K | 100%| 366000 | 374000 | 1 |
| 22K | 91.7| 336000 | 342000 | 1 |
| 21K | 87.5| 322000 | 327000 | 1 |
| 18K | 75% | 274000 | 281000 | 1 |
If your sheet structure is different, update the cell references in the script (e.g., change C4 to match your buying price cell for 24K).
Step 3: Deploy the Script
- Click Deploy > New deployment
- Click the gear icon ⚙️ and select Web app
- Settings:
- Description: Gold Rates API
- Execute as: Me
- Who has access: Anyone
- Click Deploy
- Authorize the script (click "Authorize access" and allow permissions)
- Copy the Web App URL (looks like:
https://script.google.com/macros/s/AKfycb.../exec)
Step 4: Test the URL
- Paste the URL in your browser
- You should see JSON data like:
{"24":{"buying":366000,"selling":374000,"active":1},"22":{...}} - ✅ If you see the data → Script is working!
- ❌ If you see an error → Check your cell references and sheet name
Step 5: Add URL to WordPress
- Go to WordPress Admin > Settings > Gold Rates
- Paste the Web App URL in Google Apps Script URL field
- Click Save Changes
- Click 🔄 Sync Prices Now to test
- Check if the cards display correctly on your page
🎨 Responsive Breakpoints
- Mobile: < 480px (1 column, optimized spacing)
- Tablet: 600px - 1023px (2 columns)
- Desktop: 1024px+ (4 columns)
- Large Desktop: 1440px+ (enhanced spacing)
🔄 How Volatility Works
- Random walk algorithm (like real trading charts)
- Each tick:
currentPrice += random(-range, +range) - Independent movements for buying & selling prices
- Smooth animations with pulse effects
- Example: 350,000 → 349,500 → 351,200 → 350,800...
🛠️ Development
Clean, maintainable code with:
- Object-oriented architecture
- Class-based organization
- Proper WordPress hooks
- Security best practices
- Mobile-first CSS
- ES6 JavaScript
📝 Changelog
Version 2.0.0
- Complete plugin refactor
- Improved folder structure
- Enhanced volatility system
- Better mobile responsive design
- Smooth animations
- Clean OOP code