businessdad

WooCommerce - Show "Earn X points" after product price

Oct 21st, 2016
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.97 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Adds a note after a product price, showing how many points can be earned.
  4.  * Requested by C.Hollebeke (https://www.facebook.com/groups/woohelp/permalink/2034366710123107/)
  5.  *
  6.  * Need help customising the code for your need? Hire us on Codeable: http://bit.ly/codeable_discount_aelia
  7.  *
  8.  * @param string price_html The HTML showing the product price.
  9.  * @param WC_Product The product for which the price is being displayed.
  10.  * @return string The product price, with the note appended to it.
  11.  * @author Aelia
  12.  * @link https://aelia.co
  13.  */
  14. add_filter('woocommerce_get_price_html', function($price_html, $product) {
  15.   /* Possible improvements
  16.    * - Don't show the note if the price is zero
  17.    * - Replace text domain placeholder with real text domain
  18.    */
  19.   $note = '<div class="custom_note">';
  20.   $note .= sprintf(__('Earn %s points', 'some_text_domain'), (string)floor($product->get_price()));
  21.   $note .= '</div>';
  22.  
  23.  
  24.   return $price_html . $note;
  25. }, 10, 2);
Add Comment
Please, Sign In to add comment