I'v created a custom product_type
in Woocommerce as below.
function register_simple_booking_product_type() {
class WC_Product_Booking extends WC_Product{
public function __construct( $product ) {
$this->product_type = 'booking';
parent::__construct( $product );
}
}
}
add_action( 'init', 'register_simple_booking_product_type' );
function add_simple_booking_product( $types ){
$types[ 'booking' ] = __( 'Simple booking' );
return $types;
}
add_filter( 'product_type_selector', 'add_simple_booking_product' );
function simple_booking_custom_js() {
if ( 'product' != get_post_type() ) :
return;
endif;
?><script type='text/javascript'>
jQuery( document ).ready( function() {
jQuery( '.options_group.pricing' ).addClass( 'show_if_booking' ).show();
});
</script><?php
}
add_action( 'admin_footer', 'simple_booking_custom_js' );
From here I would like to query the product by product_type
. Though the product_type appears in the post_meta
in the Wordpress database, the products created as booking
type only appear when I query for simple
product type. How can I query for just products of the booking
product_type
?
$args = array(
'post_type' => 'product',
'tax_query' => array(
array(
'taxonomy' => 'product_type',
'field' => 'slug',
'terms' => 'booking',
),
),
);
$query = new WP_Query( $args );
Correct me if I understand your question wrong, but if the "product_type" is a meta data, you should not use 'tax_query'. Check out meta query for a solution