• Hello,
    I would like to display the price following /1 year instead of /12 months.
    Is it possible changing any code in php? I found in functions.yith-wc-subscription.php something about show price per year:

    function ywsbs_get_price_per_string( $price_per, $time_option ) {
    $price_html = ( ( $price_per == 1 ) ? ” : $price_per ) . ‘ ‘;

    switch( $time_option ){
    case ‘days’:
    $price_html .= _n( ‘day’, ‘days’, $price_per, ‘yith-woocommerce-subscription’ );
    break;
    case ‘weeks’:
    $price_html .= _n( ‘week’, ‘weeks’, $price_per, ‘yith-woocommerce-subscription’ );
    break;
    case ‘months’:
    $price_html .= _n( ‘month’, ‘months’, $price_per, ‘yith-woocommerce-subscription’ );
    break;
    case ‘years’:
    $price_html .= _n( ‘year’, ‘years’, $price_per, ‘yith-woocommerce-subscription’ );
    break;
    default:
    }

    return $price_html;
    }

    Which do I have to change to show the price per one year instead of 12 months?
    I’m in a hurry and I’ll be grateful for your help. Thank you so much.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author YITHEMES

    (@yithemes)

    Hello,

    you can try adding the following code to the functions.php file of your child theme:

    if ( class_exists( 'YITH_WC_Subscription' ) ) {
    	remove_filter( 'woocommerce_get_price_html', array( YITH_WC_Subscription(), 'change_price_html' ), 10 );
    	add_filter( 'woocommerce_get_price_html', 'yith_ywsbs_change_price_html', 10, 2 );
    
    	function yith_ywsbs_change_price_html( $price, $product ) {
    
    		if ( ! YITH_WC_Subscription()->is_subscription( $product->get_id() ) ) {
    			return $price;
    		}
    
    		$price_is_per      = yit_get_prop( $product, '_ywsbs_price_is_per' );
    		$price_time_option = yit_get_prop( $product, '_ywsbs_price_time_option' );
    		if ( $price_is_per == 12 && 'months' == $price_time_option ) {
    			$price_time_option_string = '1 year';
            } else {
    			$price_time_option_string = ywsbs_get_price_per_string( $price_is_per, $price_time_option );
    		}
    
    		$price .= ' / ' . $price_time_option_string;
    
    		return $price;
    	}
    }

    Let me know.

    Hello,

    we have the same problem, but at our site this code only changes the price in the backend and not in the frontend (checkout and mail). Is there something else to add?

    Thank you!

    • This reply was modified 4 years, 10 months ago by laura@nnax. Reason: more details
    Plugin Author YITHEMES

    (@yithemes)

    Hello @lmeinecke,
    the filter should work also in frontend page.
    Maybe there’s some other hook that is working.

    Try to change the priority replace this:

    add_filter( 'woocommerce_get_price_html', 'yith_ywsbs_change_price_html', 10, 2 );

    with this:

    add_filter( 'woocommerce_get_price_html', 'yith_ywsbs_change_price_html', 100, 2 );

    Hello,
    thanks for the reply! We tried it with the new priority.
    The price option changes in frontend at the product and shop page, but not at our checkout page and not in our mails.
    Could it be a problem, that we use the woocommerce checkout shortcode at a different page?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘1 year instead 12 months’ is closed to new replies.