Community Forums › Forums › Archived Forums › General Discussion › I need your help with a code for functions.php
Tagged: coding, core, functions.php, Variable pricing
- This topic has 3 replies, 3 voices, and was last updated 4 years, 6 months ago by
AppleWormDesign.
-
AuthorPosts
-
April 3, 2017 at 11:14 am #204228
Mobiusynergy
MemberI am wondering if the code below has to be changed for Studio press themes (As I noticed the Studio Press codes look slightly enhanced. Has anyone here figured out how to removed the variable price ranges and if so can you help?
Back ground:
Link to show problem: https://www.cannabistriangle.com/product/logo-crew-neck-t-shirt-white-letters/
Theme: infinity pro
Wordpress with woocommerceProblem: Found code to add to functions.php to remove variable product price range.
add_filter('woocommerce_variable_price_html','custom_from',10);
add_filter('woocommerce_grouped_price_html','custom_from',10);
add_filter('woocommerce_variable_sale_price_html','custom_from',10);
function custom_from($price){return false;}
) );The code when added to functions.php and saved leads to this result:
This page isn’t working
http://www.cannabistriangle.com is currently unable to handle this request.
HTTP ERROR 500I had to log into my server/file manager to remove the code to get the site back up.
Ideal solution: Remove the variable price range to show original price and sale price as all the variable products have the same price.
https://www.cannabistriangle.com/product/logo-crew-neck-t-shirt-white-letters/April 3, 2017 at 11:57 am #204230Victor Font
ModeratorThis is all you need:
add_filter('woocommerce_variable_price_html','custom_from',10); add_filter('woocommerce_grouped_price_html','custom_from',10); add_filter('woocommerce_variable_sale_price_html','custom_from',10); function custom_from($price){return false;}
You have too many characters at the end of the code.
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?April 3, 2017 at 6:00 pm #204254Mobiusynergy
MemberThank you.
I had to find a different approach to this solution. It may not have been the easiest, but it worked. Now, I need to find out how to do this with simple products so they don't show the same price twice.
Used code:
function wc_ninja_custom_variable_price( $price, $product ) {
// Main Price
$prices = array( $product->get_variation_price( 'min', true ), $product->get_variation_price( 'max', true ) );
$price = $prices[0] !== $prices[1] ? sprintf( __( 'From: %1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );// Sale Price
$prices = array( $product->get_variation_regular_price( 'min', true ), $product->get_variation_regular_price( 'max', true ) );
sort( $prices );
$saleprice = $prices[0] !== $prices[1] ? sprintf( __( 'From: %1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );if ( $price !== $saleprice ) {
$price = '' . $saleprice . '<ins>' . $price . '</ins>';
}return $price;
}
add_filter( 'woocommerce_variable_sale_price_html', 'wc_ninja_custom_variable_price', 10, 2 );
add_filter( 'woocommerce_variable_price_html', 'wc_ninja_custom_variable_price', 10, 2 );September 28, 2018 at 2:26 pm #223439AppleWormDesign
Member -
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.