Link to home
Start Free TrialLog in
Avatar of Robert Granlund
Robert GranlundFlag for United States of America

asked on

WordPress Change Class Function Select Field

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,

Avatar of Scott Fell
Scott Fell
Flag of United States of America image

Just a good guess, viewing the source when the page is rendered, you see
<select>
   <option value="">No</option>
   <option value="yes">Yes - Rental only</option>
    <option value="yes_purchase ">Yes - Rental or purchase </option>
</select>

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.

'options' => array(
                 
    'yes' => __( 'Yes - Rental only', 'wcrp-rental-products' ),  //// MAKE THIS SELECTED, Not NO
   'yes_purchase'   => __( 'Yes - Rental or purchase', 'wcrp-rental-products' ),
   ''            => __( 'No', 'wcrp-rental-products' ),
  ),
'selected'      => true,

Open in new window


Avatar of Robert Granlund

ASKER

@scottt, OK, but how do I extend that class from the plugin and then filter the function?
Your only option that I know of is to duplicate the plug in and change the name of it, then manually update the classes to what you want.

Being that is a paid extension, check out what your rights to the code are before making any modifications.
ASKER CERTIFIED SOLUTION
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial