Skip to content

Instantly share code, notes, and snippets.

@stefaeva
Last active June 1, 2020 14:23
Show Gist options
  • Select an option

  • Save stefaeva/954288067dc693f15cd2b09650e8d950 to your computer and use it in GitHub Desktop.

Select an option

Save stefaeva/954288067dc693f15cd2b09650e8d950 to your computer and use it in GitHub Desktop.

Revisions

  1. stefaeva revised this gist Jun 1, 2020. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions WC_variable_products.php
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    /* i need help to modify this snippet to show only the product variations without the product parent */

    add_action( 'pre_get_posts', 'custom_remove_products_from_shop_page' );
    function custom_remove_products_from_shop_page( $q ) {
    if ( ! $q->is_main_query() ) return;
  2. stefaeva created this gist Jun 1, 2020.
    7 changes: 7 additions & 0 deletions WC_variable_products.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    add_action( 'pre_get_posts', 'custom_remove_products_from_shop_page' );
    function custom_remove_products_from_shop_page( $q ) {
    if ( ! $q->is_main_query() ) return;
    if ( ! $q->is_post_type_archive() ) return;
    if ( ! is_admin() && is_shop() ) {
    $q->set( 'post__in', array(0) ); }
    remove_action( 'pre_get_posts', 'custom_remove_products_from_shop_page' );