Product Catalog

9

questions

How do you find a product by SKU?

wc_get_product_id_by_sku( $sku ) — a lookup table query. Not a meta_query on _sku.

How do you get a variable product's price range?

$product->get_variation_price( 'min' ) and ( 'max' ), or get_price_html(). Don't loop over all variations by hand.

How do you hide a meta field from the REST API?

A _ prefix doesn't protect it from REST: meta_data returns all meta. Filter it with woocommerce_rest_prepare_product_object, or don't keep sensitive data in product meta.

How does a global attribute differ from a local one?

A global attribute is a pa_* taxonomy shared by all products: you can filter the catalog by it. A local one lives only in one product and has no filters.

How does wc_get_products() differ from WC_Product_Query?

Not in principle: wc_get_products() is a wrapper that creates a WC_Product_Query and returns the result.

How does WooCommerce hide out-of-stock products?

With the outofstock term in the product_visibility taxonomy and the "Hide out of stock items" option. Catalog queries add a tax_query on that taxonomy.

How many variations per product is reasonable?

Hundreds are technically possible, but the product form and price calculation slow down. If there are thousands of combinations, rethink the model: separate products, add-ons or options instead of variations.

When do you need a custom product type?

When the product behaves differently: pricing, cart, shipping, post-payment handling. If only a few fields change, meta fields are enough.

Why not save_post for product fields?

save_post fires for any post and before WooCommerce saves its own data. woocommerce_admin_process_product_object gives you the product object and makes your changes part of the main save.