Managing WooCommerce With The YITH Frontend Manager For WooCommerce Plugin

If managing your WooCommerce Store isn’t time consuming enough, imagine having to train new personnel on what they can do or should do when they access your Website’s back-end. YITH saw there was a need to allow collaborators and even store managers to be able to add and edit products without ever having access to the back-end. Say hello to the “YITH Frontend Manager For WooCommerce” plugin.

YITH Frontend Manager For WooCommerce Plugin

The YITH Frontend Manager For WooCommerce plugin allows you to:

  • Enable Front-End Shop Management for Your Site
    It will provide a Shop manager with an interactive, feature-rich dashboard allowing to update many aspects of your WooCommerce Store.
  • Restrict Shop Manager’s Back-End Access
    Prevent All Shop Managers From Having Access To The Site Back-end. Your WooCommerce Store will be completely managed from the Front-End of your Website.
  • Choose Shop Sections To Enable In The Front-End
    That’s right, you can easily enable or disable which WooCommerce Modules are displayed to Shop Managers. Modules include Coupons, Dashboard, Logout, Orders, Products and Reports.
  • Manage Unauthorized Access
    Keep those without access out of your Website. Show them you mean business by displaying a customizable error message.
  • Enable WordPress Admin Bar
    Enable the WordPress Admin Bar for Shop Managers so they can quickly get to the Front-End Dashboard.
  • Edit The Endpoints Of Each SectionChange the Endpoints/Urls to specific sections. For example, the default endpoint to manage Coupons is /coupon/. This option would allow you to change it to something like /coupon-management/.
  • Choose The Skin To Be Used For The Dashboard

The YITH Frontend Manager For WooCommerce Plugin In Combination With YITH Multi Vendor Can

  • Enable All Vendors To Access The Front-End Dashboard
  • Choose Which Sections To Enable For Vendors
  • Prevent All Vendors From Accessing WordPress Dashboard

YITH Frontend Manager For WooCommerce Is Developer Friendly

The YITH Frontend Manager For WooCommerce plugin is developer friendly. It contains a significant number of actions and filters that you can use to make it your own and customize it to your needs. A quick example of this can be seen below, where we are changing the capability required to view the Front-End manager to those who have upload_files permissions. In a real world application, this could be a capability registered by your own plugin.

Speed Up Large WordPress & WooCommerce Website Back-End

Last week while trying to find ways to improve KelbyOne’s Website speed, I came across a particular query being ran on the back-end that was responsible for slowing it down. Every time you tried loading an Order, Course, Lesson, Subscription or anything else, that query was responsible for almost 80% of the time it took to load.

The query was discovered using the latest version of Query Monitor. What did the query do, it goes through the whole postmeta table and tries to find every different meta_key found for a particular post_type. Needless to say if you have a large postmeta table with millions of records, this query will take a long time to run.

Results from the query populate the Custom Fields metabox select menu so that you can easily add new custom fields with a few clicks. Keep in mind that if you add this code to your Website, the select menu will not be populated anymore. Also, any custom fields added to the post will still show in Custom Fields metabox and you’ll have the “Add New Custom Field” interface to add any fields if you need to.

I was able to reduce page load times from around 27 seconds down to 4-5 seconds. How is this beneficial? Simple. The less time the server is busy running the query the more resources available to your visitors. Also, if you have a lot of people going in the back-end for things like Customer Service, they’ll thank you, too.

Enough rambling, here is the code.

LearnDash Zapier Integration: Sending Additional User Information

I was recently hired at Codeable to write a plugin which would allow the LearnDash Zapier Integration plugin to pass additional user information with every call made to Zapier. This information needed to happen whenever global user even happened, like completing a quiz, for example. Upon reviewing the plugin, I noticed there was no filter that would allow me to pass in this additional data or an action to alter it’s default behavior.

Luckily the plugin was using WordPress’ HTTP API and I knew if I could listen to every request being made to an external site, then I could check whether or not the call was being made to Zapier and add my data there. This is exactly what I ended up doing. I’m posting this hoping that it will help someone else who needs to do this and you should get in touch with LearnDash like I did in order to ask for a filter to be added to the already existing plugin. It wouldn’t take more than 5 minutes to add a filter and open the request so that you can pass your own data.

Below is the plugin I wrote to pass a single field the User object being sent to Zapier. You can use the same technique and add as many as you’d like.

