Created
February 15, 2018 20:55
-
-
Save grola/63bfc9b38949fbfcf9477997fd4221d3 to your computer and use it in GitHub Desktop.
Price suffix from category
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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