WordPress.org

Ready to get started?Download WordPress

Forums

eShop
[resolved] Offer free shipping by country/zone? (27 posts)

  1. daymobrew
    Member
    Posted 1 year ago #

    I would like to offer customers free shipping if the cart is over a certain amount. That amount will be different based on the destination country.

    I realise that this is not possible within the module settings so I am looking at overriding the is_shipfree() function from cart-functions.php.

    How can I access the destination country and shipping zone number?
    Is $_POST['country'] available?

    http://wordpress.org/extend/plugins/eshop/

  2. esmi
    Forum Moderator
    Posted 1 year ago #

    Try checking the eShop $_SESSION.

  3. daymobrew
    Member
    Posted 1 year ago #

    I found $_POST['ship_country'] and then I got the zone:

    // Check shipping country for free shipping - 60 for Ireland (zone 1) and 100 for UK/Europe (zone 2).
    $country_code=$wpdb->escape($_POST['ship_country']);
    $country_table=$wpdb->prefix.'eshop_countries';
    $ship_zone = $wpdb->get_var("SELECT zone FROM $country_table WHERE code='$country_code' limit 1");

    I tried redeclaring is_shipfree() in my theme's functions.php but I get the "Cannot redeclare is_shipfree() (previously declared in /wp-content/plugins/eshop/cart-functions.php:447)" error message.

    I know that is_shipfree() has a function_exists() check but it must get loaded before my code.

    How can I resolve this? Do I have to write a small plugin?

  4. daymobrew
    Member
    Posted 1 year ago #

    I put the new is_shipfree() function in wp-content/plugins/aaa-eshop-shipfree/aaa-eshop-shipfree.php (to help it be activated earlier than eshop).

    Unfortunately when I active the plugin WordPress says that is_shipfree() has already been declared. I could deactivate eshop then activate my plugin and then eshop but I am reluctant to do this.

    When I put the file in wp-content/mu-plugins/aaa-eshop-shipfree.php but it didn't appear to get executed.

  5. esmi
    Forum Moderator
    Posted 1 year ago #

    You're right about the function in eShop loading before yours. But we could add an action or a filter to the is_shipfree() core function that you could then use in an add-on plugin or via your theme's functions.php.

    Which would you prefer - action or filter?

  6. daymobrew
    Member
    Posted 1 year ago #

    I don't have a preference.
    My first thought was a filter where the function's return value is modified.
    http://pastebin.com/P95V3sRh
    The only variable I could think of passing was $total. Adding more will only lead to others requesting additional parameters.

    An action would be pretty much the same.

  7. esmi
    Forum Moderator
    Posted 1 year ago #

    I've flagged this topic up for eShop's main developer. If he does manage come up with something soon, he'll fill you in with the details so you can manually update your copy of the plugin immediately. any changes will be them rolled into the next plugin update.

  8. daymobrew
    Member
    Posted 1 year ago #

    Thanks.
    I think that I will modify my copy per my pastebin.com idea so that am not blocking my client.

  9. elfin
    Moderator
    Plugin Author

    Posted 1 year ago #

    changed for next release:

    [removed code]

    making a further necessary change.

  10. elfin
    Moderator
    Plugin Author

    Posted 1 year ago #

    codes amended, let me know if this uits your needs.

    if (!function_exists('is_shipfree')) {
    	function is_shipfree($total){
    		global $blog_id,$eshopoptions;
    		$shipfree = false;
    		$amt=$eshopoptions['discount_shipping'];
    		if(isset($_SESSION['eshop_discount'.$blog_id]) && eshop_discount_codes_check()){
    			$chkcode=valid_eshop_discount_code($_SESSION['eshop_discount'.$blog_id]);
    			if($chkcode && apply_eshop_discount_code('shipping'))
    				$shipfree = true;
    		}
    		if($amt!='' && $amt <= $total)
    			$shipfree = true;
    
    		return apply_filters('eshop_is_shipfree',$shipfree, $total);
    	}
    }

    and for some reason this one is niggling me - the filter name will not change, nor its placement - but I may change the code.

  11. daymobrew
    Member
    Posted 1 year ago #

    Perfect, thanks.
    Here is my working code:

    // Check shipping country for free shipping - 60 for Ireland (zone 1) and 100 for UK/Europe (zone 2).
    add_filter('eshop_is_shipfree', free_shipping_checks, 10, 2);
    
    function free_shipping_checks($shipfree,$total) {
      global $wpdb;
    
      $country_code=$_POST['ship_country'];
      $country_table=$wpdb->prefix.'eshop_countries';
      $ship_zone = $wpdb->get_var("SELECT zone FROM $country_table WHERE code='$country_code' limit 1");
    
      // Ireland is zone 1.
      if (($ship_zone == 1) && ($total >= 60)) {
        return true;
      }
      // UK/Europe is zone 2.
      if (($ship_zone == 2) && ($total >= 100)) {
        return true;
      }
    
      return $shipfree;
    }
  12. WorkingOnClouds
    Member
    Posted 1 year ago #

    Hi Daymobrew,

    how did you solve this?
    I need this for my client too.

    Where did you paste that code?
    I tried to paste it in cart-functions.php
    But my shopping cart went blank.

    Can you help me out?

    Regards

  13. daymobrew
    Member
    Posted 1 year ago #

    elfin's update to is_shipfree() goes into eshop/cart-functions.php.

    I put my code in the theme's functions.php (though I should move it to a site plugin).

  14. WorkingOnClouds
    Member
    Posted 1 year ago #

    Thanks for your quick reply!!!
    I will give it a try.

    Yes, a plugin would be nice. I think useful for lots of people.

  15. daymobrew
    Member
    Posted 1 year ago #

    A "site plugin" is not a plugin is unlikely to be useful to others as it would generally contain snippets of code for use on a specific site.

    Putting my free shipping code into a plugin would definitely not be useful to others as the values are specific to my client's site.

    Just put it in your theme's functions.php. That is an appropriate location.

    Sorry for the confusion. I should not have mentioned "site plugin"

  16. WorkingOnClouds
    Member
    Posted 1 year ago #

    No problem!
    Maybe i`m not that good in coding, but for me its not working.

    In functions.php i pasted this, just before the last ?> :

    if function free_shipping_checks($shipfree,$total) {
      global $wpdb;
    
      $country_code=$_POST['ship_country'];
      $country_table=$wpdb->prefix.'eshop_countries';
      $ship_zone = $wpdb->get_var("SELECT zone FROM $country_table WHERE code='$country_code' limit 1");
    
      // Netherlands is zone 1.
      if (($ship_zone == 1) && ($total >= 75)) {
        return true;
      }
      // UK/Europe is zone 2.
      /*if (($ship_zone == 2) && ($total >= 100)) {
        return true;
      }*/
    
      return $shipfree;
    }

    In cart-functions.php i pasted this:

    // Check shipping country for free shipping - 60 for Ireland (zone 1) and 100 for UK/Europe (zone 2).
    add_filter('eshop_is_shipfree', free_shipping_checks, 10, 2);
    
    if (!function_exists('is_shipfree')) {
    	function is_shipfree($total){
    		global $blog_id,$eshopoptions;
    		$shipfree = false;
    		$amt=$eshopoptions['discount_shipping'];
    		if(isset($_SESSION['eshop_discount'.$blog_id]) && eshop_discount_codes_check()){
    			$chkcode=valid_eshop_discount_code($_SESSION['eshop_discount'.$blog_id]);
    			if($chkcode && apply_eshop_discount_code('shipping'))
    				$shipfree = true;
    		}
    		if($amt!='' && $amt <= $total)
    			$shipfree = true;
    
    		return apply_filters('eshop_is_shipfree',$shipfree, $total);
    	}
    }

    Am i doing well?

  17. esmi
    Forum Moderator
    Posted 1 year ago #

    There's no way that a generic plugin could be created that would apply to every site/situation. The best that could be produced would be an example plugin that would still need editing to suit the needs of a specific site. Furthermore, this plugin/code cannot be implemented until the next version of eShop is released.

  18. WorkingOnClouds
    Member
    Posted 1 year ago #

    oh, my wrong.
    Sorry, for the misunderstanding.
    Is there any other solution?

  19. esmi
    Forum Moderator
    Posted 1 year ago #

    Not at the moment. You'd need to wait until the next version of eShop is released in about a month or so. Once that is available, we may publish some example code that you could use as the basis for a site-specific plugin on http://quirm.net/wiki/eshop/additional-plugins-and-code-snippets/

  20. WorkingOnClouds
    Member
    Posted 1 year ago #

    Ok, thanks for the repsonse :)
    I will tell my client.

  21. elfin
    Moderator
    Plugin Author

    Posted 1 year ago #

    // Check shipping country for free shipping - 60 for Ireland (zone 1) and 100 for UK/Europe (zone 2).
    add_filter('eshop_is_shipfree', free_shipping_checks, 10, 2);

    should not be added to cart-functions.php it should be added (in your case) to the themes functions.php along with the function you have already added.

  22. daymobrew
    Member
    Posted 1 year ago #

    I used the updated is_shipfree() in eshop/cart-functions.php and put the other code, free_shipping_checks, in functions.php.

    @WorkingOnClouds: I can help you (and your client) if you want. For free.

  23. Angelp357
    Member
    Posted 1 year ago #

    I'm having the same problem. @daymobrew would you be able to help me out?

  24. daymobrew
    Member
    Posted 1 year ago #

    @Angelp357: Contact me via http://www.damiencarbery.com/contact/

  25. WorkingOnClouds
    Member
    Posted 1 year ago #

    Hi Daymobrew,

    wow, that would be very very nice.
    I will contact you with help of above contact details, ok?

  26. daymobrew
    Member
    Posted 1 year ago #

    Oops, what I have a let myself in for :-)

    @WorkingOnClouds: Yes, use the contact page mentioned above.
    In the form describe what you are trying to do.

  27. Angelp357
    Member
    Posted 1 year ago #

    @daymobrew Thank you very much for helping with this issue. The site is working great and I owe it all to you!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic