woocommerce / woocommerce-accommodation-bookings

An accommodations add-on for the WooCommerce Bookings extension.
87 stars 31 forks source link

Filter "product_type_selector" should be applied everywhere, not only in admin area #407

Open axi opened 5 months ago

axi commented 5 months ago

What I expected

I use recommanded way to get products on a custom template: WC_Product_Query/ wc_get_products(), following the good practice from here.

I'm expecting to get all my products with default params:

$products = wc_get_products();

but $products is empty.

I tracked it down to the filter 'product_type_selector' (adding type 'accommodation-booking', see method WC_Accommodation_Booking_Admin_Panels::product_type_selector()) not being applied when not on admin area.

So wc_get_product_types() does not include 'accommodation-booking' and I'm forced to specify the type in query to get my products:

$products = wc_get_products(['type' => ["accommodation-booking"]]);

Suggestion

Maybe I don't get the complete picture but I guess this 'product_type_selector' filter should be called on plugin loading. PS: same thing for booking plugin