Add a Custom Post Type Through WooCommerce
Lets a non-`product` post type behave like a purchasable WooCommerce item — pulling its price from a custom field and giving it a working "Add to Cart" button, without converting it into an actual Product post type.
Step 1 — hook your price field into WooCommerce
/**
* Your post type should have a custom field called 'price'.
* We just have to make sure that its meta key is '_price'.
* How to check that? You can try to inspect the element:
* 1) Visit your post type admin page.
* 2) Try to add or edit a post in your post type admin page.
* 3) Look for the text box that has the price label and right click on the text box.
* 4) You should find it's name attribute to be '_price'.
* Usually the name is the meta key for a custom field.
*
* Add the code below if your meta key is not '_price'
*/
add_filter('woocommerce_get_price','wc_get_price', 20, 2);
function wc_get_price($price, $post) {
if ($post->post->post_type === 'post') {
$price = get_post_meta($post->id, 'price', true);
}
return $price;
}
Step 2 — add the “Add to Cart” button
Heads up: for the “added to cart” confirmation message to actually appear, you’ll need to call `wc_print_notices()` somewhere in your `single-{post_type}.php` template.
More WooCommerce snippets
Reorder (and Rename) the My Account Menu Tabs
Controls the exact order the tabs appear in on the WooCommerce My Account page, and lets you rename any of them at the same time — including slotting in a custom tab you've added elsewhere.
Add a Custom Tab to the WooCommerce My Account Page
Registers a brand new endpoint (in this example, "Premium Support") and adds it as its own tab in the My Account menu, complete with its own content area — the standard pattern for extending My Account with anything WooCommerce doesn't ship by default.
Shortcode: Show a Customer’s Purchase History as a Product Grid
Registers a `[my_products]` shortcode that looks up everything the logged-in customer has ever bought (completed or processing orders) and renders it as a normal WooCommerce product loop — useful for a "buy again" section on the My Account page.