Skip to content

Instantly share code, notes, and snippets.

@grola
Created February 15, 2018 20:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grola/63bfc9b38949fbfcf9477997fd4221d3 to your computer and use it in GitHub Desktop.
Save grola/63bfc9b38949fbfcf9477997fd4221d3 to your computer and use it in GitHub Desktop.
Price suffix from category
<?php
class studiowp_single_product_price_suffix {
private $suffix;
private $category_id;
/**
* studiowp_single_product_price_suffix constructor.
*
* @param string $suffix
* @param int $category_id
*/
public function __construct( $suffix, $category_id ) {
$this->suffix = $suffix;
$this->category_id = $category_id;
add_filter( 'woocommerce_get_price_html', array( $this, 'woocommerce_get_price_html' ), 10, 2 );
}
/**
* @param string $price
* @param WC_Product $product
*
* @return string
*/
public function woocommerce_get_price_html( $price, $product ) {
$categories = $product->get_category_ids();
if ( in_array( $this->category_id, $categories ) ) {
$price .= $this->suffix;
}
return $price;
}
}
new studiowp_single_product_price_suffix( ' na miesiąc', 17 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment