panda
Forum Replies Created
-
Forum: Plugins
In reply to: [WooCommerce] Making Rating Filter always showCan you help me a little? I lost in the width of the star. I managed to show them all but the size of the star 5 to 1 is a little messy because of the calculation of rating.
for ( $rating = 5; $rating >= 1; $rating-- ) { $count = $this->get_filtered_product_count( $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' ) ); /** This is responsible for the width of the golden color of rating. **/ $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(), ) ); 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. }
- This reply was modified 4 years, 3 months ago by panda.
Forum: Plugins
In reply to: [WooCommerce] What happened to the API Docs?What about the source code?
Forum: Plugins
In reply to: [WooCommerce] Making Rating Filter always showHello! It doesn’t matter if there are no products to filter, I just want to keep it viewable for the sake of the UI.
Forum: Plugins
In reply to: [WooCommerce] Is there a way to ignore empty query parameter?I found this
pre_get_posts
, I think it is somehow related to querying, but I don’t know how to use it to ignore an empty query. Something like like:function search_filter_get_posts($query) {
if ( !$query->is_search ){
return $query;
}
//if parameters are empty, then remove or ignore it
return $query;
}
add_action( ‘pre_get_posts’, ‘search_filter_get_posts’ );Forum: Plugins
In reply to: [WooCommerce] Is there a way to ignore empty query parameter?I want to ignore those empty query string.
(1) For example, with this query:
https://domain.com/?min_price=100All products with a minimum price of 100 will show up.
(2) With this query, assuming the
input
formax_price
is empty:
https://domain.com/?min_price=100&max_priceNo products will be shown, or the result will become empty.
(I am expecting to show all products with a minimum of 100, then ignore themax_price
since it is empty.)–
I want to ignore the empty query string so it won’t have an effect on the other query.Forum: Plugins
In reply to: [WooCommerce] wc_add_notice not working on Edge and FirefoxI wasn’t able to find a solution, I was able to solve the issue. Both of the links you’ve shared above don’t help at all. Even posting it as a bug on DSM doesn’t help.
Forum: Plugins
In reply to: [WooCommerce] wc_add_notice not working on Edge and FirefoxThose codes are actually in your docs, so I guess that is default functionality of WooCommerce, I just don’t know why I doesn’t work on Microsoft Edge and Mozilla Firefox, something’s not right. What I want is an answer as to why it doesn’t work and the possible solution.
Anyway, the below codes are my current solution and it works but I still want to know your side.
session_start(); function csx_process_query() { if ( isset( $_GET[ 'new-password-created' ] ) && $_GET[ 'new-password-created' ] === "true" ) { if ( !empty( $_SESSION[ "new-password-created" ] ) && isset( $_SESSION[ "new-password-created" ] ) && $_SESSION[ "new-password-created" ] === "true" ) { wc_add_notice( __( 'Password successfully changed!', 'woocommerce' ), 'success' ); } unset( $_SESSION[ "new-password-created" ] ); } } add_action( 'init', 'csx_process_query' ); function woocommerce_new_pass_redirect( $user ) { $_SESSION[ "new-password-created" ] = "true"; wp_redirect( home_url() . "/sign-in/?new-password-created=true" ); exit; } add_action( 'woocommerce_customer_reset_password', 'woocommerce_new_pass_redirect' );
What I think is the message is being removed before the page load (only on Mozilla Firefox and Microsoft Edge).
Best Regards
Forum: Plugins
In reply to: [WooCommerce] wc_add_notice not working on Edge and FirefoxWhich one of the codes I posted is not the default functionality of WooCoommerce?
Your support is very poor.
- This reply was modified 4 years, 4 months ago by panda.
Forum: Plugins
In reply to: [WooCommerce] Redirect after submission of form on lost passwordI just updated my Firefox into 78.0.2, and now the notice message is no longer works.
function woocommerce_new_pass_redirect( $user ) { wc_add_notice( __( 'Your password has been changed successfully! Please login to continue.', 'woocommerce' ), 'success' ); wp_redirect( home_url() . "/sign-in/?new-password-created=true" ); exit; } add_action( 'woocommerce_customer_reset_password', 'woocommerce_new_pass_redirect' );
Forum: Plugins
In reply to: [WooCommerce] Redirect after submission of form on lost passwordany update?
Forum: Plugins
In reply to: [WooCommerce] Custom Reset Password PageSo I managed to fix it all, I just need to set the reset password cookie again.
$value = sprintf( "%s:%s", wp_unslash( $_GET[ 'id' ] ), wp_unslash( $_GET[ 'key' ] ) ); WC_Shortcode_My_Account::set_reset_password_cookie( $value );
Here’s the whole code.
//Create shortcode for lost password form [lost_password_form] function wc_custom_lost_password_form( $atts ) { if ( !empty( $_COOKIE[ "csx-reset-link-set" ] ) && isset( $_COOKIE[ "csx-reset-link-set" ] ) && $_COOKIE[ "csx-reset-link-set" ] === "true" ) { // WPCS: input var ok, CSRF ok. return wc_get_template( 'myaccount/lost-password-confirmation.php' ); } elseif ( !empty( $_SESSION[ "csx-show-reset-form" ] ) && isset( $_SESSION[ "csx-show-reset-form" ] ) && $_SESSION[ "csx-show-reset-form" ] === "true" ) { $rp_id = $_SESSION[ "csx-id" ]; $rp_key = $_SESSION[ "csx-key" ]; if ( isset( $_COOKIE[ 'wp-resetpass-' . COOKIEHASH ] ) && 0 < strpos( $_COOKIE[ 'wp-resetpass-' . COOKIEHASH ], ':' ) ) { // @codingStandardsIgnoreLine list( $rp_id, $rp_key ) = array_map( 'wc_clean', explode( ':', wp_unslash( $_COOKIE[ 'wp-resetpass-' . COOKIEHASH ] ), 2 ) ); // @codingStandardsIgnoreLine $userdata = get_userdata( absint( $rp_id ) ); $rp_login = $userdata ? $userdata->user_login : ''; $user = WC_Shortcode_My_Account::check_password_reset_key( $rp_key, $rp_login ); // Reset key / login is correct, display reset password form with hidden key / login values. if ( is_object( $user ) ) { return wc_get_template( 'myaccount/form-reset-password.php', array( 'key' => $rp_key, 'login' => $rp_login, ) ); } } } // Show lost password form by default. return wc_get_template( 'myaccount/form-lost-password.php', array( 'form' => 'lost_password', ) ); } add_shortcode( 'lost_password_form', 'wc_custom_lost_password_form' ); //Handling query function csx_process_query() { if ( isset( $_GET[ 'reset-link-sent' ] ) && $_GET[ 'reset-link-sent' ] === "true" ) { setcookie( 'csx-reset-link-set', "true", time() + ( 300 * 1 ), "/" ); //Allow to submit email for reset after 5 minutes only. unset( $_SESSION[ "csx-show-reset-form" ] ); } if ( isset( $_GET[ 'show-reset-form' ] ) && $_GET[ 'show-reset-form' ] === "true" || isset( $_GET[ 'key' ] ) && isset( $_GET[ 'id' ] ) ) { $_SESSION[ "csx-show-reset-form" ] = "true"; setcookie( 'csx-reset-link-set', "", time() - 3600, "/" ); } //Set session and cookie if key and id are existed if ( isset( $_GET[ 'key' ] ) && isset( $_GET[ 'id' ] ) ) { $_SESSION[ "csx-key" ] = $_GET[ 'key' ]; $_SESSION[ "csx-id" ] = $_GET[ 'id' ]; $value = sprintf( "%s:%s", wp_unslash( $_GET[ 'id' ] ), wp_unslash( $_GET[ 'key' ] ) ); WC_Shortcode_My_Account::set_reset_password_cookie( $value ); } //Unset session and cookie after successfully changed the password. if ( isset( $_GET[ 'new-password-created' ] ) && $_GET[ 'new-password-created' ] === "true" ) { setcookie( 'wp-resetpass-' . COOKIEHASH, "", time() - 3600 ); unset( $_SESSION[ "csx-show-reset-form" ] ); unset( $_SESSION[ "csx-reset-link-set" ] ); unset( $_SESSION[ "csx-id" ] ); unset( $_SESSION[ "csx-key" ] ); } } add_action( 'init', 'csx_process_query' ); //Redirect to custom lost password on request function csx_redirections() { if ( isset( $_GET[ 'reset-link-sent' ] ) || isset( $_GET[ 'show-reset-form' ] ) || isset( $_GET[ 'key' ] ) && isset( $_GET[ 'id' ] ) ) { wp_redirect( home_url() . '/password-recovery' ); exit; } } add_action( 'template_redirect', 'csx_redirections' ); //Replace the default URL from lost password function wdm_lostpassword_url() { return site_url( '/password-recovery' ); } add_filter( 'lostpassword_url', 'wdm_lostpassword_url', 10, 0 ); //Redirect to login page with success notice after successful password reset. function woocommerce_new_pass_redirect( $user ) { wc_add_notice( __( 'Your password has been changed successfully! Please login to continue.', 'woocommerce' ), 'success' ); wp_redirect( home_url() . "/sign-in/?new-password-created=true" ); exit; } add_action( 'woocommerce_customer_reset_password', 'woocommerce_new_pass_redirect' );
Now I can just use the ShortCode
[lost_password_form]
on any page and set the default URL for lost password.Also, I’ve changed the URL in the email message. Here’s how I did it.
Anyway, I’m still a little bit skeptical about my solution, feels like not right.
The support is very poor responding to queries.
Forum: Plugins
In reply to: [WooCommerce] Change URL in Password Reset EmailI managed to change it by overriding the templates located at
woocommerce/templates/emails/customer-reset-password.php
andwoocommerce/templates/emails/plain/customer-reset-password.php
;For plain email:
<?php /** * Customer Reset Password email * * This template can be overridden by copying it to yourtheme/woocommerce/emails/plain/customer-reset-password.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/Emails/Plain * @version 3.7.0 */ defined( 'ABSPATH' ) || exit; echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n"; echo esc_html( wp_strip_all_tags( $email_heading ) ); echo "\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; /* translators: %s: Customer username */ echo sprintf( esc_html__( 'Hi %s,', 'woocommerce' ), esc_html( $user_login ) ) . "\n\n"; /* translators: %s: Store name */ echo sprintf( esc_html__( 'Someone has requested a new password for the following account on %s:', 'woocommerce' ), esc_html( wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ) ) ) . "\n\n"; /* translators: %s: Customer username */ echo sprintf( esc_html__( 'Username: %s', 'woocommerce' ), esc_html( $user_login ) ) . "\n\n"; echo esc_html__( 'If you didn\'t make this request, just ignore this email. If you\'d like to proceed:', 'woocommerce' ) . "\n\n"; echo esc_url( add_query_arg( array( 'key' => $reset_key, 'id' => $user_id ), home_url().'/your-custom-url/' ) ) . "\n\n"; // phpcs:ignore echo "\n\n----------------------------------------\n\n"; /** * Show user-defined additional content - this is set in each email's settings. */ if ( $additional_content ) { echo esc_html( wp_strip_all_tags( wptexturize( $additional_content ) ) ); echo "\n\n----------------------------------------\n\n"; } echo wp_kses_post( apply_filters( 'woocommerce_email_footer_text', get_option( 'woocommerce_email_footer_text' ) ) );
For non-plain email:
<?php /** * Customer Reset Password email * * This template can be overridden by copying it to yourtheme/woocommerce/emails/customer-reset-password.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/Emails * @version 4.0.0 */ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } ?> <?php do_action( 'woocommerce_email_header', $email_heading, $email ); ?> <?php /* translators: %s: Customer username */ ?> <p><?php printf( esc_html__( 'Hi %s,', 'woocommerce' ), esc_html( $user_login ) ); ?></p> <?php /* translators: %s: Store name */ ?> <p><?php printf( esc_html__( 'Someone has requested a new password for the following account on %s:', 'woocommerce' ), esc_html( wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ) ) ); ?></p> <?php /* translators: %s: Customer username */ ?> <p><?php printf( esc_html__( 'Username: %s', 'woocommerce' ), esc_html( $user_login ) ); ?></p> <p><?php esc_html_e( 'If you didn\'t make this request, just ignore this email. If you\'d like to proceed:', 'woocommerce' ); ?></p> <p> <a class="link" href="<?php echo esc_url( add_query_arg( array( 'key' => $reset_key, 'id' => $user_id ), home_url()."/your-custom-url/" ) ); ?>"><?php // phpcs:ignore ?> <?php esc_html_e( 'Click here to reset your password', 'woocommerce' ); ?> </a> </p> <?php /** * Show user-defined additional content - this is set in each email's settings. */ if ( $additional_content ) { echo wp_kses_post( wpautop( wptexturize( $additional_content ) ) ); } do_action( 'woocommerce_email_footer', $email );
Forum: Plugins
In reply to: [WooCommerce] Custom Reset Password PageUpon checking the value of
$_COOKIE['wp-resetpass-'.COOKIEHASH]
it says;
Notice: Undefined index: wp-resetpass-3307b20d0f1aa2f65f1a8220dac0acfc in ...
The
COOKIEHASH
however has a value. It looks like the cookie forwp-resetpass
is failed to set or it is being destroyed before loading the page.Maybe setting the value of
$_COOKIE['wp-resetpass-'.COOKIEHASH]
will fix the issue, but I don’t know what is the value of it or how you set it.- This reply was modified 4 years, 4 months ago by panda.
Forum: Plugins
In reply to: [WooCommerce] Redirect after submission of form on lost passwordI’ve checked the version of Edge;
Microsoft Edge 44.19041.1.0
Microsoft EdgeHTML 18.19041Anyway, regarding my query about redirecting after submission of the form on lost password, is my approach enough? or is there a hook to simply set the URL?
Forum: Plugins
In reply to: [WooCommerce] Redirect after submission of form on lost passwordThis is what I’ve done so far.
function myi_redirections() { if(isset($_GET['reset-link-sent']) && $_GET['reset-link-sent'] === 'true') { wc_add_notice( __( "Instructions sent to email", 'gateway' ), 'success' ); wp_redirect(home_url().'/password-recovery-confirmation'); exit; } } add_action( 'template_redirect', 'myi_redirections' );
But for some reason, the notice is not working or not showing up on Microsoft Edge Browser except on Firefox and Google Chrome.