Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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