Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 543
  • Last Modified:

Wordpress WooCommerce Core Functions

I would like to edit a WooCommerce Core Function but am not 100% How to accomplish:

WooCommerce Function:
public function get_price_html( $price = '' ) {

if ( $this->get_price() > 0 ) {
				$price .= wc_price( $display_price ) . $this->get_price_suffix();

				$price = apply_filters( 'woocommerce_price_html', $price, $this );

			}
}

Open in new window


My Function:
add_filter('woocommerce_price_html', 'renderQuote', 10, 2);
function renderQuote()	{

	if(isset($_POST['get_quote'])) { // Handle the form.)
		$new_price = $price + 10;
		echo 'New Price'. $new_price;
	
	}
}

Open in new window


What I want to do is add 10 to the price.

Please let me know if you need more information.
0
rgranlund
Asked:
rgranlund
1 Solution
 
RartemassAuthor, martial arts coach, IT ConsultantCommented:
Quick question: Why do you want the core function to hard code a price increase instead of changing the list price for the product?
0
 
eemitCommented:
You have two problems here:
- a filter must return something
- you have no parameters in your filter function, but in filter two parameters are defined
Change your function from:
add_filter('woocommerce_price_html', 'renderQuote', 10, 2);
function renderQuote()	{

	if(isset($_POST['get_quote'])) { // Handle the form.)
		$new_price = $price + 10;
		echo 'New Price'. $new_price;
	
	}
}

Open in new window

To:
add_filter( 'woocommerce_price_html', 'renderQuote', 10, 2 );
function renderQuote( $price, $product ) {

	if(isset($_POST['get_quote'])) { // Handle the form.)
		$new_price = $price + 10;
		//echo 'New Price'. $new_price;

		// a filter must return something
		return $new_price;
	}

}

Open in new window

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now