Last active
October 17, 2021 07:57
-
-
Save devbeno/bf550286c187dc4bbb1aa506b7e6aaa8 to your computer and use it in GitHub Desktop.
Prikaz rata za mobishop.ba
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 | |
/** | |
* Plugin Name: WooCommerce cijena na rate | |
* Description: Prikaz cijene na rate u zavisnosti od mjeseci te iznos jedne rate. | |
* Author: Benjamin Pelto | |
* Version: 1.0 | |
* License: GPLv2 or later | |
*/ | |
/** | |
* Cijena na rate za 12. | |
* | |
* @return string | |
*/ | |
function cs12_product_parceled() { | |
$product = get_product(); | |
if ( $product->get_price_including_tax() ) { | |
$percent = 10; | |
$value = woocommerce_price( $product->get_price_including_tax() + $percent / 100 ); | |
return $value; | |
} | |
} | |
/** | |
* Pojedinacna rata | |
* | |
* @return string | |
*/ | |
function cs12a_product_parceled() { | |
$product = get_product(); | |
if ( $product->get_price_including_tax() ) { | |
$value = woocommerce_price( $product->get_price_including_tax() / 24 ); | |
return $value; | |
} | |
} | |
/** | |
* Prikazi na product loop | |
* | |
* @return string | |
*/ | |
function cs_product_parceled_loop() { | |
echo '<span class="cijena-rate">Cijena na 24 rate <b>' . cs12_product_parceled() . '</b><br> već od <b>' . cs12a_product_parceled() . '</b>/mj.</span>'; | |
} | |
/** | |
* Prikazi unutar proizvoda | |
* | |
* @return string | |
*/ | |
function cs_product_parceled_single() { | |
$product = get_product(); | |
?> | |
<div itemprop="offers" itemscope itemtype="http://schema.org/Offer"> | |
<p style="margin: 0;" itemprop="price" class="price"> | |
<?php echo $product->get_price_html(); ?> | |
</p> | |
<p> | |
<span class="cijena-rate">Za cijenu <b>(<?php echo cs12_product_parceled(); ?>)</b> plaćajte na 24 mjesečne rate već od <?php echo cs12a_product_parceled(); ?>/mj.</span> | |
</p> | |
<meta itemprop="priceCurrency" content="<?php echo get_woocommerce_currency(); ?>" /> | |
<link itemprop="availability" href="http://schema.org/<?php echo $product->is_in_stock() ? 'InStock' : 'OutOfStock'; ?>" /> | |
</div> | |
<?php | |
} | |
add_action( 'woocommerce_after_shop_loop_item_title', 'cs_product_parceled_loop', 20 ); | |
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 ); | |
add_action( 'woocommerce_single_product_summary', 'cs_product_parceled_single', 10 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment