Alan Storm Alan Storm - 4 months ago 11
PHP Question

Where Does WooCommerce Set the post_type to "product"

WooCommerce is a set of plugins and themes that, when installed into Wordpress, create an ecommerce system. This is a question about the programatic implementation of a WooCommerce feature in the core of Wordpress. The Wordpress Stack Exchange explicitly forbids WooCommerce questions, and the Wordpress forums seem oriented towards users, not core developers. i.e. -- Stack Overflow seems like the best place to ask this question, but if there's a better place, please let me know.

Products in WooCommerce are actually Wordpress posts, with the

post_type
data set to 'product`.

When you load the
http:://woo.example.com/shop
page, and Wordpress performs its post lookup query, the
post_type
is already set to
product
.

#File: wp-includes/query.php
if ( !empty($q['post_type']) && 'any' != $q['post_type'] ) {
}


Where does the WooCommerce plugin (or theme?) set this
post_type
? I'd assume via an
action
or a
filter
, but my Wordpress code tracing skills aren't up to the task of finding this myself.

Answer

The WooCommerce WC_Template_Loader class is responsible for loading the shop (i.e. archive) template, after the query arguments have been set in class-wc-query.php via the pre_get_posts hook.