• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

I need your help with a code for functions.php

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › General Discussion › I need your help with a code for functions.php

This topic is: not resolved

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.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • April 3, 2017 at 11:14 am #204228
    Mobiusynergy
    Member

    I 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 woocommerce

    Problem: 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 500

    I 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 #204230
    Victor Font
    Moderator

    This 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 #204254
    Mobiusynergy
    Member

    Thank 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 #223439
    AppleWormDesign
    Member

    Thank You!


    Jason Taylor | Creative Director
    https://www.applewormdesign.co.uk/

  • Author
    Posts
Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘General Discussion’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2023 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble