add_action( 'wp_dashboard_setup', 'register_my_dashboard_widget' );
function register_my_dashboard_widget() {
wp_add_dashboard_widget(
'net_profit_widget',
'Net Profit Calculator',
'net_profit_widget_display'
);
}
function net_profit_widget_display() {
$subPrice = 0;
$subnumb = 0;
if (array_key_exists('subprice', $_POST) !== false) {
$subPrice = $_POST['subprice'];
}
if (array_key_exists('subnumb', $_POST) !== false) {
$subnumb = $_POST['subnumb'];
}
$payperc = "2.9";
$paystan = "0.3";
$netprof = "N/A";
$expense = "N/A";
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if ($subPrice === false || $subnumb === false ) {
die("Please fill in all the required information!");
} else {
$expense = $subPrice * (($payperc / 100) + $paystan);
$netprof = ($subPrice - $expense) * $subnumb;
}
}
?>
<div style="color: #777;">Paypal fee per transaction: 2.9% + $0.3</div><br>
<form class="netcalc" method="POST" action="#">
<label for="sub-price">Subscription Price($)</label><input name="subprice" id="sub-price" type="text" value="<?php echo $subPrice; ?>">
<br><label for="total-subs">Subscriptions Sold</label><input name="subnumb" id="total-subs" type="text" value="<?php echo $subnumb; ?>" >
<br><br><div><span class="expenses-label">Expenses</span><span class="expenses-output">$<?php echo $expense; ?></span></div>
<div><span class="net-profit-label">Net Profit</span><span class="net-profit-output">$<?php echo $netprof; ?></span></div>
<br><br><input id="submit" class="button button-primary" type="submit" value="Calculate"></input>
</form>
<?php }