I have added functionality to Payment method step, which is related to shipping address, if shipping address changes, then Payment method HTML content must be reloaded. I tried to add JavaScript to Billing and Shipping step, but my backend requires that Shipping address is saved to work. So If I add my own JavaScript after onclick="shipping.save();" in shipping.phtml, it is never called.
Is there way to refresh step HTML every time step is viewed?
Yes it's possible but not with pure JS (there is not ajax callbacks available to reload a step by a single click)
You'll need to overload the OnepageController from Mage_Checkout. In this class you'll see that each step saveAction contains the logic to refresh/display the next step.
For example, in the saveShippingAction() of Mage_Checkout_OnepageController you can see :
[...]
if (!isset($result['error'])) {
$result['goto_section'] = 'shipping_method';
$result['update_section'] = array(
'name' => 'shipping-method',
'html' => $this->_getShippingMethodsHtml()
);
}
[...]
The part update_section is the one to tell magento to force-refresh the step.
You should be able to adapt this to your needs.
Related
I'm using PayPal and want to add the payment method SEPA on my current website.
Here are some examples I have followed:
https://developer.paypal.com/docs/checkout/integration-features/standalone-buttons/#funding-sources
https://demo.paypal.com/de/demo/go_platform/pcRestServerV2/paymentOptions
So basically I'm not getting SEPA button as displayed here on above 2nd link.
Here is my code that helps you to identify what I'm doing wrong.
var FUNDING_SOURCES = [
paypal.FUNDING.PAYPAL,
paypal.FUNDING.VENMO,
paypal.FUNDING.CREDIT,
paypal.FUNDING.CARD,
paypal.FUNDING.SEPA,
];
FUNDING_SOURCES.forEach(function(fundingSource) {
// Initialize the buttons
var button = paypal.Buttons({
fundingSource: fundingSource
});
// Check if the button is eligible
if (button.isEligible()) {
// Render the standalone button for that funding source
button.render('#paypalCheckoutContainer');
}
});
Is there a reason you are checking for and rendering particular funding sources? You can let PayPal handle that automatically instead of a forEach loop. Basically, use the simpler code at; https://developer.paypal.com/demo/checkout/#/pattern/client
If you are not located in a country that defaults to showing SEPA, add &buyer-country=DE to the SDK script query string line when testing in sandbox mode. Only do this for testing other countries in sandbox mode, it is not a valid parameter in live. The buyer's country will be auto detected in live.
I am sharing 3 screens step by step will be through woocommerce.
I have a shop page. On selecting a product, I will go to a front end form for creating a post. After creating a post I will go to checkout page.
My question is that, can I get the middle one (front end form for creating a post) in woocommerce platform ?
Please look my shared screen for understanding it better.
Thank you
First Screen
Second Screen
Third Screen
My question is that, can I get the middle one (front end form for
creating a post) in woocommerce platform ?
Sure, but you have to save the data from step 2 in the current session (cart).
Only when an order is created, collect the session data and create the (custom_post_type) job post. You don't want to create the job post before the order is completed / paid for.
Your question is very general, so you can expect a similar answer. We do not build complete plugins here. You will need to use multiple hooks to complete this.
EDIT: some more info
# step 2, collect, sanitize and validate the form values.
I would save this data in the cart session. something like this:
// I don't know how and where you collect the step 2 data,
// so i can't provide a hook for this function.
function step_2_data_to_session() {
global $woocommerce;
$step_two_data = array();
// validate and sanitize data first
// save data to woocommerce session
$woocommerce->session->set('step_two_data', $step_two_data );
}
Then when the user pays and creates an order, use a hook to collect the session data and save it to your costom post type.
add_action('woocommerce_checkout_update_order_meta', 'new_order', 10, 2)
function new_order($order_id, $data) {
global $woocommerce;
// At this point the order is created and the session data is still alive.
if(! is_admin() ) {
$step_two_data = $woocommerce->session->get('step_two_data');
if($step_two_data) {
$args = array(
'post_author' => get_current_user_id(),
'post_title' => 'The Job title here',
'post_type' => 'job',
'post_status' => 'publish'
);
$new_job_post_id = wp_insert_post($args);
if($new_job_post_id) {
// Job post is saved now..
// Now you'll probably want to add step_two_data as meta data to the post.
}
}
}
}
NOTE: I haven't tested this code, error handling is not included, etc. This is just a pointer how to save the session data when the order is created.
You'll have to do much more, for example, i see that the job listing has a set expiration date. I would use a cron-job to daily check which jobs have to be removed, with the same cron i would also inform customers their job post 'will be removed in 2 days' etc etc ;-)
Regards, Bjorn
So first I'll say the plugin works fine, returns correct rates and all that perfectly. What I am attempting to do is send to paypal a custom attribute that displays which UPS service that was selected (ground, 2nd day air, 3rd day, etc).
I know the custom attribute is reaching paypal correctly because I tested the code as follows:
$paypal_args = array(
'CUSTOM' => "THIS IS MY SHIPPING"
);
And it creates the "CUSTOM" field and displays the text on my paypal dashboard when I'm looking at the order details.
I've tried the following with no success:
'CUSTOM' => $order -> method_title,
&
'CUSTOM' =>$order -> shipping_method_title,
I feel like it's should look something like this:
$order -> (whatever variable I'm missing)
I'm adding the solution to my problem here just in case anyone stumbles across this issue.
So from the beginning the code was entered in to the following file on the woothemes UPS shipping method plugin: class-wc-paypal-advanced.php
I added the following line: 'CUSTOM' => $order ->get_shipping_method(), and what it does now is it sends a "CUSTOM" attribute to paypal which will read "ups ground" or "2nd day air" in my paypal transaction details.
I have a problem that I am not sure how to fix.
I have a formstack form on my wordpress site. It allows people to buy a product. For this
particular page, there is only one item available for sale, so once the
form is processed (data sent to Formstack->Stripe and payment confirmation received),
the page needs to "turn off" so others can't purchase the item.
Before I used formstack, I used gravity forms plugin.
When the form submitted, I had a add_action filter in my functions.php in
wordpress. It fired when gravity forms completed the submission process and
ran a function that turned off the page.
Here is that code that worked beautifully.
add_action("gform_after_submission", "set_post_content", 10, 2);
function set_post_content(){
global $cfs;
$field_data = array('sold' => '1');
$post_data = array('ID' => get_the_ID()); // the ID is required
$cfs->save($field_data, $post_data);
}
I see formstack has a webhook function.
I cannot seem to find code on how to parse the data the formstack webhook sends. I used http://requestb.in/ to see the data that was being sent.
I believe I need to use php://input, but once I read the data, I am not sure how to say
If formstack webhook fires, then run this code
function set_post_content(){
global $cfs;
$field_data = array('sold' => '1');
$post_data = array('ID' => get_the_ID()); // the ID is required
$cfs->save($field_data, $post_data);
}
I also believe the code needs to be in the functions.php in my theme file because otherwise it won't understand the $cfs variable that is from another wordpress plugin.
I saw this new formstack function the other day - it sounds like it could solve your problem?http://support.formstack.com/customer/portal/articles/1444519-event-fields
Event handling options
When your Event has filled to capacity, you can mark the Event as "Sold Out" so new submitters will see the item is no longer available. You may also choose to hide this field on the Form once the items have sold out. Additionally, you can deactivate the whole Form when the Event has sold out; this is done through the Form Settings tab > General > Deactivate Form settings.
if (isset($_GET['add']) && isset($_GET['price']) && isset($_GET['qty'])){
$ITEM = array(
//Item name
'name' => $_GET['add'],
//Item Price
'price' => $_GET['price'],
//Qty wanted of item
'qty' => $_GET['qty']
);
$_SESSION['SHOPPING_CART'][] = $ITEM;
An item is added in cart when page is refresh. any one help how to remove url variable??
A POST request is designed to update the server's state.
A GET request is not.
You are using the wrong tool for the job. Adding an item to your shopping cart should be a POST request.
As Alex mentions from a http protocol perspective you should use POST requests to update your cart.
Keep in mind that the problem persists using GET or POST request. POST are even more anoying because and alert is displayed to the customer.
To avoid that refreshing the page in the browser the shopping cart gets another duplicated item you can choose for example :
Sends a redirection (301,302) after adding the item to the browser to clean the vars from the url/request
Use AJAX to add items to the shopping cart