I want add changing on category page, I customize page websitelink.com/components\com_virtuemart\themes\default\templates\browse\browse_3.php
I add code
<div class="addtocart_buttonList">
<?php
$button_lbl = $VM_LANG->_('PHPSHOP_CART_ADD_TO');
$button_cls = 'addtocart_button';
if( CHECK_STOCK == '1' && ( $product_in_stock < 1 ) ) {
$button_lbl = $VM_LANG->_('VM_CART_NOTIFY');
$button_cls = 'notify_button';
$notify = true;
} else {
$notify = false;
}
?>
<form action="<?php echo $mm_action_url ?>index.php" method="post" name="addtocart" id="addtocart<?php echo $i ?>" class="addtocart_form" <?php if( $this->get_cfg( 'useAjaxCartActions', 1 ) && !$notify ) { echo 'onsubmit="handleAddToCart( this.id );return false;"'; } ?>>
<input type="submit" class="<?php echo $button_cls ?>" value="<?php echo $button_lbl ?>" title="<?php echo $button_lbl ?>" />
<input type="hidden" name="category_id" value="<?php echo #$_REQUEST['category_id'] ?>" />
<input type="hidden" name="product_id" value="<?php echo $product_id ?>" />
<input type="hidden" name="prod_id[]" value="<?php echo $product_id ?>" />
<input type="hidden" name="page" value="shop.cart" />
<input type="hidden" name="func" value="cartadd" />
<input type="hidden" name="Itemid" value="<?php echo $sess->getShopItemid() ?>" />
<input type="hidden" name="option" value="com_virtuemart" />
<input type="hidden" name="set_price[]" value="" />
<input type="hidden" name="adjust_price[]" value="" />
<input type="hidden" name="master_product[]" value="" />
</form>
</div>
After adding this line add to cart button appear on list items, but than i click on add to cart button error will come
Please enter a valid quatity for this item
How i can solve this?
You need to specify a quantity as an input field, hidden or otherwise. We only wanted the customer to be able to order one of an item, so added this code:
<input type="hidden" value="1" name="quantity">
Having that named input field satisifed the Virtuemart validation.
Related
I made a group of fields of type Checkbox to be able to select several options using ACF | Advanced Custom Fields, these fields are added to the profile of the user in the WP dashboard, I want to edit them from the front end using a custom form.
Fields created:
Fields in user profile:
Form in front page
I need when you select any option / checkbox on the page of the frontpage that is saved and also updated in the user's profile.
The code that I have in the from template is this:
account_page.php
<form id="your-profile" class="nice" action="<?php echo the_permalink() ?>" method="POST" />
<div>
<p>Please check the email newsletters you wish to receive.<br>Unchecking a box will unsubscribe you from future emails.</p>
</div>
<fieldset>
<input name="_wp_http_referer" value="<?php echo home_url('account') ?>" type="hidden">
<input name="from" value="profile" type="hidden">
<input name="action" value="update" type="hidden">
<input name="user_id" id="user_id" value="<?php echo $current_user->ID ?>" type="hidden">
<input name="checkuser_id" value="<?php echo get_current_user_id(); ?>" type="hidden">
<input name="nickname" value="<?php echo $current_user->user_email ?>" type="hidden">
<input name="user_email" value="<?php echo $current_user->user_email ?>" type="hidden">
<input name="phone" value="<?php echo $current_user->phone; ?>" type="hidden">
<input name="first_name" value="<?php echo $current_user->first_name ?>" type="hidden">
<input name="last_name" value="<?php echo $current_user->last_name ?>" type="hidden">
<input name="address" value="<?php echo $current_user->address ?>" type="hidden">
<input name="address2" value="<?php echo $current_user->address2 ?>" type="hidden">
<input name="city" value="<?php echo $current_user->city; ?>" type="hidden">
<input name="state" value="<?php echo $current_user->state; ?>" type="hidden">
<input name="zip_code" value="<?php echo $current_user->zip_code; ?>" type="hidden">
<input name="country" value="<?php echo $current_user->country; ?>" type="hidden">
<?php
//Get all items from newslwtter
$newsletter = get_field('newsletter_preferences', $current_user);
$id = get_the_ID();
$field = get_field_objects($current_user);
$field_name = $field["newsletter_preferences"]["name"];
if( $field ){
foreach ( $field["newsletter_preferences"]['choices'] as $key => $value) {
if ( in_array( $key, $newsletter ) ) {
$checked = 'checked';
}else{
$checked = '';
}
echo '<p class="field"><input type="checkbox" '.$checked.' name="'.$field_name.'" value="'.$key.'">'.$value.'</p>';
}
}
?>
</fieldset>
<div>
<input class="btn btn-primary" name="Update E-mail Preferences" value="Update E-mail Preferences" type="submit">
<?php wp_nonce_field( 'update-user' ) ?>
<input name="action" type="hidden" id="action" value="update-user">
</div>
</form>
And in the functions.php
function update_extra_profile_fields($user_id) {
if ( isset( $_POST['newsletter_preferences'] ) )
update_user_meta( $user_id, 'newsletter_preferences',
$_POST['newsletter_preferences'] );
}
add_action('personal_options_update','update_extra_profile_fields');
But don't work, dont save anything, help me please. Thank you
Solved creating :
function update_extra_profile_fields($user_id) {
if ( isset( $_POST['state'] ) )
$state = update_user_meta( $user_id, 'state', $_POST['state'] );
.
.
.
//all fields to save
}
add_action('personal_options_update', __NAMESPACE__ . '\\update_extra_profile_fields');
i want to get the textfield value and assign it for the radio button value
my code is working but not from the first time
after the first submit it will work perfectly
how do i make it work from the first page load
here is my code
<input type="text" name="optionAtxt" value="<?php echo #$_POST['optionAtxt'] ?>" /> <input type="radio" name="option" required value="<?php echo #$_POST['optionAtxt'] ?>">
<input type="text" name="optionBtxt" value="<?php echo #$_POST['optionBtxt'] ?>" /> <input type="radio" name="option" value="<?php echo #$_POST['optionBtxt'] ?>">
<input type="text" name="optionCtxt" value="<?php echo #$_POST['optionCtxt'] ?>"/> <input type="radio" name="option" value="<?php echo #$_POST['optionCtxt'] ?>">
<input type="submit" name="submit" value="Add" />
<input type="hidden" name="submitted" value="1" />
<?php
if (isset($_POST['submitted'])) {
$selected = trim($_POST['option']);
echo $selected;
}?>
I'm looking to add a discount code to this Paypal button but don't know how to go about doing it.
Can anyone help or suggest how too, I just need it so a customer can enter a the code and receive 10% off the price
The code is below for the button
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<p>Please click on the link to pay</p>
<input type="hidden" name="cmd" value="_cart" />
<input type="hidden" name="upload" value="1" />
<input type="hidden" name="business" value="<?php echo C_OUR_EMAIL; ?>" />
<input type="hidden" name="first_name" value="<?php echo strfordisp($ofirstname); ?>" />
<input type="hidden" name="last_name" value="<?php echo strfordisp($olastname); ?>" />
<input type="hidden" name="address1" value="<?php echo strfordisp($theorder["oaddress"]); ?>" />
<input type="hidden" name="address2" value="<?php echo strfordisp($theorder["oaddress2"]); ?>" />
<input type="hidden" name="address3" value="<?php echo strfordisp($theorder["oaddress3"]); ?>" />
<input type="hidden" name="city" value="<?php echo strfordisp($theorder["otown"]); ?>">
<input type="hidden" name="zip" value="<?php echo strfordisp($theorder["opostcode"]); ?>" />
<?php $orderdets = mysql_query("select * from c4d_orderitems where orderid='" . $_SESSION["db_order"] . "' and confirm");
$iloop = 1;
while ($orderrow = mysql_fetch_array($orderdets))
{
$itemdesc = $orderrow["itemtypedesc"];
$itemdesc .= " to " . $orderrow["dpostcode"];
$itemprice = $orderrow["cost"] + $orderrow["surcharge"] + $orderrow["insurancecost"];
?>
<input type='hidden' name="item_name_<?php echo $iloop; ?>" value='<?php echo strfordisp($itemdesc); ?>' />
<input type='hidden' name="item_number_<?php echo $iloop; ?>" value='<?php echo $orderrow["itemtype"]; ?>' />
<input type='hidden' name="amount_<?php echo $iloop; ?>" value='<?php
// pctrends
if ((strtoupper($ofirstname)=="PCTRENDSTEST") || (strtoupper($olastname)=="PCTRENDSTEST") || (substr($_SERVER['REMOTE_ADDR'],0,11)=="82.152.55.1"))
echo("0.01");
else echo $itemprice;
?>' />
<input type='hidden' name="quantity_<?php echo $iloop; ?>" value='1' />
<?
$iloop++;
}
?>
<input type="hidden" name="return" value="<?php echo C_SITE_ROOT; ?>stage7.php" />
<input type="hidden" name="cancel-return" value="<?php echo C_SITE_ROOT; ?>order-cancel.php" />
<input type="hidden" name="notify_url" value="<?php echo C_SITE_ROOT; ?>paypal.php" />
<input type="hidden" name="rm" value="2" />
<input type="hidden" name="invoice" value="<?php echo $_SESSION["db_order"]; ?>" />
<input type="hidden" name="currency_code" value="GBP" />
<input type="hidden" name="no-shipping" value="1" />
<input type="hidden" name="button_subtype" value="products" />
<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHostedGuest" />
<input type="hidden" name="country" value="GB" />
<p class='fmenu'><input type="image" src="https://www.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"></p>
</form>
You must check for the discount-code validity (with AJAX) and make the appropriate calculations to apply the discount to the amount variable (with JavaScript) before to send the payment notification.
The user writes the discount-code insiede the custom variable where you can store whatever you want for your own tracking purposes.
// Check here on keypress with JS and AJAX for discount code validity
<input type="text" name="custom" value="" />
If the discount-code is verified, apply the discount to the amount variable. Something like this:
// Javascript and jQuery
if(verified == true) {
var discounted = $("[name='amount']").val() - ($("[name='amount']").val()/100)*10);
$("[name='amount']").val(discounted);
}
else {
alert("Discount code not found");
}
Then when you send the payment and get the information from paypal (the IPN response) process it like so:
$discountCode = $_POST["custom"];
// ... Discount-code validity check ...
$discountedAmount = $originalAmount - (($originalAmount/100)*10);
// And then check if the paid amount corresponds to the due amount
if($discountedAmount == $_POST["amount"])
How do I integrate paybox system to handle deferred payment?
I learned that PBX_DIFF parameter is used to mention no. of days to delay the transaction. Thats exactly what I wanted. But there seems no working code for php with deferred payment for Paybox.
The following code is working fine without mentioning the deferred payment parameter (PBX_DIFF). But when I add that parameter, its not working
<form name="paybox_frm" id="paybox_frm" method="GET" action="<?php echo $payboxUrl;?>">
<input type="hidden" name="PBX_SITE" value="<?php echo $PBX_SITE; ?>">
<input type="hidden" name="PBX_RANG" value="<?php echo $PBX_RANG; ?>">
<input type="hidden" name="PBX_IDENTIFIANT" value="<?php echo $PBX_IDENTIFIANT; ?>">
<input type="hidden" name="PBX_TOTAL" value="<?PHP echo $MONTANT;?>">
<input type="hidden" name="PBX_DEVISE" value="<?php echo $PBX_DEVISE; ?>">
<input type="hidden" name="PBX_CMD" value="<?PHP echo $REFERENCE;?>">
<input type="hidden" name="PBX_PORTEUR" value="<?PHP echo $PORTEUR;?>">
<input type="hidden" name="PBX_RETOUR" value="<?php echo $PBX_RETOUR;?>">
<input type="hidden" name="PBX_HASH" value="<?php echo $PBX_HASH;?>">
<input type="hidden" name="PBX_TIME" value="<?PHP echo $datetime;?>">
<input type="hidden" name="PBX_HMAC" value="<?PHP echo $pbx_hmac;?>">
<!-- Code added for return url-->
<input type="hidden" name="PBX_REFUSE" value="<?PHP echo $PBX_REFUSE;?>" />
<input type="hidden" name="PBX_ANNULE" value="<?PHP echo $PBX_ANNULE;?>" />
<input type="hidden" name="PBX_EFFECTUE" value="<?PHP echo $PBX_EFFECTUE;?>" />
<input type="hidden" name="PBX_LANGUE" value="<?PHP echo $PBX_LANGUE;?>" />
Any help greatly appreciated. Thanks in advance.
<section class="rl-box">
<div class="container padd-xs-0">
<div class="content-section1">
<div class="left-cont col-md-12 col-sm-12"
<div class="container-fluid">
<?php
$PBX_SITE = "1999888";
$PBX_RANG = "32";
$PBX_IDENTIFIANT = "your identifiant id";
$secretKeyTest = "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF";
$PBX_PORTEUR = "your-email";
$PAYBOX_DOMAIN_SERVER = "tpeweb.paybox.com";
$dateTime = date("c");
$PBX_TOTAL = 4000; //$_POST["PBX_TOTAL"]; // Amount
$PBX_DEVISE = 978;
//$PBX_CMD = $_POST["PBX_CMD"]."|".$_POST["user"]."|".$_POST["typed"]."|".$_POST["period"]."|".$_POST["id"]; // order ID no.
$PBX_CMD = 1; // order ID no.
$PBX_RETOUR = "Mt:M;Ref:R;Auto:A;Erreur:E";
$PBX_HASH = "SHA512";
$PBX_TIME = $dateTime;
//$PBX_EFFECTUE = "http://www.leader-underwriting.eu/payment/payment.php";
$msg = "PBX_SITE=$PBX_SITE" .
"&PBX_RANG=$PBX_RANG" .
"&PBX_IDENTIFIANT=$PBX_IDENTIFIANT" .
"&PBX_TOTAL=$PBX_TOTAL" .
"&PBX_DEVISE=$PBX_DEVISE" .
"&PBX_CMD=$PBX_CMD" .
"&PBX_PORTEUR=$PBX_PORTEUR" .
"&PBX_RETOUR=$PBX_RETOUR" .
"&PBX_HASH=$PBX_HASH" .
"&PBX_TIME=$PBX_TIME";
$binKey = pack("H*", $secretKeyTest);
$hmac = strtoupper(hash_hmac('sha512', $msg, $binKey));
$cuu = str_replace(",", "", $ramount);
?>
<form method="POST" name="form_payment" action="https://preprod-tpeweb.paybox.com/cgi/MYchoix_pagepaiement.cgi">
<input type="hidden" name="PBX_SITE" value="<?php echo $PBX_SITE; ?>">
<input type="hidden" name="PBX_RANG" value="<?php echo $PBX_RANG; ?>">
<input type="hidden" name="PBX_IDENTIFIANT" value="<?php echo $PBX_IDENTIFIANT; ?>">
<input type="hidden" name="PBX_TOTAL" value="<?php echo $PBX_TOTAL; ?>"> <!--dynamic-->
<input type="hidden" name="PBX_DEVISE" value="<?php echo $PBX_DEVISE; ?>">
<input type="hidden" name="PBX_CMD" value="<?php echo $PBX_CMD; ?>"> <!--dynamic-->
<input type="hidden" name="PBX_PORTEUR" value="<?php echo $PBX_PORTEUR ?>">
<input type="hidden" name="PBX_RETOUR" value="<?php echo $PBX_RETOUR; ?>">
<input type="hidden" name="PBX_HASH" value="<?php echo $PBX_HASH; ?>">
<input type="hidden" name="PBX_TIME" value="<?php echo $PBX_TIME; ?>">
<input type="hidden" name="PBX_HMAC" value="<?php echo $hmac; ?>">
<button type="submit" class="btn btn-primary payment">
Payer
</button>
</form>
<center>
</center>
</div>
</div>
</div> <!-- .container-fluid -->
</div>
</div>
</div>
</section>
On my local machine, when I submit this form, and I do have items inside the $_SESSION['cart'], the sandbox does recognize the items inside it. But when I tried it on a live server, and I submitted the form while there's an item inside $_SESSION['cart'], the sandbox says my cart is empty... Why is that?
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" <?php if(empty($_SESSION['cart'])){echo "onsubmit=\"return false;\"";} ?>>
<input type="hidden" name="cmd" value="_cart" />
<input type="hidden" name="upload" value="1" />
<input type="hidden" name="business" value="<?=$ppemail['email']?>" />
<?php
$i = 1;
foreach($_SESSION['cart'] as $id => $qty):
$product = $myCart->getProduct($id);
?>
<input type="hidden" name="item_name_<?php echo $i; ?>" value="<?php echo $product['ProductName']; ?>">
<input type="hidden" name="item_number_<?php echo $i; ?>" value="<?php echo $product['ProductID']; ?>">
<input type="hidden" name="amount_<?php echo $i; ?>" value="<?php echo $product['ProductOverridePrice']; ?>">
<input type="hidden" name="quantity_<?php echo $i; ?>" value="<?php echo $qty; ?>">
<?php
$i++;
endforeach;
?>
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="rm" value="2">
<input type="hidden" name="shipping_1" value="<?php echo $shipping; ?>">
<input type="hidden" name="return" value="<?php echo $the_class->settings[0]['DomainName'];?>shopping-cart-details.php">
<input type="hidden" name="cancel_return" value="<?php echo $the_class->settings[0]['DomainName'];?>">
<input type="hidden" name="notify_url" value="<?php echo $the_class->settings[0]['DomainName'];?>classes/paypal.php">
<input type="image" src="images/continue-btn.png" name="pay now" value="pay" />
</form>
i found the bug...the table that was at the live server....i meant, one of the field names was small caps..errr