mercredi 25 février 2015

Remove checkbox php

I'm really new to PHP, and i'm currently making a small webshop (Locally) to try out my skills.


I've got some code, where there is a checkbox if you are a danish citizen, but i want the checkbox to be removed and then just run the code which normally only would have been running if it was checked no matter what.


Can you guys give me a hint or direction i should go?



function my_pmpro_tax($tax, $values, $order) {

$tax = round((float)$values[price]*0.8 * 0.25, 2);
return $tax;

}

function my_pmpro_level_cost_text($cost, $level)
{
//only applicable for levels > 1
$cost .= "Inkl. moms";

return $cost;
}

add_filter("pmpro_level_cost_text", "my_pmpro_level_cost_text", 10, 2);
//add Danish checkbox to the checkout page
function my_pmpro_checkout_boxes()
{
?>

<table id="pmpro_pricing_fields" class="pmpro_checkout" width="100%" cellpadding="0" cellspacing="0" border="0">
<thead>
<tr>
<th>
Do you live in Denmark?
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<div>
<input id="danish" name="danish" type="checkbox" value="1" <?php if(!empty($_REQUEST['danish']) || !empty($_SESSION['danish'])) {?>checked="checked"<?php } ?> /> Check this box if your billing address is in Denmark.
</div>
</td>
</tr>
</tbody>
</table>
<?php
}

add_action("pmpro_checkout_boxes", "my_pmpro_checkout_boxes");
//update tax calculation if buyer is danish
function my_danish_tax_check()
{
//check request and session
if(isset($_REQUEST['danish']))
{
//update the session var
$_SESSION['danish'] = $_REQUEST['danish'];

//not empty? setup the tax function
if(!empty($_REQUEST['danish']))
add_filter("pmpro_tax", "my_pmpro_tax", 10, 3);
}
elseif(!empty($_SESSION['danish']))
{
//add the filter
add_filter("pmpro_tax", "my_pmpro_tax", 10, 3);
}
}

add_action("init", "my_danish_tax_check");
//remove the danish session var on checkout
function my_pmpro_after_checkout()
{
if(isset($_SESSION['danish']))
unset($_SESSION['danish']);
}

add_action("pmpro_after_checkout", "my_pmpro_after_checkout");




Aucun commentaire:

Enregistrer un commentaire