businessdad icon

WooCommerce - Show "Earn X points" after product price

businessdad | PRO | 10/21/16 08:54:39 AM UTC | 0 ⭐ | 874 👁️ | Never ⏰ | []
PHP |

970 B

|

None

|

0 👍

/

0 👎

<?php
/**
 * Adds a note after a product price, showing how many points can be earned.
 * Requested by C.Hollebeke (https://www.facebook.com/groups/woohelp/permalink/2034366710123107/)
 *
 * Need help customising the code for your need? Hire us on Codeable: http://bit.ly/codeable_discount_aelia
 *
 * @param string price_html The HTML showing the product price.
 * @param WC_Product The product for which the price is being displayed.
 * @return string The product price, with the note appended to it.
 * @author Aelia
 * @link https://aelia.co
 */
add_filter('woocommerce_get_price_html', function($price_html, $product) {
  /* Possible improvements
   * - Don't show the note if the price is zero
   * - Replace text domain placeholder with real text domain
   */
  $note = '<div class="custom_note">';
  $note .= sprintf(__('Earn %s points', 'some_text_domain'), (string)floor($product->get_price()));
  $note .= '</div>';
  
 
  return $price_html . $note;
}, 10, 2);

Comments