
Plugin Goal
Client is an all-in-one directories platform for building and managing directory websites, membership sites, and online communities.
The goal of the plugin is to sync WooCommerce Customers(registered customers + guest users) with the clients’ Directories website using their API. Initially, the customer import process was handled via Zapier, a paid platform. However, the client’s idea was to develop this as a WordPress plugin which would be a free option and an easier one for their Directory customers.
Client Requirements
The client’s initial objective was to import the WooCommerce Customers(registered customers + guest users) into their directories website. After having multiple brainstorming sessions with the client, we prepared a requirement document with the list of core features for the first phase of this plugin development.
Below are the key requirements planned for the first phase of this project.
Automatic Import: When a new customer places an order in WooCommerce, the customer will be automatically imported as a member to the directory website via API.
Manual Sync: This option allows all WooCommerce Customers(registered customers + guest users) to be imported into the directory site as members with a single click.
Scheduled Sync: In this case, WooCommerce Customers (registered customers + guest users) will be automatically imported using a WP cron job on a scheduled basis (Daily, Weekly, and Monthly).
Problem Statement
The directory users who own both a WordPress WooCommerce website and client’s website, are struggling to import WooCommerce Customers (registered customers + guest users) into the directory website.
Solution Approach
The plugin was developed using PHP and JavaScript, utilizing the directories’ API to import WooCommerce Customers(registered customers + guest users). The primary feature of the plugin is the ability to import customers in bulk and assign a membership plan ID and member tag IDs before the import process. This ensures that imported customers are automatically assigned the chosen membership plan and member tags on the clients’ website.
Challenges & Solutions
Duplicate Members
Issue:
We encountered an issue with duplicate customer creation on the client website during the import process. The website was accepting the same username and email address repeatedly, causing the same user to be created multiple times.
Solution:
To resolve the duplicate customer creation issue, we implemented an email address check via the API. Before creating a customer, we check if the email address already exists on the client’s website. If it exists, we skip the creation; if not, we proceed to create the customer. By following this approach, we had to make 2 API calls to create 1 member. However, we decided to follow this approach to prevent duplicate customer records from being created.
API Rate Limits & Server Timeout
Issue:
If we attempted to import a large batch of customers, we encountered an API request failure due to API rate limits, resulting in the IP address being blocked for exceeding the allowed number of API requests.
We also faced a server timeout issue when importing a high number of customers using the Auto-Sync Schedule (via a cron job). The server would time out, unable to handle the large volume of customer imports.
Solution:
The client API allows 100 requests per minute, which led us to implement API Throttling strategy to address the API rate limit issue:
- Manual Sync: We calculated the number of requests that would be needed for importing 1 member and planned the number of users to be imported in a batch, an interval gap to provided within each batch based on the API rate limits and this prevents exceeding the API rate limit issue.
- Auto-Sync Schedule (Cron Job): To resolve the server timeout issue when importing a high number of customers, we follow a similar batch-based approach. We import customers in batches and run a single cron event every 30 seconds to process each batch. This method ensures that the import process runs smoothly without server timeouts.
Security Measures
To ensure the security of sensitive information, we implemented encryption for storing the API key. Before storage, the API key is encrypted to protect it from unauthorized access, ensuring the safety of user data.
Code Optimization
- We ensured that all text output is properly sanitized and escaped using the esc_html__ function. This prevents potential security vulnerabilities such as XSS (Cross-Site Scripting) by ensuring that all dynamic content is displayed safely.
- The UI styles were optimized by consolidating repeated styles into common CSS classes. This improves the maintainability and readability of the code, reduces redundancy, and ensures a more efficient load time for the plugin’s user interface.
Testing and Optimization
We conducted thorough testing to ensure the core functionalities of the plugin are working seamlessly. This included testing the following processes:
Automatic Sync: We verified that the plugin automatically synchronizes newly placed WooCommerce orders with the client website. This ensures that customers are added automatically when they make a purchase on WooCommerce.
Manual Sync: We tested the manual synchronization process to ensure that users can manually trigger customer imports from WooCommerce to client’s Directories without any issues. The process was evaluated for stability, accuracy, and performance.
Auto-Sync Schedule (Cron Job): We validated the automatic sync schedule, ensuring that the cron job runs as expected and imports customers at scheduled intervals. The cron job was tested for efficiency and performance when dealing with large batches of customer data.
Plugin Check (PCP)
Apart from the regular testing, we also used WordPress’s official Plugin Check, a tool for testing whether your plugin meets the required standards for the WordPress.org plugin directory, and ensured that our plugin meets all the standard criteria for publishing the plugin in WordPress’s Plugin Repository.
Conclusion
The plugin successfully addressed the client’s goal of importing WooCommerce customers and Registered customer role users into the client’s website, providing a seamless integration via the client API. Overall, the solution meets the client’s needs, enhancing their workflow and integrating WooCommerce with clients directory website seamlessly while maintaining security and performance standards.

This Case Study was written by Bharath. Bharath is a skilled developer with expertise in building websites, web applications, and custom plugins. His structured approach to documentation ensures that his work is not only efficient but also valuable to fellow developers. Beyond coding, he brings a fun-loving spirit and a caring nature to the team, making collaboration both productive and enjoyable.