There you have it, nice and simple.

Faster AJax Calls In WordPress By Using The AjaxFlow Plugin

Is it possible to achieve faster Ajax Calls in WordPress? You bet it is possible and you can start doing it right now with very little edits to the code you already have in place. We are going to be using a little plugin called AjaxFlow to speed it up, but first let’s go over the regular, slow way of doing Ajax Calls in WordPress.

Meet Ajaxflow

By installing this plugin in your Website, your Ajax calls will be so fast you’ll think it’s sorcery, but it is not, I think it’s not. All kidding aside, the plugin basically tells WordPress to load the bare minimum instead of loading the whole WordPress environment, thus speeding everything up and resulting in much faster Ajax calls. I’m talking calls that would normally would take 3-5 seconds on a good server down to 100-300 milliseconds.

How To Use Use AjaxFlow

Using AjaxFlow is super easy, and if you are already using regular Ajax calls within WordPress using wp_ajax_nopriv_$action and wp_ajax_$action, converting to AjaxFlow can be done in minutes.

What Are The Differences?

  • Ajax calls need to be made to /ajaxflow/$action, meaning that /wp-admin/admin-ajax.php is no longer used.
  • Passing the action parameter in your Ajax request is no longer necessary since we include the action in the call endpoint as explained above
  • ajaxflow_nopriv_$action and ajaxflow_$action must be used in your PHP code instead of using wp_ajax_nopriv_$action and wp_ajax_$action

AjaxFlow Example

If for some reason you get an error message other than zero saying your call $action doesn’t exists, then it means you have forgotten to add the Ajax handler in the back-end or you didn’t add it properly since it can’t find it.

That’s it, give it a try and watch your Ajax calls fly.

Connecting WooCommerce To Salesforce: OAuth2 Authorization

Along with learning Typescript in the fast few months, I’ve also been putting a lot of time an energy into learning Salesforce and the Apex language. So far it has been an amazing journey and my end goal for learning Salesforce is so that I can write REST APIs that would synchronize WooCommerce and Salesforce seamlessly.

With that purpose in mind, I realized doing something like this is no easy task or something you can write in a day or two and never have to touch it again, specially since the whole ecosystem (WordPress, WooCommerce, Salesforce) gets updated very frequent and things change all the time. I’ve taken the approach of dividing this humongous task into smaller modules that would help me accomplish this in faster and more maintainable way. Being able to re-use the components and sort of add or delete them as needed is what I’m after and the first step would be to establish a connection with Salesforce so that I can begin sending my Requests.

Since this would be tied to WooCommerce on this side, I figured I would do it the WordPress/WooCommerce way so I wrote a little plugin that integrates with WooCommerce and handles the saving of all the data received from Salesforce after the initial oAuth2 authorization and saves it to the database for later use. Note that this part doesn’t include the option the revoke the token or to send the refresh token in order to obtain a new access token once the old one has expired.

Register Our Integration With WooCommerce

Let’s start coding and register our registration with WooCommerce so that it appears under the WooCommerce -> Settings -> Integrations tab. This file’s sole purpose is to help WooCommerce know this is an integration and to load other PHP Classes we are going to be using. The actual fields, settings and any other logic will be in another file.

Integration Fields Using WooCommerce’s Settings API

Everything is pretty standard, just a few fields to save our the values we get back from Salesforce.

  • SF App Consumer Key
  • SF App Consumer Secret
  • SF Login URI
  • SF oAuth2 Token
    Salesforce Token (Not actually used to communicate back and forth but it was used for obtaining the Access Token
  • SF Access Token
    Access token sent with every request for authenticating purposes.
  • SF Refresh Token
    Refresh token used whenever the Access Token needs to be renewed/refreshed
  • SF Instance URI
    All REST Request will be send to this base Uri.
  • Debug Log
    Log events such as API requests

Register Custom WordPress Endpoints

Next we register 2 endpoints which are used in the 2 step process. What follows takes care of registering two endpoints, oauth2 and oauth2-step2. It will also add some quick and dirty logic to overriding what each of these endpoints display. These templates are called authorization-step-1.php and authorization-step-2.php.

Endpoint Templates

Finally, these are the layouts for those 2 endpoints.

Download WooCommerce To Salesforce Integration: Initial Integration

WooCommerce To Salesforce Integration: Initial Integration