Forum Replies Created

Viewing 15 replies - 1 through 15 (of 47 total)
  • Thread Starter panda

    (@alejorostata)

    Very good.

    Thread Starter panda

    (@alejorostata)

    Nevermind,

    global $wp;
    $current_url = home_url(add_query_arg(array(),$wp->request));
    $billing = home_url('/account/edit-address/billing');
    
    if(is_wc_endpoint_url('edit-address') && $current_url === $billing){ 
       echo 'Currently displayed page is billing.';
    }
    Thread Starter panda

    (@alejorostata)

    Hello!

    From the My-Account > Address, I don’t want to show the Billing and Shipping options. Instead, when I clicked the Address, the form for Billing should be displayed, I need the form directly.

    So what I did is override the my-address.php, then replace its content with:

    <?php
    defined( 'ABSPATH' ) || exit;
    echo WC_Shortcode_My_Account::edit_account('billing');
    ?>

    The form for billing is working and displayed, however, I wasn’t able to save the changes.

    • This reply was modified 4 years, 3 months ago by panda.
    Thread Starter panda

    (@alejorostata)

    Hello!

    I’m not sure either on how to reproduce the issue, it only happened when I tried using PHP version 7.4, I roll back to PHP 7.3 and no issue so far. Just right now, I tried updating into 7.4 again just to test and the issue is still there.

    Thread Starter panda

    (@alejorostata)

    oh God…

    Thread Starter panda

    (@alejorostata)

    You keep marking my post as “Solved”, I didn’t even read your reply yet, I didn’t even test your suggestion yet. That is why I keep on making another post. If that’s the case, please don’t mark it as solve yet. There is a thing “Status” at the right sidebar of WordPress and I can change it to “Solved” anytime as soon as it really solves the issue.

    Anyway, one of your support said;

    The issue happened because you need to add rewrite rules for pagination on your endpoint.
    Wishlist query using wl_paged variable for the number of the page to adjust wishlist products query.

    Then, I expected this to work but it doesn’t and yet you mark my previous post as “solved”;

    function add_wc_endpoint_rewrite() {
        add_rewrite_rule('wl_paged/([^/]+)/?$', 'index.php?wl_paged=$matches[1]', 'top');
    }
    add_action( 'init', 'add_wc_endpoint_rewrite' );
    
    function wc_endpoint_query_vars( $vars ) {
        $vars[] = 'wl_paged';
        return $vars;
    }
    add_filter( 'query_vars', 'd_wallet_query_vars', 0 );
    Thread Starter panda

    (@alejorostata)

    As I said, I forgot to mention that even turning it off, still not working.. Why do you keep on marking a post as “Solved” even it is not?

    Alright, here’s another screenshot of the setting, maybe you don’t understand, noticed that the “Show button text” is “Disabled“.

    View post on imgur.com

    And I do refresh the cache of the page by pressing “SHIFT” and “F5” on my keyboard. I do even “Purge All” the “Caching” from the Dashboard and yet, nothing works.

    I told you, the “Product listing Button Settings” is not taking effect when the product is on the wishlist.

    Just look at this screenshot. Take a look at the custom class I added which is “csx-btn-remove-from-wishlist“, its there right? Well, this product is not yet on the wishlist.

    View post on imgur.com

    Take a look at this screenshot, did you see the custom class I added which is “csx-btn-remove-from-wishlist“? It’s not there anymore right? Well, this product is added into the wishlist.

    View post on imgur.com

    • This reply was modified 4 years, 3 months ago by panda.
    Thread Starter panda

    (@alejorostata)

    Please enlighten me on how to do that. How can I add rewrite rules for pagination?

    Thread Starter panda

    (@alejorostata)

    I forgot to mention that even turning it off, still not working. You’ll get an idea on the class, I added a class and yet it wasn’t present when the product is in Wishlist but it does present on a product that is not in Wishlist.

    Here is the source of the product that is not in Wishlist. Noticed that the class I added is on it and the text is empty.

    View post on imgur.com

    Here is the source of the product that is added or in the wishlist. Noticed that the class I added is no longer exist and the text is not empty and has a value of Remove from Wishlist

    View post on imgur.com

    Thread Starter panda

    (@alejorostata)

    To remove the text, I had to used:

    div.tinv-wraper.woocommerce.tinv-wishlist.tinvwl-shortcode-add-to-cart .tinvwl-product-in-list.tinvwl-product-make-remove .tinvwl_remove_from_wishlist-text{
    	display: none !important;
    }

    But this is very wrong, too much selector. Once changes for the selector for both your side and woocommerce and it will no longer work.

    Thread Starter panda

    (@alejorostata)

    It looks like the option for Product listing Button Settings is not working if the product is in Wishlist.

    I tried adding a class into it and tried to empty the text, I look into the source by using Inspect Element, and here’s what I found.

    Here I added a class and remove the text and saved it then reload the Shop Page.

    View post on imgur.com

    Here is the source of the product that is not in Wishlist. Noticed that the class I added is on it and the text is empty.

    View post on imgur.com

    Here is the source of the product that is added or in the wishlist. Noticed that the class I added is no longer exist and the text is not empty and has a value of Remove from Wishlist

    View post on imgur.com

    Thread Starter panda

    (@alejorostata)

    Hello!

    1. I tried to remove the text from Product page "Add to Wishlist" Button Settings it does remove the text from the Shop Page, however, it also removes the text from the Single Product Page. I only want to remove it in Shop Page.

    2. I tried to remove the text from Product listing Button Settings but it doesn’t work for both Shop Page and Single Product Page.

    Thread Starter panda

    (@alejorostata)

    UPDATED: I forgot to remove the condition;

    if ( ! WC()->query->get_main_query()->post_count ) {
       return;
    }

    In functions.php, the code should be:

    class Custom_Widget_Rating_Filter extends WC_Widget_Rating_Filter {
    
    	/**
    	 * Constructor.
    	 */
    	public function __construct() {
    		$this->widget_cssclass    = 'woocommerce widget_rating_filter';
    		$this->widget_description = __( 'Display a list of star ratings to filter products in your store.', 'woocommerce' );
    		$this->widget_id          = 'woocommerce_rating_filter';
    		$this->widget_name        = __( 'Filter Products by Rating', 'woocommerce' );
    		$this->settings           = array(
    			'title' => array(
    				'type'  => 'text',
    				'std'   => __( 'Average rating', 'woocommerce' ),
    				'label' => __( 'Title', 'woocommerce' ),
    			),
    		);
    		parent::__construct();
    	}
    
    	/**
    	 * Count products after other filters have occurred by adjusting the main query.
    	 *
    	 * @param  int $rating Rating.
    	 * @return int
    	 */
    	protected function get_filtered_product_count( $rating ) {
    		global $wpdb;
    
    		$tax_query  = WC_Query::get_main_tax_query();
    		$meta_query = WC_Query::get_main_meta_query();
    
    		// Unset current rating filter.
    		foreach ( $tax_query as $key => $query ) {
    			if ( ! empty( $query['rating_filter'] ) ) {
    				unset( $tax_query[ $key ] );
    				break;
    			}
    		}
    
    		// Set new rating filter.
    		$product_visibility_terms = wc_get_product_visibility_term_ids();
    		$tax_query[]              = array(
    			'taxonomy'      => 'product_visibility',
    			'field'         => 'term_taxonomy_id',
    			'terms'         => $product_visibility_terms[ 'rated-' . $rating ],
    			'operator'      => 'IN',
    			'rating_filter' => true,
    		);
    
    		$meta_query     = new WP_Meta_Query( $meta_query );
    		$tax_query      = new WP_Tax_Query( $tax_query );
    		$meta_query_sql = $meta_query->get_sql( 'post', $wpdb->posts, 'ID' );
    		$tax_query_sql  = $tax_query->get_sql( $wpdb->posts, 'ID' );
    
    		$sql  = "SELECT COUNT( DISTINCT {$wpdb->posts}.ID ) FROM {$wpdb->posts} ";
    		$sql .= $tax_query_sql['join'] . $meta_query_sql['join'];
    		$sql .= " WHERE {$wpdb->posts}.post_type = 'product' AND {$wpdb->posts}.post_status = 'publish' ";
    		$sql .= $tax_query_sql['where'] . $meta_query_sql['where'];
    
    		$search = WC_Query::get_main_search_query_sql();
    		if ( $search ) {
    			$sql .= ' AND ' . $search;
    		}
    
    		return absint( $wpdb->get_var( $sql ) ); // WPCS: unprepared SQL ok.
    	}
    
    	/**
    	 * Widget function.
    	 *
    	 * @see WP_Widget
    	 * @param array $args     Arguments.
    	 * @param array $instance Widget instance.
    	 */
    	public function widget( $args, $instance ) {
    		if ( ! is_shop() && ! is_product_taxonomy() ) {
    			return;
    		}
    
    		/* Responsible for not showing the STAR when query returns empty
    		if ( ! WC()->query->get_main_query()->post_count ) {
    			return;
    		}*/
    
    		ob_start();
    
    		$found         = false;
    		$rating_filter = isset( $_GET['rating_filter'] ) ? array_filter( array_map( 'absint', explode( ',', wp_unslash( $_GET['rating_filter'] ) ) ) ) : array(); // WPCS: input var ok, CSRF ok, sanitization ok.
    		$base_link     = remove_query_arg( 'paged', $this->get_current_page_url() );
    
    		$this->widget_start( $args, $instance );
    
    		echo '<ul>';
    
    		for ( $rating = 5; $rating >= 1; $rating-- ) {
    			$count = $this->get_filtered_product_count( $rating );
    			
    			/*Responsible for not showing all the 5 star rating
    			if ( empty( $count ) ) {
    				continue;
    			}*/
    			$found = true;
    			$link  = $base_link;
    
    			if ( in_array( $rating, $rating_filter, true ) ) {
    				$link_ratings = implode( ',', array_diff( $rating_filter, array( $rating ) ) );
    			} else {
    				$link_ratings = implode( ',', array_merge( $rating_filter, array( $rating ) ) );
    			}
    
    			$class       = in_array( $rating, $rating_filter, true ) ? 'wc-layered-nav-rating chosen' : 'wc-layered-nav-rating';
    			$link        = apply_filters( 'woocommerce_rating_filter_link', $link_ratings ? add_query_arg( 'rating_filter', $link_ratings, $link ) : remove_query_arg( 'rating_filter' ) );
    			/*  Responsible for showing rating span (gold|width)
    				$rating_html = wc_get_star_rating_html( $rating );
    			*/
    			$count_html  = wp_kses(
    				apply_filters( 'woocommerce_rating_filter_count', "({$count})", $count, $rating ),
    				array(
    					'em'     => array(),
    					'span'   => array(),
    					'strong' => array(),
    				)
    			);
    			
    			$rating_html = '<span style="width:'.(($rating/5)*100).'%">Rated <strong class="rating">'.$rating.'</strong> out of '.$rating.'</span>';
    			
    			$checked = '';
    			if(in_array( $rating, $rating_filter, true )){
    				$checked = '<i class="fas fa-check-circle csx-attribute-active"></i><i class="fas fa-times-circle csx-attribute-active-remove"></i>';
    			}else{
    				$checked = '<i class="fas fa-check-circle csx-attribute-not-active"></i>';
    			}
    		
    			printf( '<li class="%s"><a href="%s"><span class="star-rating">%s</span> %s</a>%s</li>', esc_attr( $class ), esc_url( $link ), $rating_html, $count_html, $checked); // WPCS: XSS ok.
    		}
    
    		echo '</ul>';
    
    		$this->widget_end( $args );
    
    		if ( ! $found ) {
    			ob_end_clean();
    		} else {
    			echo ob_get_clean(); // WPCS: XSS ok.
    		}
    	}
    }
    
    //handling the widget registration
    function my_widget_price_filter_register() {
    	unregister_widget( 'WC_Widget_Rating_Filter' ); //unregister the default
    	register_widget( 'Custom_Widget_Rating_Filter' ); //register the new one above.
    } 
    add_action( 'widgets_init', 'my_widget_price_filter_register' );

    No need to change the CSS but if you do it should be;

    .widget_rating_filter li.wc-layered-nav-rating span.star-rating{
    	width: 6em !important; /* change this */
    }
    • This reply was modified 4 years, 3 months ago by panda.
    Thread Starter panda

    (@alejorostata)

    Nevermind, I forgot your Github repository.

    Thread Starter panda

    (@alejorostata)

    Alright, I managed to do it.

    I hope there is an easy way to do this, probably a hook, action, or filter to disable the counter and display them all. Anyway, by extending the class of WC_Widget_Rating_Filter I managed to override the widget.

    Here’s the full source in my functions.php.

    /**
     * Widget rating filter class.
     */
    class Custom_Widget_Rating_Filter extends WC_Widget_Rating_Filter {
    
    	/**
    	 * Constructor.
    	 */
    	public function __construct() {
    		$this->widget_cssclass    = 'woocommerce widget_rating_filter';
    		$this->widget_description = __( 'Display a list of star ratings to filter products in your store.', 'woocommerce' );
    		$this->widget_id          = 'woocommerce_rating_filter';
    		$this->widget_name        = __( 'Filter Products by Rating', 'woocommerce' );
    		$this->settings           = array(
    			'title' => array(
    				'type'  => 'text',
    				'std'   => __( 'Average rating', 'woocommerce' ),
    				'label' => __( 'Title', 'woocommerce' ),
    			),
    		);
    		parent::__construct();
    	}
    
    	/**
    	 * Count products after other filters have occurred by adjusting the main query.
    	 *
    	 * @param  int $rating Rating.
    	 * @return int
    	 */
    	protected function get_filtered_product_count( $rating ) {
    		global $wpdb;
    
    		$tax_query  = WC_Query::get_main_tax_query();
    		$meta_query = WC_Query::get_main_meta_query();
    
    		// Unset current rating filter.
    		foreach ( $tax_query as $key => $query ) {
    			if ( ! empty( $query['rating_filter'] ) ) {
    				unset( $tax_query[ $key ] );
    				break;
    			}
    		}
    
    		// Set new rating filter.
    		$product_visibility_terms = wc_get_product_visibility_term_ids();
    		$tax_query[]              = array(
    			'taxonomy'      => 'product_visibility',
    			'field'         => 'term_taxonomy_id',
    			'terms'         => $product_visibility_terms[ 'rated-' . $rating ],
    			'operator'      => 'IN',
    			'rating_filter' => true,
    		);
    
    		$meta_query     = new WP_Meta_Query( $meta_query );
    		$tax_query      = new WP_Tax_Query( $tax_query );
    		$meta_query_sql = $meta_query->get_sql( 'post', $wpdb->posts, 'ID' );
    		$tax_query_sql  = $tax_query->get_sql( $wpdb->posts, 'ID' );
    
    		$sql  = "SELECT COUNT( DISTINCT {$wpdb->posts}.ID ) FROM {$wpdb->posts} ";
    		$sql .= $tax_query_sql['join'] . $meta_query_sql['join'];
    		$sql .= " WHERE {$wpdb->posts}.post_type = 'product' AND {$wpdb->posts}.post_status = 'publish' ";
    		$sql .= $tax_query_sql['where'] . $meta_query_sql['where'];
    
    		$search = WC_Query::get_main_search_query_sql();
    		if ( $search ) {
    			$sql .= ' AND ' . $search;
    		}
    
    		return absint( $wpdb->get_var( $sql ) ); // WPCS: unprepared SQL ok.
    	}
    
    	/**
    	 * Widget function.
    	 *
    	 * @see WP_Widget
    	 * @param array $args     Arguments.
    	 * @param array $instance Widget instance.
    	 */
    	public function widget( $args, $instance ) {
    		if ( ! is_shop() && ! is_product_taxonomy() ) {
    			return;
    		}
    
    		if ( ! WC()->query->get_main_query()->post_count ) {
    			return;
    		}
    
    		ob_start();
    
    		$found         = false;
    		$rating_filter = isset( $_GET['rating_filter'] ) ? array_filter( array_map( 'absint', explode( ',', wp_unslash( $_GET['rating_filter'] ) ) ) ) : array(); // WPCS: input var ok, CSRF ok, sanitization ok.
    		$base_link     = remove_query_arg( 'paged', $this->get_current_page_url() );
    
    		$this->widget_start( $args, $instance );
    
    		echo '<ul>';
    
    		for ( $rating = 5; $rating >= 1; $rating-- ) {
    			$count = $this->get_filtered_product_count( $rating );
    			/*
    			Responsible for showing available rating filter only.
    			if ( empty( $count ) ) {
    				continue;
    			}*/
    			$found = true;
    			$link  = $base_link;
    
    			if ( in_array( $rating, $rating_filter, true ) ) {
    				$link_ratings = implode( ',', array_diff( $rating_filter, array( $rating ) ) );
    			} else {
    				$link_ratings = implode( ',', array_merge( $rating_filter, array( $rating ) ) );
    			}
    
    			$class       = in_array( $rating, $rating_filter, true ) ? 'wc-layered-nav-rating chosen' : 'wc-layered-nav-rating';
    			$link        = apply_filters( 'woocommerce_rating_filter_link', $link_ratings ? add_query_arg( 'rating_filter', $link_ratings, $link ) : remove_query_arg( 'rating_filter' ) );
    			/*  Responsible for showing rating span (gold|width)
    				$rating_html = wc_get_star_rating_html( $rating );
    			*/
    			$count_html  = wp_kses(
    				apply_filters( 'woocommerce_rating_filter_count', "({$count})", $count, $rating ),
    				array(
    					'em'     => array(),
    					'span'   => array(),
    					'strong' => array(),
    				)
    			);
    			
    			$rating_html = '<span style="width:'.(($rating/5)*100).'%">Rated <strong class="rating">'.$rating.'</strong> out of '.$rating.'</span>';
    		
    			printf( '<li class="%s"><a href="%s"><span class="star-rating">%s</span> %s</a></li>', esc_attr( $class ), esc_url( $link ), $rating_html, $count_html ); // WPCS: XSS ok.
    		}
    
    		echo '</ul>';
    
    		$this->widget_end( $args );
    
    		if ( ! $found ) {
    			ob_end_clean();
    		} else {
    			echo ob_get_clean(); // WPCS: XSS ok.
    		}
    	}
    }
    
    //handling the widget registration
    function my_widget_price_filter_register() {
    	unregister_widget( 'WC_Widget_Rating_Filter' ); //unregister the default
    	register_widget( 'Custom_Widget_Rating_Filter' ); //register the new one above.
    } 
    add_action( 'widgets_init', 'my_widget_price_filter_register' );

    then in the CSS I override the width because the default one is 6.5em which will make the fill color overlap.

    .widget_rating_filter li.wc-layered-nav-rating span.star-rating{
    	width: 6em !important; 
    }

    I hope this helps someone who wants to make the UI of their store more beautiful.

    • This reply was modified 4 years, 3 months ago by panda.
Viewing 15 replies - 1 through 15 (of 47 total)