WordPress.org

Ready to get started?Download WordPress

Forums

MarketPress - WordPress eCommerce
[resolved] Free shipping on some products (21 posts)

  1. Robin W
    Member
    Posted 1 year ago #

    I'm using marketpress lite 2.5.1

    In use table rates for shipping based on price, and know that I can add extra costs for a particular product.

    But I'd also like the opposite - to set "free shipping" for particular products.

    Is their a way I can do this either something I missed, by upgrading or by tweaking code or via a plugin?

    http://wordpress.org/extend/plugins/wordpress-ecommerce/

  2. I'm afraid that out of the box this can't be done, and I am not aware of any plugins that can do this.
    However, you could edit the shipping gateway file and add exceptions for these products... I 've never tried anything like that, but I don't see why it wouldn't be done.
    Basically you could check the cart and if the IDs of some products is there, then remove their value from the cart total on shipping calculation.

    I hope that helps!

    Cheers,
    Ari.

  3. Robin W
    Member
    Posted 1 year ago #

    Thanks, suspected that would be the case, and will delve into the shipping php's !

  4. Ann McG
    Member
    Posted 1 year ago #

    I'm also interested in this solution - we sell festival tickets and merchandise. Flat rate shipping is fine for merch, but excessive for tickets. Would like to disregard shipping for that item. If you don't mind sharing your solution, we'd love it!

  5. Robin W
    Member
    Posted 1 year ago #

    Ann...

    Yes exactly the problem I had a couple of months ago when I stumbled across a solution outside of ecommerce, which works really well. I am part way through writing it up, hope to come back in the next 24 hours with a documented solution !

  6. ellbristow
    WPMU DEV Support Staff
    Posted 1 year ago #

    That sounds interesting! I'm intrigued to see what you come up with!

  7. Robin W
    Member
    Posted 1 year ago #

    Firstly, suggest you read this all though, so that you know where you are headed, as it may at first seem long and complicated, but like most things, once achieved it is easy in retrospect!

    Obviously I don’t know your level of expertise, so if some of this is laboured excuse me, and if some is too vague, come back with questions!

    I presume you have a paypal account.

    I will also presume you have an FTP product such as filezilla, and are able to upload and download files. I’ll also presume you know how to use notepad or equivalent to edit a file. If you don’t know these, google “how to use filezilla video” or similar – there are lots of videos that’ll take you through this.

    End results
    From users points of view:
    They access a form within a page (or post) which asks whatever q’s you need (each of which you can set up as mandatory or optional)
    They select membership type within this – or the Q’s make the selection for them (up to you how you set this up)
    They click a payment button
    They are taken to paypal’s payment page with the appropriate words (eg single membership, joint membership) and the correct amount for that type.
    They pay, and go to a thankyou page

    From your point of view:
    You receive an email with answers to the Q’s
    You receive a paypal payment confirmation
    You can then send welcome pack, set up user, do nothing etc.

    If you want to see what this looks like for real, go to my test site

    http://gos.rewweb.co.uk/the-club/membership/

    Feel free to complete the boxes with rubbish and you can quite happily click the payment button to be taken to the Paypal page, but if follow the payment all the way through, I’ll get the money, so stop there !

    You’ll see the last two boxes - membership and newsletter types - combine to determine the amount to be paid.

    OK so if this is what you’re after carry on...

    CformsII is not the easiest forms package to get into setting up, but it does have the neat trick of being able to do things conditional on what answers are given, hence why I used it.

    In terms of getting it working, the following steps are needed :

    1. Download plugin to your PC
    2. Upload to your website
    3. Activate
    4. Set up form
    5. Choose styling
    6. Set up entry page
    7. Set up exit page
    8. Edit my-functions plugin
    9. Go live

    Steps 1 through 4 are best covered by watching the following video on cforms, this shows you installing and takes you through how to set up a form.

    http://www.youtube.com/watch?v=gvB5h9hH8kY

    When you watched this go ahead and install and set up your form.

    When you have done so, go back to the video and take note of the following ;

    Setting up the email bit, as this is how you get the data ! (around 6:30 on the video)
    Setting up messages – I changed “submit” to “Payment” and the success message to “Thank you for your application, proceeding to payment...” to make it clear that you are progressing to the money bit.

    Finally, when they have completed the form, you’ll need a “success page” – you’ll need this for two reasons. Firstly to thank them for filling in the form, but secondly because paypal terms insist you have a confirmation page following payment.

    Mine looks like this

    http://gos.rewweb.co.uk/membership-payment-page/

    You need to put this url into “redirect” part in “core admin” section of the form – this will then come into play after they have made payment.

    CSS Styling

    Having created your form, you can try it by adding it to test page and see what it looks like. At the moment it’ll just go from the form to the post payment page when you click “submit” or “payment” or whatever you call the button - don’t worry we’ll add the hook to payment in between these stages later.

    You may not like how the form is styled – however in the dashboard>cformsII>styling you’ll find different styles you can use, I liked wide_form.css, so chose this.

    If you’re clever you can change the styles via an editor at the bottom of this screen.

    Adding Payment

    Ok, so now that you have created your form, got it looking how you like and all working, finally you can add the payment part. I say finally, because the hook it uses depends on knowing the order of the questions, so you need to have finalised this otherwise you’ll need to keep doing changes to the php file we are about to change.

    This is where we need Filezilla or equivalent – your host provider might have this capability built in – in essence you’re looking for package that lets you do FTP – file transfer protocol.

    As state above if you don’t have one, then filezilla is a popular choice – simply download the Client version, google for videos on how to do this, but make sure it’s the CLIENT one you download.

    Once connected you’ll need to find the current my-functions file in the cforms plugin.

    Navigate the following

    wp-content/plugins/cforms

    Save this away to your local PC as a backup.

    Then create a new my-functions.php and put the following code into it
    <?php
    function my_cforms_logic($cformsdata,$oldvalue,$setting) {

    //### If you're unsure how to reference $cformsdata use the below @mail call to send you the data array
    @mail('goswebmaster@btinternet.com', 'cforms my_action test', print_r($cformsdata,1), 'From: goswebmaster@btinternet.com');
    /*
    if ( $setting == "redirection" ){

    $userfield = $cformsdata['data'][$cformsdata['data']['$$$28']];
    $userfield2 = $cformsdata['data'][$cformsdata['data']['$$$29']];

    if ( $userfield == 'Family' && $userfield2=='By Email')
    return 'https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=XXXXXXXX&item_name=Family%20Membership%20Email%20Newsletter&amount=20%2e00&no_shipping=1&currency_code=GBP&return=YYYYYYYYY';

    if ( $userfield == 'Family' && $userfield2=='By Post')
    return 'https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=XXXXXXXX&item_name=Family%20Membership%20Postal%20Newsletter&amount=25%2e00&no_shipping=1&currency_code=GBP&return=YYYYYYYYY';

    }
    */
    return $oldvalue; // If you use this function, this MUST be the last statement!
    }

    ?>

    Then save it and upload it to replace the existing file ie at wp-content/plugins/cforms

    Then run your membership form, click the submit/payment button. This will now access the new my-functions and send you an email with what fields have what ID no,.s.

    Look at the email and what you are looking for are the $$$ no.s say for instance no.family members is $$$14

    Now go back to your my-functions.php in notepad.

    Comment out the @mail line, and uncomment the bits between the /* and */

    In this version I am looking at two parameters and setting the return dependant on this combination
    If you have only one parameter then change accordingly.

    You’ll see that the if statement then sends the user to the paypal website with lots of parameters in, including your paypal account, item-name, amount, shipping, and return url.

    Now on the return line you need to replace the XXXXXX and YYYYYY

    The XXXXX is you email address that you use for paypal. But this needs to be phrased so that the URL doesn’t contain any punctuation which is used for coding.

    So we need to replace the @ symbol with %40 and the full stops/periods with %2e

    So fred@mail.com becomes fred%40mail%2ecom

    Then we need to change the return url (this is where paypal will send the user back to after payment) again taking out slashes and fullstops/periods. Slashes are %2f, and colons %3a

    So
    http://abc.com/payment-thankyou/

    Becomes

    http%3a%2f%2fabc%2ecom%2fpayment%2dthankyou%2f#

    Finally change the item_name in this line to what you want , and alter the amount, and you have a working couple of lines.

    Then just repeat these two lines (the one starting IF, and the one saying return) for all your other conditions, changing item_name and amount as needed.

    Upload and test.

    Anything not clear – come back and I’ll try and help further !

  8. Robin W
    Member
    Posted 1 year ago #

    ok, so 5 days later, and whilst finalising a route, I stumbled across some other code which led me down an entirely different route.

    Many days of sheer frustration, and I cracked it, end result is really easy, but boy if you are not an expert programmer, it is really hard to piece together lots of helpful posts into a single "how to".

    I always feel that wordpress and associated products are a bit like a car. The codex and documentation gives masses of detail about say the engine, but nothing tells you that this bit helps it go, and that bit helps it stop. A fully documented steering wheel diagram tells you nothing about what it's for, and how you work it !

    Anyway, can't complain as many people write this stuff for us for free, and coding is 100 times as fun as documenting!

    So in the end I have written a plugin, which does two things;

    1. Creates a meta box on each product page that gives a check box for free shipping
    2. Creates a new table rate that amends the table-rate calculation to check for free ship items and excludes them from the calculation.

    To go with that I have spent ten minutes creating a website that you can download it from

    Plugin is available at

    http://www.rewweb.co.uk

    Look for the freeship plugin page and download
    Then go into plugins>add new>upload and upload the zipped file, then activate etc.

    To get the shipping rates to work, you'll need to change from 'table rate' to "fs table rate" then create the table.

    I will add the readme and other bits to make it loadable from wordpress in the next few weeks.

    The coding is fine, but not the prettiest, I am only a junior at this !

    Any other feedback welcome.

  9. ellbristow
    WPMU DEV Support Staff
    Posted 1 year ago #

    I will be honest with you, I haven't read all of your last two posts... it's 9pm where I am and I'm afraid at this time of day a skim read is all I can offer.... however I notice from your latest post that you managed to fix your issue, and the fact that you have provided a downloadable version of your results is great! Nicely done!

  10. Robin W
    Member
    Posted 1 year ago #

    No sweat - know you guys are busy, and was posting for general benefit :-)

  11. Mike
    WPMU DEV Support Staff
    Posted 9 months ago #

    Thanks for posting Robin, that's great and I'm glad you got this sorted out too! :-)

  12. Vince L
    Member
    Posted 8 months ago #

    Robin W thanks for your post! I am a rookie at this and was successfully able to install your plug-in, activate it and configure. Nice job!

    I do have one questions/request; what if I only wanted to offer free shipping on a specific product, but limit it to a specific country? i.e. USA only. All other countries would have Flat Rate apply...
    Regards,
    Vince L

  13. Robin W
    Member
    Posted 8 months ago #

    Vince,

    Will leave this in my inbox - I wrote that plugin a while ago, and will need to get my head back around what it is doing, should be possible, but give me a few days to have a look.

    If I haven't come back by next Thursday, post again and it'll make me feel guilty !

  14. Robin W
    Member
    Posted 8 months ago #

    Ok had a quick look.

    If you know how to edit files then edit

    wp-content/plugins/freeship/freeship_calc.php

    (save the original down to your PC in case it doesn't work !)

    You find on line 268 the following code

    //******shipping_values array added to calculate if free shipping set
    	$shipping_values = array() ;
          foreach ($cart as $product_id => $variations) {
          foreach ($variations as $variation => $data) {
          $id_product=get_the_ID();
    	$fs = get_post_meta($product_id, 'fsFreeShip', true);
    		if($fs !=='on') {
    		$shipping_values[] = $mp->before_tax_price($data['price'], $product_id) * $data['quantity'];
    		}
    	   }
         }
             $total = array_sum($shipping_values) ;
    
    //*****then back to the original code

    paste the following over that to replace that section

    //******shipping_values array added to calculate if free shipping set and country is US
    	$shipping_values = array() ;
          foreach ($cart as $product_id => $variations) {
          foreach ($variations as $variation => $data) {
          $id_product=get_the_ID();
    	$fs = get_post_meta($product_id, 'fsFreeShip', true);
    		if($fs !=='on') {
    		$shipping_values[] = $mp->before_tax_price($data['price'], $product_id) * $data['quantity'];
    		} elseif ($country!=='US') {
    		$shipping_values[] = $mp->before_tax_price($data['price'], $product_id) * $data['quantity'];
    	   } else {
    	   }
         }
    	 }
             $total = array_sum($shipping_values) ;
    
    //*****then back to the original code

    This will then only allow free shipping in the US
    I haven't tested this, so it may not work, but I think it should, but you'll need to test. if it doesn't come back and I'll look again.

    If you are not into editing code, please come back, and I'll cut it into another plugin after the weekend but only if I need to !

  15. Vince L
    Member
    Posted 8 months ago #

    Robin,
    I got side tracked; editting code is a bit beyond my capabilities... afraid I might break something.
    Thanks!
    Vince

  16. Robin W
    Member
    Posted 8 months ago #

    Ok, I'll update the plugin and post back when I have done it

  17. Robin W
    Member
    Posted 8 months ago #

    ok, I've changed the code

    you'll need to delete the existing plugin - don't worry you won't lose any product settings - and download and upload the new one from

    http://www.rewweb.co.uk/freeship-per-product-free-shipping-for-marketpress/

    This now offers free shipping in your base country only.

    Your base country is the one set in dashboard>products>store settings>general settings and under your location.

    Can't see anyone wanting to do free shipping to other countries or worldwide

    So if your websites base country is the US freeshipping is USA only
    If if your websites base country is the UK freeshipping is UK only
    etc.

    I have tested this - but PLEASE do test it yourself to ensure it is doing what you want.

  18. Vince L
    Member
    Posted 8 months ago #

    Robin,

    Deleted previous post.

    Sorry, it does appear to work, even though I deleted the previous version, it was still listed and activated, so I had to deactivate the old and activate the new...

    Thanks,

  19. Robin W
    Member
    Posted 8 months ago #

    Great, but do come back if you spot any issues !

  20. Vince L
    Member
    Posted 7 months ago #

    Hi Robin,
    I just came across another situation... If I have item (a) with free shipping then the customer also buys item (b) which does not have free shipping, the customer is charged shipping...

    If item (a) is a large ticket item and (b) is an accessory going to the same customer, no shipping fees should be charged?

    Does this make sense? Your thoughts?
    Thanks,
    Vince

  21. Robin W
    Member
    Posted 7 months ago #

    They should only be charged shipping for item b - presume that it what it is doing.

    If you wanted to create the situation in your second para, I'd make another product which has a&b as a single item. You can then have a&b as a single product (lets call it c) with free shipping, and product b which bought alone has shipping costs. You could even have product a as well if your customers might not want the accessory, but I'd probably make that an option

    eg One product with the following variations

    Laptop computer $200
    Laptop computer with carry case $220
    Laptop computer with Power adapter $230
    Laptop computer with carry case and adapter $250

    all with free shipping

    then

    carry case $20
    Power adapter $30

    with shipping costs

    To make the code do free shipping with create products would be really quite hard as you might want to ship several large ticket items with their respective accessories.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags