Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Start a free Basic trial
to watch this video
In this video we look at an example of how you can hook into the popular WordPress ecommerce plugin, WooCommerce.
-
0:00
In our next example here we're going to search for
-
0:03
hooks that relate to the popular eCommerce WooCommerce.
-
0:07
We can see that with a simple Google search we can
-
0:10
find access to their documentation and hooks, this is a good sign.
-
0:18
Once we get in here though what we'll find is that we get a huge list of all of
-
0:22
the possible hooks, and then what files they're called in.
-
0:27
However we don't have further documentation about what they accept,
-
0:31
what other things are tied in, or example code that we could use to override it.
-
0:38
So let's say for
-
0:39
example that we wanted to look further into the wpcommerce_ after_cart.
-
0:44
Or an easier one, the wpcommerce_after_mini_cart since we could
-
0:48
see one appears in a number of files and one appears in just the single one.
-
0:56
From here, if we know what we're doing and we know that this is just an action,
-
1:01
we could say add action and simply add our action in and hook into this.
-
1:06
However, if we come down and we're working with the filters,
-
1:10
we may not know exactly what it is that we're getting in order to filter, or
-
1:15
other parameters that might be involved.
-
1:18
So in this case, it's going to require us to do another Google search,
-
1:23
that I usually start with by searching for the actual function or the actual hook.
-
1:29
And then you could begin working through sites that begin to show you some of
-
1:32
the content.
-
1:33
And then you could begin pulling up sites that show you some examples of
-
1:37
where it's used in the source code,
-
1:39
as well as hopefully how you can use it on your own site.
-
1:44
You'll find that some of the files, for example, are hosted on GitHub, so if we
-
1:48
pull up one of the GitHub templates that has this in it, we could find it here.
-
1:53
This would be similar for
-
1:54
example to just searching the source code of actual WooCommerce.
-
2:00
So I bring up WooCommerce for a specific reason.
-
2:03
We can see that it has some documentation and it has a ton of hooks.
-
2:08
But it isn't quite as robust as gravity forms in terms of all of
-
2:13
the documentation it gives you, examples and explanations of how to use it.
-
2:18
However, this may be the place with a lot of other functions that you try to
-
2:21
tie into, which is why it's important to know how to search for
-
2:25
things like add filter, apply filters, add action, do action.
-
2:31
So that you can begin to look in some of these functions and
-
2:34
files for where this is occurring.
-
2:36
And understand what's being passed along with it and what is expected back.
You need to sign up for Treehouse in order to download course files.
Sign up