<?php
/**
 * Show options for ordering
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/loop/orderby.php.
 *
 * HOWEVER, on occasion WooCommerce will need to update template files and you
 * (the theme developer) will need to copy the new files to your theme to
 * maintain compatibility. We try to do this as little as possible, but it does
 * happen. When this occurs the version of the template file will be bumped and
 * the readme will list any important changes.
 *
 * @see         https://docs.woocommerce.com/document/template-structure/
 * @package     WooCommerce/Templates
 * @version     3.6.0
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

global $options, $labels;

$menu_order_label = $options->get_option( 'menu-order-label' );
$popularity_label = $options->get_option( 'popularity-label' );
$rating_label = $options->get_option( 'rating-label' );
$date_label = $options->get_option( 'date-label' );
$price_label = $options->get_option( 'price-label' );
$price_desc_label = $options->get_option( 'price-desc-label' );
if ( $menu_order_label ) {
	$catalog_orderby_options['menu_order'] = irk_translated_string($menu_order_label);
}
if ( $popularity_label ) {
	$catalog_orderby_options['popularity'] = irk_translated_string($popularity_label);
}
if ( $rating_label ) {
	$catalog_orderby_options['rating'] = irk_translated_string($rating_label);
}
if ( $date_label ) {
	$catalog_orderby_options['date'] = irk_translated_string($date_label);
}
if ( $price_label ) {
	$catalog_orderby_options['price'] = irk_translated_string($price_label);
}
if ( $price_desc_label ) {
	$catalog_orderby_options['price-desc'] = irk_translated_string($price_desc_label);
}

$active = __( 'Default', 'irk' );
?>
<form class="woocommerce-ordering" method="get">
    <ul class="orderby" aria-label="<?php esc_attr_e( 'Shop order', 'irk' ); ?>:">
        <a href="#" class="toggle-ordering" rel="nofollow"></a>
		<?php foreach ( $catalog_orderby_options as $id => $name ) : ?>
			<?php
			$link = remove_query_arg( 'orderby' );
			$link = add_query_arg( array( 'orderby' => $id ), $link );

			$active = $orderby == $id ? $name : $active;
			?>
            <a href="<?php echo $link; ?>" class="<?php echo $orderby == $id ? 'active' : ''; ?>"><?php echo esc_html( $name ); ?></a>
		<?php endforeach; ?>
    </ul>
    <input type="hidden" name="paged" value="1"/>
	<?php wc_query_string_form_fields( null, array( 'orderby', 'submit', 'paged', 'product-page' ) ); ?>
</form>
<a href="#" class="shop-toggle toggle-ordering" rel="nofollow"><?php echo ucfirst( $active ); ?></a>
<a href="#" class="shop-toggle toggle-sidebar-shop" rel="nofollow"><?php echo $labels->get_label( 'advanced-search' ); ?></a>