How do I edit the string of a function in includes/abstracts directly?

For example the function get_price_html_from_to() in file plugins/woocommerce/includes/abstracts/abstract-wc-product.php

public function get_price_html_from_to( $from, $to ) {
    return '<del>' . ( ( is_numeric( $from ) ) ? wc_price( $from ) : $from ) . '</del> <ins>' . ( ( is_numeric( $to ) ) ? wc_price( $to ) : $to ) . '</ins>';
}

Without going into the file itself and changing it, how do I alter that string?

Read More

Is it possible to create my own abstract-wc-product.phpfile, and point wordpress/woo at the file instead of the original? or is there a way to simply remove & replace the function with one of my own? or just alter it’s string before it gets used?

Related posts

Leave a Reply

2 comments

  1. One way i think you can make this work, is by declaring your new function get_price_html_from_to( $from, $to ) before you include abstract-wc-product.php file.

    And then going in the abstract-wc-product.php file and adding this code near the function’s get_price_html_from_to( $from, $to ) definition :

    if ( ! function_exists( 'get_price_html_from_to' ) )
        public function get_price_html_from_to( $from, $to ) {
        return '<del>' . ( ( is_numeric( $from ) ) ? wc_price( $from ) : $from ) . '</del> <ins>' . ( (       is_numeric( $to ) ) ? wc_price( $to ) : $to ) . '</ins>';
    }
    

    }

    Though that requires you to go in the file and actually change it.. really slightly though.

  2. Don`t change the templates as you will loose your changed once there is an update. Instead, add your method to the filter:

        dd_filter( 'woocommerce_get_price_html', 'your_function_name', 100, 2 );
        function your_function_name( $price, $product ){
             return 'Was:' . str_replace( '<ins>', ' Now:<ins>', $price );
        }