Okay
  Public Ticket #1888540
Hide Tickets in Woocomerce Shop
Closed

Comments

  •  1
    beezley started the conversation

    How can I hide the tickets from being displayed on my normal woocomerce shop page. If I set them to private they do not show up in the select ticket drop down for the event.

    Thanks,

    Richard

  •  877
    Zhivko replied

    Add this filter in your theme functions.php file:

    /**
     * Exclude tickets from shop page
     */
    add_action('woocommerce_product_query', function($q) {
        $tax_query = (array) $q->get('tax_query');
        $tax_query[] = array(
            'taxonomy' => 'product_type',
            'field'    => 'slug',
            'terms'    => array('stec_bookable'), // Don't display tickets in shop page
            'operator' => 'NOT IN'
        );
        $q->set('tax_query', $tax_query);
    });
    

    Stachethemes Developer

  •  1
    beezley replied

    Thank you. Can you tell me where in the functions.php file I should insert this code? It did not work so I must be putting it in the wrong place.

  •  1
    beezley replied

    I am using OceanWP Pro. I placed it here...

    <?php
    /**
     * Theme functions and definitions.
     *
     * Sets up the theme and provides some helper functions
     *
     * When using a child theme (see http://codex.wordpress.org/Theme_Development
     * and http://codex.wordpress.org/Child_Themes), you can override certain
     * functions (those wrapped in a function_exists() call) by defining them first
     * in your child theme's functions.php file. The child theme's functions.php
     * file is included before the parent theme's file, so the child theme
     * functions would be used.
     *
     *
     * For more information on hooks, actions, and filters,
     * see http://codex.wordpress.org/Plugin_API
     *
     * @package OceanWP WordPress theme
     */
    // Exit if accessed directly

    // Core Constants
    define( 'OCEANWP_THEME_DIR', get_template_directory() );
    define( 'OCEANWP_THEME_URI', get_template_directory_uri() );
    final class OCEANWP_Theme_Class {
     /**
      * Main Theme Class Constructor
      *
      * @since   1.0.0
      */
     public function __construct() {
     
      /**
       * Exclude tickets from shop page
       */
      add_action('woocommerce_product_query', function($q) {
           $tax_query = (array) $q->get('tax_query');
           $tax_query[] = array(
               'taxonomy' => 'product_type',
               'field'    => 'slug',
               'terms'    => array('stec_bookable'), // Don't display tickets in shop page
               'operator' => 'NOT IN'
          );
          $q->set('tax_query', $tax_query);
      });
     
     
      if ( ! defined( 'ABSPATH' ) ) {
       exit;
      }
      // Define constants
      add_action( 'after_setup_theme', array( 'OCEANWP_Theme_Class', 'constants' ), 0 );
      // Load all core theme function files
      add_action( 'after_setup_theme', array( 'OCEANWP_Theme_Class', 'include_functions' ), 1 );
      // Load configuration classes
      add_action( 'after_setup_theme', array( 'OCEANWP_Theme_Class', 'configs' ), 3 );
      // Load framework classes
      add_action( 'after_setup_theme', array( 'OCEANWP_Theme_Class', 'classes' ), 4 );
      // Setup theme => add_theme_support, register_nav_menus, load_theme_textdomain, etc
      add_action( 'after_setup_theme', array( 'OCEANWP_Theme_Class', 'theme_setup' ), 10 );
      // Setup theme => Generate the custom CSS file
      add_action( 'admin_bar_init', array( 'OCEANWP_Theme_Class', 'save_customizer_css_in_file' ), 9999 );
      // register sidebar widget areas
      add_action( 'widgets_init', array( 'OCEANWP_Theme_Class', 'register_sidebars' ) );
      // Registers theme_mod strings into Polylang
      if ( class_exists( 'Polylang' ) ) {
       add_action( 'after_setup_theme', array( 'OCEANWP_Theme_Class', 'polylang_register_string' ) );
      }


  •  877
    Zhivko replied

    Place the code at the end of the file.


    Stachethemes Developer