add_shortcode(‘formatted_subscriptions’, function() {
// Use the WPGetAPI shortcode to fetch raw data
$raw_data = do_shortcode(“{
"statusCode": 200,
"message": "Success",
"data": [
{
"id": 1,
"name": "Basic Plan",
"description": "Comes with basic features",
"imageUrl": "https:\/\/cloudloom-api-dev.craftme.dev\/media\/download?media=magnavisio\/general\/Illustration-510c8c1015224e6110e411710121d5148f71.svg",
"status": "active",
"features": [
"50GB Storage per month",
"2GB Bandwidth per month",
"100k Requests per month",
"24\/7 Support",
"Analytics Dashboard",
"Web tool to manage your data"
],
"createdAt": "2024-05-21T10:15:15.000Z",
"updatedAt": "2024-05-21T10:15:15.000Z",
"deletedAt": null,
"plans": [
{
"id": 1,
"subscriptionId": 1,
"interval": "monthly",
"paymentCode": "PLN_ys9jit0mooci0jx",
"country": null,
"currency": "NGN",
"amount": 6500,
"status": "active",
"trialPeriod": 7,
"totalRequest": 100000,
"totalStorage": 53687100000,
"createdAt": null,
"updatedAt": null,
"deletedAt": null
},
{
"id": 2,
"subscriptionId": 1,
"interval": "yearly",
"paymentCode": "PLN_ys9jit0mooci0jx",
"country": null,
"currency": "NGN",
"amount": 65000,
"status": "active",
"trialPeriod": 7,
"totalRequest": 100000,
"totalStorage": 53687100000,
"createdAt": null,
"updatedAt": null,
"deletedAt": null
}
]
},
{
"id": 2,
"name": "Business Plan",
"description": "Comes with advanced features",
"imageUrl": "https:\/\/cloudloom-api-dev.craftme.dev\/media\/download?media=magnavisio\/general\/Illustration-2d6c3c1cd9e3b786f1fbd544fd16bfcc.svg",
"status": "active",
"features": [
"100GB Storage per month",
"5GB Bandwidth per month",
"200k Requests per month",
"24\/7 Support",
"Analytics Dashboard",
"Advance Reporting",
"Web tool to manage your data"
],
"createdAt": "2024-05-21T10:15:15.000Z",
"updatedAt": "2024-05-21T10:15:15.000Z",
"deletedAt": null,
"plans": [
{
"id": 3,
"subscriptionId": 2,
"interval": "monthly",
"paymentCode": "PLN_kcgozjxslmzzvhg",
"country": null,
"currency": "NGN",
"amount": 20000,
"status": "active",
"trialPeriod": 7,
"totalRequest": 200000,
"totalStorage": 107374000000,
"createdAt": null,
"updatedAt": null,
"deletedAt": null
},
{
"id": 4,
"subscriptionId": 2,
"interval": "yearly",
"paymentCode": "PLN_kcgozjxslmzzvhg",
"country": null,
"currency": "NGN",
"amount": 200000,
"status": "active",
"trialPeriod": 7,
"totalRequest": 200000,
"totalStorage": 107374000000,
"createdAt": null,
"updatedAt": null,
"deletedAt": null
}
]
},
{
"id": 3,
"name": "Enterprise Plan",
"description": "Comes with enterprise features",
"imageUrl": "http:\/\/cloudloom-api-dev.craftme.dev\/media\/download?media=magnavisio\/general\/Illustration-33baece5222ead107aed85d4511e7fe5c.svg",
"status": "active",
"features": [
"500GB Storage per month",
"10GB Bandwidth per month",
"1M Requests per month",
"24\/7 Support",
"Analytics Dashboard",
"Advance Reporting",
"Web tool to manage your data",
"Customizable Dashboard",
"Customizable Reporting",
"Advance Media Categorization",
"Advance Media Search",
"AI Media Analysis",
"AI Chatbot"
],
"createdAt": "2024-05-21T10:15:15.000Z",
"updatedAt": "2024-05-21T10:15:15.000Z",
"deletedAt": null,
"plans": [
{
"id": 5,
"subscriptionId": 3,
"interval": "monthly",
"paymentCode": "PLN_eybslmvhbmhilf3",
"country": null,
"currency": "NGN",
"amount": 120000,
"status": "active",
"trialPeriod": 7,
"totalRequest": 1000000,
"totalStorage": 536871000000,
"createdAt": null,
"updatedAt": null,
"deletedAt": null
},
{
"id": 6,
"subscriptionId": 3,
"interval": "yearly",
"paymentCode": "PLN_eybslmvhbmhilf3",
"country": null,
"currency": "NGN",
"amount": 1200000,
"status": "active",
"trialPeriod": 7,
"totalRequest": 1000000,
"totalStorage": 536871000000,
"createdAt": null,
"updatedAt": null,
"deletedAt": null
}
]
}
]
}“);
// Decode the JSON response
$response = json_decode($raw_data, true);
// Check if the response has data
if (!is_array($response) || empty($response[‘data’])) {
return ‘
No subscriptions data available.
‘;
}
// Start building the HTML output
$output = ‘
‘;
// Loop through the subscription plans
foreach ($response[‘data’] as $plan) {
$output .= ‘
‘;
$output .= ‘
$output .= ‘
‘ . esc_html($plan[‘name’]) . ‘
‘;
$output .= ‘
‘ . esc_html($plan[‘description’]) . ‘
‘;
$output .= ‘‘;
// Features list
$output .= ‘
Features:
‘;
$output .= ‘
- ‘;
- ‘ . esc_html($feature) . ‘
foreach ($plan[‘features’] as $feature) {
$output .= ‘
‘;
}
$output .= ‘
‘;
// Pricing plans
$output .= ‘
Pricing:
‘;
$output .= ‘
- ‘;
- ‘ . ucfirst($pricing[‘interval’]) . ‘: ‘ . esc_html($pricing[‘currency’]) . ‘ ‘ . number_format($pricing[‘amount’]) . ‘
foreach ($plan[‘plans’] as $pricing) {
$output .= ‘
‘;
}
$output .= ‘
‘;
$output .= ‘
‘; // Close subscription card
}
$output .= ‘
‘; // Close subscriptions container
// Return the formatted HTML
return $output;
});