Skip to content

Instantly share code, notes, and snippets.

@growdev
Created November 11, 2014 22:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save growdev/967ad18e4bde62cdc190 to your computer and use it in GitHub Desktop.
Save growdev/967ad18e4bde62cdc190 to your computer and use it in GitHub Desktop.
Add text to the Price based on conditional in WooCommerce
<?php
add_filter( 'woocommerce_get_price_html', 'growdev_custom_price_message', 30, 2 );
/**
* Add string to
*
* @param $price HTML string
* @param $product WC_Product object
* @return string
*/
function growdev_custom_price_message( $price, $product ) {
//error_log( "price: " . $price );
//error_log( "product: " . get_class($product) );
/*
[11-Nov-2014 16:42:23 UTC] price: <span class="amount">&#36;20.00</span>
[11-Nov-2014 16:42:23 UTC] product: WC_Product_Simple
*/
if ( ! is_admin() ) {
$s = 59;
if ( (int) $product->get_regular_price() >= $s ) {
$free_shipping_text = ' <h4>FREE SHIPPING!</h4>';
return $price . $free_shipping_text;
}
}
return $price;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment