Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add information about the price in installments after price on product page
<?php
new studiowp_single_product_price_installments( $parts_count = 4, $factor = 1.2 );
class studiowp_single_product_price_installments {
private $add_installment_price = false;
private $parts_count;
private $factor;
public function __construct( $parts_count = 12, $factor = 1.1 ) {
$this->parts_count = $parts_count;
$this->factor = $factor;
add_filter( 'woocommerce_get_price_html', array( $this, 'woocommerce_get_price_html' ), 10, 2 );
add_action( 'woocommerce_before_single_product_summary', array( $this, 'woocommerce_before_single_product_summary' ) );
add_action( 'woocommerce_after_single_product_summary', array( $this, 'woocommerce_after_single_product_summary' ) );
}
public function woocommerce_before_single_product_summary() {
$this->add_installment_price = true;
}
public function woocommerce_after_single_product_summary() {
$this->add_installment_price = false;
}
public function woocommerce_get_price_html( $price, $product ) {
if ( $this->add_installment_price ) {
$single_part = $product->get_price() * $this->factor / $this->parts_count;
$single_part = ceil( $single_part );
$price .= sprintf(' lub <strong>%s</strong> w %d ratach', wc_price( $single_part ), $this->parts_count );
}
return $price;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment