Show hidden products on the checkout page with One Page Checkout

WooCommerce One Page Checkout is a premium plugin that let’s you create a page that shows a product, or a list of products, and the checkout form.
From that page, your customers can add products to their cart and buy them from the same page, without having to visit more different pages to complete the checkout process.

That is amazing, because less clicks and distractions means more chances that the user converts to a customer.

One Page Checkout allows you to specify which products to show on the page, and obviously they will show also on the default Shop page of your site and customers will be able to buy it also in the normal way they do with WooCommerce.

Sometimes though, that is not what you want. You created a landing page to sell a special product in your store, and you don’t want to show that product also in the catalog. How can you solve that?

The first thing you think to do is to go edit that product and change its visibility to Hidden. And then it’s hidden both in the catalog and in the One Page Checkout page.

Darth-vader-epic-fail

Did you think that it was going to work eh?

If you think about it, it makes sense that it does not show now. It’s hidden, why should it show on the One Page Checkout page if it is not supposed to show on the catalog? The product is not purchasable, there must be a reason if it’s hidden.

But there’s a filter in One Page Checkout that allows you to change the visibility settings allowed, so you can show hidden products on the One Page Checkout page but not on the catalog.

Open the file functions.php located in wp-content/themes/your-theme-name/ and add this code at the end of the file:


add_filter( 'wcopc_products_query_args', 'wc_opc_show_hidden_products' );
function wc_opc_show_hidden_products( $args ) {
if ( isset( $args['meta_query'] ) ) {
array_push( $args['meta_query'][0]['value'], 'hidden' );
}
return $args;
}

view raw

functions.php

hosted with ❤ by GitHub

After doing so, the product will show only on the One Page Checkout page, but not in the catalog.


More Posts That You Might Like…


7 responses to “Show hidden products on the checkout page with One Page Checkout”

  1. It’s awesome!
    Exactly did what I hope!

    1. Amazing! Thanks for reading Asia!

  2. Hi Nicola, how would I do this on a normal page?

    I’m trying to make a ‘secret’ page which have duplicates of my products at a special price to offer to new leads -so I want these products hidden from catalog/search but only visible on this offer page. They won’t seem to show with product id/category shortcodes because they are hidden…

    Thanks

    1. Hi Scott,
      If you add the code from this article you can mark them as Hidden in the catalog/search and use them with the OPC shortcode.

  3. […] Show hidden products on the checkout page with One Page Checkout […]

  4. I understand that this article is specific to One Page Checkout, but I was wondering how this would be possible for any page? I would like to create a page for one specific category, however the products are all set to hidden. Is there a way to incorporate your code for a regular page?

    1. Hey Nick,
      No, this code only works for OPC. The filter does not exist in the core of WooCommerce.

Leave a Reply

Categories

Newsletter

Receive new articles from this blog directly in your inbox!

No spam guaranteed!

Blog at WordPress.com.

%d bloggers like this: