Want to create a Booking, Rental, or Gift Card product in WooCommerce without relying on bloated third-party plugins? You’re in the right place.
In this tutorial, we’ll walk through how to add a completely custom product type in WooCommerce — using native hooks, classes, and filters.
This is a powerful technique used in real-world plugins like:
- Booking plugins (
bookable
) - Gift card tools (
giftcard
) - Rental product managers (
rental
)
What We’ll Build
We’ll create a new product type called Rental Product
. It will:
- Appear in the admin “Product Data” dropdown
- Show only when selected
- Use a custom pricing field (e.g., price per day)
Step 1: Register the Product Type
Add this to your custom plugin or theme functions.php
:
add_filter( 'product_type_selector', 'custom_add_rental_product_type' );
function custom_add_rental_product_type( $types ) {
$types['rental'] = __( 'Rental Product', 'your-textdomain' );
return $types;
}
Now, in the admin product edit screen, you’ll see “Rental Product” as an option.
Step 2: Extend the WC_Product Class
WooCommerce needs to know what a rental
product does.
Create a new class:
class WC_Product_Rental extends WC_Product {
public function get_type() {
return 'rental';
}
public function get_price_per_day() {
return $this->get_meta( '_price_per_day' );
}
public function set_price_per_day( $value ) {
$this->update_meta_data( '_price_per_day', $value );
}
}
Then tell WooCommerce about this custom type:
add_filter( 'woocommerce_product_class', 'custom_rental_product_class', 10, 2 );
function custom_rental_product_class( $classname, $product_type ) {
if ( $product_type === 'rental' ) {
$classname = 'WC_Product_Rental';
}
return $classname;
}
Step 3: Add Custom Fields in Admin
Use WooCommerce’s woocommerce_product_options_general_product_data
action:
add_action( 'woocommerce_product_options_general_product_data', 'custom_rental_product_fields' );
function custom_rental_product_fields() {
global $product_object;
if ( $product_object && $product_object->get_type() !== 'rental' ) return;
woocommerce_wp_text_input( array(
'id' => '_price_per_day',
'label' => __( 'Price Per Day', 'your-textdomain' ),
'desc_tip' => true,
'description' => __( 'Enter the price per day for rental.', 'your-textdomain' ),
'type' => 'number',
'custom_attributes' => array(
'step' => '0.01',
'min' => '0',
),
) );
}
And save the data:
add_action( 'woocommerce_process_product_meta', 'custom_save_rental_product_fields' );
function custom_save_rental_product_fields( $post_id ) {
if ( isset( $_POST['_price_per_day'] ) ) {
update_post_meta( $post_id, '_price_per_day', wc_clean( $_POST['_price_per_day'] ) );
}
}
Step 4: Adjust Visibility of Tabs and Fields
Some default WooCommerce tabs (like shipping) may not apply. Use:
add_filter( 'woocommerce_product_data_tabs', 'custom_hide_tabs_for_rental' );
function custom_hide_tabs_for_rental( $tabs ) {
global $post;
$product_type = get_post_meta( $post->ID, '_product_type', true );
if ( $product_type === 'rental' ) {
unset( $tabs['shipping'] );
}
return $tabs;
}
Bonus: Show Custom Price on Frontend
If you want to display “₹500 per day” instead of the regular price:
add_filter( 'woocommerce_get_price_html', 'custom_rental_price_html', 10, 2 );
function custom_rental_price_html( $price, $product ) {
if ( $product->get_type() === 'rental' ) {
$per_day = $product->get_price_per_day();
return wc_price( $per_day ) . ' ' . __( 'per day', 'your-textdomain' );
}
return $price;
}
Final Result
Now your WooCommerce store supports an entirely new product type with custom logic — perfect for plugins like: