Build a Custom Shopify Customer Registration App (With Metafields) – Step-by-Step Guide (PHP)
Build a Custom Shopify Customer Registration App (With Metafields) – Step-by-Step Guide (PHP)
In this tutorial, we’ll build a simple Shopify custom app using PHP that:
Creates customers from a custom frontend form
Saves additional fields (Instagram, Facebook, ENI, Website, etc.) using metafields
Adds a wholesale tag to customers
Uses Shopify OAuth authentication
Works with the new Shopify customer account system
This is perfect if you want a wholesale registration form or custom onboarding system.
🚀 Step 1: Create Shopify Custom App
Go to your Shopify Admin
Navigate to:
Settings → Apps and Sales Channels → Develop AppsCreate a new app
Configure API scopes:
read_customers
write_customers
Set URLs:
App URL:
https://yourdomain.com/
Redirect URL:
https://yourdomain.com/callback.php
🔐 Step 2: OAuth Authentication
Create a file:
📁 callback.php
<?php
include 'config.php';
if (!isset($_GET['code']) || !isset($_GET['shop'])) {
die("Missing parameters");
}
$shop = $_GET['shop'];
$code = $_GET['code'];
$url = "https://$shop/admin/oauth/access_token";
$data = [
"client_id" => $apiKey,
"client_secret" => $apiSecret,
"code" => $code
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, ["Content-Type: application/json"]);
$response = curl_exec($ch);
curl_close($ch);
$responseData = json_decode($response, true);
if (isset($responseData['access_token'])) {
saveAccessToken($responseData['access_token']);
echo "App installed successfully!";
} else {
print_r($responseData);
}
📁 config.php
<?php
$apiKey = "YOUR_API_KEY";
$apiSecret = "YOUR_API_SECRET";
$accessTokenFile = __DIR__ . '/access_token.txt';
function saveAccessToken($token) {
global $accessTokenFile;
file_put_contents($accessTokenFile, $token);
}
function getAccessToken() {
global $accessTokenFile;
return file_exists($accessTokenFile) ? file_get_contents($accessTokenFile) : null;
}
🧾 Step 3: Create Registration Form
📁 customer_register.php
<form method="POST" action="https://yourdomain.com/register_customer.php">
<input name="first_name" placeholder="First Name" required>
<input name="last_name" placeholder="Last Name" required>
<input name="email" type="email" required>
<input name="phone" placeholder="Phone">
<input name="company" placeholder="Company">
<input name="address" placeholder="Address">
<select name="country" required>
<option value="United States">United States</option>
<option value="Canada">Canada</option>
<option value="Mexico">Mexico</option>
</select>
<input name="state" placeholder="State">
<input name="postal_code" placeholder="Postal Code">
<input name="eni_code" placeholder="ENI Code">
<input name="instagram" placeholder="Instagram">
<input name="facebook" placeholder="Facebook">
<input name="tiktok" placeholder="TikTok">
<input name="website" placeholder="Website">
<button type="submit">Register</button>
</form>
⚙️ Step 4: Create Customer + Save Metafields
📁 register_customer.php
<?php
include 'config.php';
$accessToken = getAccessToken();
$shop = "your-store.myshopify.com";
if (!$accessToken) {
die("Install app first");
}
$firstName = $_POST['first_name'];
$lastName = $_POST['last_name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$company = $_POST['company'];
$address = $_POST['address'];
$country = $_POST['country'];
$state = $_POST['state'];
$postal = $_POST['postal_code'];
$eni = $_POST['eni_code'];
$instagram = $_POST['instagram'];
$facebook = $_POST['facebook'];
$tiktok = $_POST['tiktok'];
$website = $_POST['website'];
$customerData = [
"customer" => [
"first_name" => $firstName,
"last_name" => $lastName,
"email" => $email,
"phone" => $phone,
"verified_email" => true,
"tags" => "wholesale",
"addresses" => [
[
"address1" => $address,
"city" => "N/A",
"province" => $state,
"country" => $country,
"zip" => $postal,
"company" => $company
]
]
]
];
$ch = curl_init("https://$shop/admin/api/2024-01/customers.json");
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Content-Type: application/json",
"X-Shopify-Access-Token: $accessToken"
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($customerData));
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response, true);
if (!isset($data['customer']['id'])) {
print_r($data);
exit;
}
$customerId = "gid://shopify/Customer/" . $data['customer']['id'];
🧩 Step 5: Save Custom Fields (Metafields)
$graphql = <<<GQL
mutation {
metafieldsSet(metafields: [
{ ownerId: "$customerId", namespace: "custom", key: "eni_code", type: "single_line_text_field", value: "$eni" },
{ ownerId: "$customerId", namespace: "custom", key: "instagram", type: "single_line_text_field", value: "$instagram" },
{ ownerId: "$customerId", namespace: "custom", key: "facebook", type: "single_line_text_field", value: "$facebook" },
{ ownerId: "$customerId", namespace: "custom", key: "tiktok", type: "single_line_text_field", value: "$tiktok" },
{ ownerId: "$customerId", namespace: "custom", key: "website", type: "single_line_text_field", value: "$website" }
]) {
metafields { key value }
userErrors { message }
}
}
GQL;
🎉 Step 6: Success Message (Popup)
After successful registration:
echo "Registration successful! We will review your account.";
Or use a modal popup for better UX.
🌐 Step 7: Show Form in Shopify Frontend
You have 2 options:
Option 1 (Simple)
Create a Shopify page and embed:
<iframe src="https://yourdomain.com/customer_register.php" width="100%" height="800"></iframe>
Option 2 (Better)
Use Shopify theme + AJAX (advanced)
🧠 Important Notes
Shopify does NOT allow duplicate emails
Phone must be in international format (
+123456789)Country must match Shopify-supported values
Custom fields must be saved using metafields
✅ Final Result
After setup:
✔ Customer is created
✔ Tagged as wholesale
✔ Custom data saved via metafields
✔ Form works on frontend
✔ Ready for approval workflow
🚀 What You Can Build Next
Admin approval system
Auto email after registration
Show metafields in customer account
Wholesale pricing access control
🎯 Conclusion
You’ve now built a fully functional Shopify custom registration system using PHP without any frameworks.
This approach gives you full control over:
Customer onboarding
Data collection
Wholesale workflows
If you want to extend this further, you can integrate:
Shopify Webhooks
Admin dashboards
React-based embedded apps
Happy coding! 🚀
In this guide, we explore real-world strategies used by professional developers to create fast, maintainable web applications.