Alan Storm Alan Storm - 1 year ago 48
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

data set to 'product`.

When you load the
page, and Wordpress performs its post lookup query, the
is already set to

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

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

Answer Source

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.