I have a plugin that turns products into rentals in Woo.
The Product Data has the ability to show if a product is Rentable or not and the Default is No:
class WCRP_Rental_Products_Product_Fields {
public function product_data_panel() {
global $post;
?>
<div id="wcrp-rental-products-panel" class="panel woocommerce_options_panel">
<?php
echo '<div class="wcrp-rental-products-panel-heading"><span class="dashicons dashicons-calendar-alt"></span>' . esc_html__( 'Rental', 'wcrp-rental-products' ) . '</div>';
echo '<div class="notice notice-info inline"><span class="dashicons dashicons-info"></span>' . esc_html__( 'Set whether this product is a rental.', 'wcrp-rental-products' ) . '</div>';
woocommerce_wp_select(
array(
'id' => '_wcrp_rental_products_rental',
'value' => get_post_meta( $post->ID, '_wcrp_rental_products_rental', true ),
'label' => esc_html__( 'Rental product', 'wcrp-rental-products' ),
'desc_tip' => true,
'description' => esc_html__( 'Enables rentals of this product. Default is no.', 'wcrp-rental-products' ),
'options' => array(
'' => __( 'No', 'wcrp-rental-products' ),
'yes' => __( 'Yes - Rental only', 'wcrp-rental-products' ),
'yes_purchase' => __( 'Yes - Rental or purchase', 'wcrp-rental-products' )
),
'selected' => true,
)
);
?>
I would like to extend this Class and filter the function so as that the Rental option is set to Yes-Rental or Purchase:
'options' => array(
'' => __( 'No', 'wcrp-rental-products' ),
'yes' => __( 'Yes - Rental only', 'wcrp-rental-products' ), //// MAKE THIS SELECTED, Not NO
'yes_purchase' => __( 'Yes - Rental or purchase', 'wcrp-rental-products' )
),
'selected' => true,
Open in new window
What happens is the first item is the default. The easy option then may be to change the order of the array.Open in new window