L
L
ligisayan2016-01-16 14:49:33
PHP
ligisayan, 2016-01-16 14:49:33

How to remove default selection from select?

There is a product catalog page on a demo site built on wordpress + woocommerce, for example this one . I created and added a product sorting widget through functions.php
fa3ae3c8ebec41eba3b36a6bda0945ac.png
, the task of which is to sort products by price and name. Now for the price select is used, which uses 2 parameters: default and price. Question: how to make it so that only the link to the price remains immediately by default, i.e. so that switching occurs only between the price and the name? Widget code:

class orderByPriceName extends WP_Widget {
    function __construct() {
        parent::__construct(...); }
        /*
     * фронтэнд виджета
     */
    public function widget( $args, $instance ) {

         $title = apply_filters( 'widget_title', $instance['title'] ); // к заголовку применяем фильтр (необязательно)
         $posts_per_page = $instance['posts_per_page'];

         echo $args['before_widget'];

         if ( ! empty( $title ) )
            echo $args['before_title'] . $title . $args['after_title'];

         $product_order = array();
         $product_order['menu_order'] = esc_html__("Default", MAD_BASE_TEXTDOMAIN);
         $product_order['price']     = esc_html__("Price", MAD_BASE_TEXTDOMAIN);

         $product_order_key = !empty($params['orderby']) ? $params['orderby'] : 'menu_order';
         $product_sort_key =  !empty($params['product_sort']) ? $params['product_sort'] : 'ASC';
         $product_sort_key = strtolower($product_sort_key);
?>

    <div class="sort-param sort-param-order">

         <div class="custom-select">
           <div class="select-title"><?php echo $product_order[$product_order_key] ?></div>
           <ul class="select-list"></ul>
           <select name="param-count">
<option data-href="menu_order" selected value="menu_order">
       <?php echo $product_order['menu_order'] ?>
</option>
<option data-href="price" value="price">
        <?php echo $product_order['price'] ?>
</option>
            </select>
          </div><!--/ .custom-select-->

     </div>

     <div class="order-param-button">
         <a title="<?php esc_html_e('Click to order products', MAD_BASE_TEXTDOMAIN) ?>" data-sort="<?php echo esc_attr($product_sort_key) ?>" class="order-param-<?php echo sanitize_html_class($product_sort_key) ?>"  href="javascript:void(0)"> Алфавит</a>
     </div><!--/ .order-param-button-->
   <?php  echo $args['after_widget'];
      }
   public function form( $instance ) {...}
   public function update( $new_instance, $old_instance ) {...}
}

If left like this
<a data-href="price" value="price">
            <?php echo $product_order['price'] ?>
    </a>

that doesn't work..

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
glenean, 2016-01-16
@glenean

Put
www.google.com/?q=option+selected%3Dselected

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question