Create e-commerce SaaS in word press with simple digital

Over the past few years, many people, including me, have been talking about how WordPress has developed into a place that can drive applications including the SaaS platform. One reason is the WordPress rest API. I totally agree, but I think this is a great choice, one of the reasons is that we have a number of fully functional e-commerce solutions. I wrote about how to use laravel cashier to implement my own subscription request system and compare it with the WordPress e-commerce platform. Since then, I have thought a lot about the things provided by e-commerce systems such as woocommerce or EDD (easy digital ). It’s not just about checking out and charging credit cards. Integration with account management, invoice issuance and marketing automation platform. The
When I wrote this post, I launched a small SaaS product, caldera forms PDF, to convert caldera forms projects to PDF. It is a laravel app that handles its own settlement. The new SaaS product caldera forms Pro is a hybrid application of WordPress and laravel. All e-commerce is handled by easy digital . This article introduces several methods of using EDD to drive SaaS products. Used to restrict access to rest API endpoints in two ways. When WordPress drives applications and applications built outside of WordPress. The
We will use EDD because it is my most familiar e-commerce plug-in for implementing these concepts. My code example is a simplified version of the plug-in that I will provide as open source and provide links to. Due to the hybrid approach, we use WordPress for e-commerce, marketing automation, and documentation, but also laravel and vuejs for applications. As a result, API requests to applications do not go through WordPress. App UI certification includes word press. We will discuss this in other articles. What I want to discuss is EDD and how EDD recovers integration with external applications. Each time you create, update, or create a subscription, you need to send an API request to the application. In addition, since there are many other types of subscription based products, it is important to restrict this logic to only work in a specific subscription. The
Part of this article is calderaforms. Based on plug-ins written to handle EDD interactions running on COM and caldera forms pro. Although it is a site-specific plug-in and cannot be reused intact, I hope others can read, copy and learn. Detaching the logical EDD recursion from the plug-in API provides all the hooks required to perform this operation. However, before connecting these events, you have created the required logic for the class that is completely disconnected from the hook. This makes it easier to test my code and use it when you need to use other methods of subscription. The
The first step is to create a subscription class to handle all the logic for this subscription. Torque’s recent article discussed decorator patterns as an alternative to class extensions. Because I think this subscription object plays a fundamentally different role from the edd\u subscription class, I decided to decorate the edd\u subscription class instead of extending the edd\u subscription class. The task of the edd_subscription class is to describe the subscription status of the database and update it according to these statuses. Therefore, it is another responsibility by default. This new class describes the relationship between WordPress and app. In addition, edd_subscription has been executed
Since it is a monthly or annual subscription, if you use the rest API, you still need to control access based on the subscription. The
This article section describes how to control access to the WordPress rest API based on subscriptions and provide meaningful error responses available to applications. In fact, we have built a fully functional plug-in that can perform all these tasks using EDD’s recovery payment add-on function. It doesn’t have a strong connection to EDD, and it can easily work with membership plug-ins or woocommerce. My original plan for caldera forms Pro was to use the WordPress rest API as a proxy for applications by default. The plug-in was built before the application architecture was changed, so it is not required, but if you want to use or copy it, there is my plug-in. The
To control access to the WordPress rest API path, I want to show you how to extend the content in the last section. I imagine this will be the way to provide your service. If the IE product is a pet walk service, the application will request a post request for this path to make an appointment for a walk. Or, if the product provides information, the application or API client will issue a get request to the application. WordPress provides a rest\u pre\u dispatch filter, and the kernel runs before responding to requests. This filter is an example of an initial entry point. If this filter does not return anything, everything will work correctly. But if something is returned, it will be used as a result. This is ideal for caching requests, implementing authentication systems that do not use word press users, or returning errors that exceed the speed limit. The following is a startup class that uses the filter to check whether the current request points to a specific path where the logical placeholder is located. Male male path = $path;
Add\u filter (‘rest\u pre\u dispatch’, [$this,’check’], 10, 3);
}The
\/**The
*WordPress checks whether it should be blocked before responding to the request. If it needs to be blocked, it should be blocked
*The
*@Whether to process param bool$serve request
*@Param\wp\u rest\u server$server server instance.
*@Param\wp\u rest\u request$request the request used to generate the response.
*The
*@Carriage return Boolean
*\/The
Check public functions ($serve, $server, $request){
\/\/Whether path properties start with \/
If (0! ==strpos ($this-> path, \
$this-> path = ‘\/’$ This-> path;
}The
\/\/Verify that the path is a path
If (0 = = = strpos ($request->get_route(), $this->route)){
\/\/Suppose there is too much logic to return wp_error using code 429.
$check= some ();
If (is_wp_error ($check)){
Return $this->generate\error\u response ($check);
}Another{
\/\/Approved, unaffected return
Return $serv;
}The
}Another{
\/\/Return unaffected, not our path
Return $serv;
}The
}The
\/**The
*Generate error response
*The
*@param \wp\u error $error
*@param int $status
*The
*@return \wp\u rest\u response
*\/The
Protected function generate\error\u response (\wp\u error$error, $status=429){
New \wp\u rest\u R
, $subscription_id);
$use =0;
}Another{
$id=$wp_query-> post [0]->id;
$uses = get\u post\u meta ($id,’\u uses’, true);
}The
If ($uses > $this->max\u uses){
Return false.
}Another{
Update\u post\u meta ($id,’\u uses’, $uses + 1);
Returns true.
}The
}The
}The class to be used in the path class verifies that the hidden post type is used. As shown by the check_uses() method, each time a check is performed, different uses are calculated and compared with the maximum allowed use. This logic may need to be extended in order to enable or reset on a monthly basis. Here, my goal is to provide a starting point and explain how to create this type of course. Here, we can use this logic to end the path class that was started before. This class is ready to format wp_error as a rest response or forward request. Therefore, we only need to call the corresponding logic in the check method connected to rest\u pre\u dispatch to interrupt the unapproved request. Male path = $path;
Add\u filter (‘rest\u pre\u dispatch’, [$this,’check’], 10, 3);
}The
\/**The
*WordPress checks whether it should be blocked before responding to the request. If it needs to be blocked, it should be blocked
*The
*@Whether to process param bool$serve request
*@Param\wp\u rest\u server$server server instance.
*@Param\wp\u rest\u request$request the request used to generate the response.
*The
*@Carriage return Boolean
*\/The
Check public functions ($serve, $server, $request){
\/\/Whether path properties start with \/
If (0! ==strpos ($this-> path, \
$this-> path = ‘\/’$ This-> path;
}The
\/\/Verify that the path is a path
If (0 = = = strpos ($request->get_route(), $this->route)){
\/\/Suppose there is too much logic to return wp_error using code 429.
$checker= new Limter (get_current_user_id());
$allowed = $checker->allowed();
If (is_wp_error (allow $){
Return $this->generate\error\u response (allow $, $checker->get\error\u code();
}Another{
\/\/Approved, unaffected return
Return $serv;
}The
}Another{
\/\/Return unaffected, not our path
Return $serv;
}The
}The
\/**The
*Generate error response
*The
*@param \wp\u error $error
*@param int $status
*The
*@return \wp\u rest\u response
*\/The
Protected function generate\error\u response (\wp\u error$error, $status=429){
New \wp\u rest\u response(
[\
$status
);
}The
}Was – using word press as SaaS, I hope this article provides the beginning of many ideas and code needed to create a word press based SaaS. WordPress is only used for e-commerce (whether it is a more detailed method in the future or for the entire application)
Whether you choose it or not, it is an excellent tool for these projects.)

Author:

Leave a Reply

Your email address will not be published. Required fields are marked *