Created
June 3, 2016 18:30
-
-
Save rodrigozan/0fa855d821455bd4e23f3975954f51ec to your computer and use it in GitHub Desktop.
Uma tabela de parcelamento de preço WooCommerce - 12x baseado no pagseguro
This file contains hidden or 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 | |
/** | |
* Single Product Price, including microdata for SEO | |
* | |
* This template can be overridden by copying it to yourtheme/woocommerce/single-product/price.php. | |
* | |
* HOWEVER, on occasion WooCommerce will need to update template files and you (the theme developer). | |
* will need to copy the new files to your theme to maintain compatibility. We try to do this. | |
* as little as possible, but it does happen. When this occurs the version of the template file will. | |
* be bumped and the readme will list any important changes. | |
* | |
* @see http://docs.woothemes.com/document/template-structure/ | |
* @author WooThemes | |
* @package WooCommerce/Templates | |
* @version 2.4.9 | |
*/ | |
if ( ! defined( 'ABSPATH' ) ) { | |
exit; // Exit if accessed directly | |
} | |
global $product; | |
?> | |
<div itemprop="offers" itemscope itemtype="http://schema.org/Offer"> | |
<p class="price"><?php echo $product->get_price_html(); ?></p> | |
<?php | |
function tableParc(){ | |
$price = get_post_meta( get_the_ID(), '_regular_price', true); | |
$sale = get_post_meta( get_the_ID(), '_sale_price', true); | |
$priceArray = array(); | |
$i; | |
echo '<table class="tableParc">'; | |
for($i = 1; $i <= 3; $i++){ | |
if($sale == null){ | |
$division = $price / $i; | |
$division = bcdiv($division, 1, 2); | |
$division = str_replace(".",",", $division); | |
$priceArray[$i] = $division; | |
}else{ | |
$division = $sale / $i; | |
$division = bcdiv($division, 1, 2); | |
$division = str_replace(".",",", $division); | |
$priceArray[$i] = $division; | |
} | |
echo '<tr><td>' . $i . 'x </td><td> R$ '. $priceArray[$i] . '</td><td>SEM JUROS</td></tr>' ; | |
} | |
for($i = 4; $i <= 12; $i++){ | |
if($sale == null){ | |
$juros = $price * 0.0399; | |
$parcela = ($price + $juros) / $i; | |
$division = $parcela + ($parcela * 0.299); | |
$division = bcdiv($division, 1, 2); | |
$division = str_replace(".",",", $division); | |
$priceArray[$i] = $division; | |
}else{ | |
$division = $sale / $i; | |
$division = bcdiv($division, 1, 2); | |
$division = str_replace(".",",", $division); | |
$priceArray[$i] = $division; | |
} | |
echo '<tr class="tableJuros"><td>' . $i . 'x </td><td> R$ '. $priceArray[$i] . '</td><td>COM JUROS</td></tr>' ; | |
} | |
echo '</table>'; | |
} | |
?> | |
<style> | |
button.accordion { | |
background-color: #eee; | |
color: #444; | |
cursor: pointer; | |
padding: 18px; | |
width: 100%; | |
border: none; | |
text-align: left; | |
outline: none; | |
font-size: 15px; | |
transition: 0.4s; | |
} | |
button.accordion.active, button.accordion:hover, button.accordion:visited { | |
background-color: #ddd; | |
border:0; | |
} | |
div.panel { | |
font-size:1rem; | |
padding: 0 18px; | |
background-color: white; | |
max-height: 0; | |
overflow: hidden; | |
transition: 0.6s ease-in-out; | |
opacity: 0; | |
} | |
div.panel.show { | |
opacity: 1; | |
max-height: 850px; | |
} | |
table.tableParc tr td{font-size:0.9rem;text-align:center; | |
} | |
table.tableParc tr.tableJuros td:last-child{ | |
color:red; | |
} | |
img{max-width:100%;} | |
</style> | |
<div itemprop="offers" itemscope itemtype="http://schema.org/Offer"> | |
<button class="accordion"> | |
<center> | |
<h5>Parcele com Pagseguro!</h5> | |
</center> | |
</button> | |
<div class="panel"> | |
<br /> | |
<center> | |
Confira abaixo como ficam os valores: | |
</center> | |
<br /> | |
<?php tableParc(); ?> | |
</div><br /><br /> | |
</div> | |
<script> | |
var acc = document.getElementsByClassName("accordion"); | |
var i; | |
for (i = 0; i < acc.length; i++) { | |
acc[i].onclick = function(){ | |
this.classList.toggle("active"); | |
this.nextElementSibling.classList.toggle("show"); | |
} | |
} | |
</script> | |
<meta itemprop="price" content="<?php echo esc_attr( $product->get_price() ); ?>" /> | |
<meta itemprop="priceCurrency" content="<?php echo esc_attr( get_woocommerce_currency() ); ?>" /> | |
<link itemprop="availability" href="http://schema.org/<?php echo $product->is_in_stock() ? 'InStock' : 'OutOfStock'; ?>" /> | |
</div> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Não funciona mais :/