Posted on Leave a comment

How To Get The Wishlist URL From YITH Wishlist Plugin

How To Get The Wishlist URL From YITH Wishlist Plugin 1

YITH Wishlist Plugin is one of the most popular plugin for Woocommerce to add a Wishlist to your WordPress website. The good thing about this plugin is they make it very simple to add the wishlist button to the product page. If you are a regular user, there isn’t many things else to do. However, if you are a developer, you may wonder how can you get the wishlist URL so you can integrate to your own plugin or theme. That’s exactly what I’m going to show you in this post.

How to get the add to wishlist URL of a particular product

If you need nothing else but a working add to wishlist button, you can put this in your code:

do_shortcode('[yith_wcwl_add_to_wishlist product_id=your_product_id]');

Make sure you replace your_product_id with actual ID.

However, YITH wishlist plugin only provide you with the text link like this:

add to wishlist yith button

What if you want to remove the text and get just the heart?

Well, this is how you can get only the URL of the add to wishlist button of YITH wishlist plugin:

esc_url( add_query_arg( 'add_to_wishlist', $your_product_id ) )

What you get from this code is an URL. When you go to that URL, the product will be added to their wishlist.

Pretty easy, isn’t it.

However, I would recommend you send an ajax request to that url instead of open it. That would improve the visitors’ experience greatly.

Caution

One final warning to plugin developers and users of wishlist plugin alike, don’t use multiple wishlist plugins on your site. The reason is because, for example, you installed and activate two wishlist plugin called A and B. There are times you add a product to A’s wishlist and try to view the B’s wishlist page. You will see things that you may not expected. So, remember not to use two different wishlist plugin on one site.

 

 

Posted on 6 Comments

Accessing Media Files (Audio, Video, Images…) From DigitalOcean Spaces Using Java

Accessing Media Files (Audio, Video, Images...) From DigitalOcean Spaces Using Java 2

Recently, I need to upgrade my English learning app on Android to use multiple servers. Previously, I used two servers already. However, the way I manage media files caused me a lot of headache. So, I decided to switch to DigitalOcean since they have servers around the world and the pricing is good ($5 for 250GB storage and 1TB monthly transfer, which is good).

The initial problem with DigitalOcean spaces

Coming from old-school servers, I thought I can upload the files to DigitalOcean spaces using FTP and access the files directly as I usually used. However, the first problem is you cannot upload to spaces using FTP and the second problem is in order to make a file accessible to public, you need to set it permission to public. If you have one or two files, that wouldn’t be a problem.

I have more than 18,000 files.

The solutions to uploading multiple files

It turned out that DigitalOcean spaces use Amazon s3 technologies. So, in order to upload to spaces, you need to have FileZilla Pro (paid) or CyberDuck(free). I chose FileZilla Pro because it allows you to resume failed transfers while CyberDuck doesn’t allow that (or I couldn’t find where is that option).

The solution to accessing files

As my app used by thousands of people, the media files need to be accessible to all of the users. Actually, it is very easy to generate a public accessible URL for any files (they are called objects) using the aws-android-sdk. In case you need a working sample code, here it is:

public class DigitalOcean implements MediaServer {
    private static final String KEY = "YOUR_KEY";
    private static final String SECRETS = "YOUR_SECRETS";
    private String endpoint, bucketName;
    private AmazonS3Client s3Client;

    @Override
    public String getEndpoint() {
        return endpoint;
    }

    @Override
    public String getType() {
        return "s3";
    }

    public DigitalOcean(String endpoint, String bucketName) {
        this.bucketName = bucketName;
        this.endpoint = endpoint;
        AWSCredentials myCredentials = new BasicAWSCredentials(KEY, SECRETS);
        s3Client = new AmazonS3Client(myCredentials);
        s3Client.setEndpoint(this.endpoint);
    }

    public String getMediaURL(String objectPath) {
        GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucketName, objectPath);
        URL objectURL = s3Client.generatePresignedUrl(request);
        return objectURL.toString();
    }
}
 

As you can see, I created an object to generate URL to any files(objects). For example, here is a sample space url:

Accessing Media Files (Audio, Video, Images...) From DigitalOcean Spaces Using Java 3

The bucket name would be data-sample.

If your file, let call it song.mp3 located at /data-sample/media/song.mp3, the objectPath would be: /media/song.mp3.

If you run the method getMediaURL(), you will get the path to the file that is accessible to your users but you don’t have to mark the file public.

https://data-sample.sgp1.digitaloceanspaces.com/media/song.mp3?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20180925T060309Z&X-Amz-SignedHeaders=host&X-Amz-Expires=899&X-Amz-Credential=BP5K25LRRQWYV2CMHZLL%2F20180925%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Signature=6a21133ced60047cfba60053afcdf712997c474585ade2f0050bc853b0a4db89
Posted on Leave a comment

How To Combine Multiple Text Files (.txt) Into One Big File

How To Combine Multiple Text Files (.txt) Into One Big File 4

Recently, I have a specific need to combine multiple files into one big file. The task is very simple. However, if I do it manually (combine over 32,000 small text files into one), it may cost me a day, or even more.

How to combine multiple text files into one

So, I decided to make a tool in Java. Its interface is very simple but you can use it right away without much learning. Here is the app’s interface:

How To Combine Multiple Text Files (.txt) Into One Big File 5

As you can see from the interface, there are three buttons and these are the one you need to pay attention to. To start combining  your small .txt files, click on the button “Select files to combine”. Here, I’m going to select all of my .txt file (over 32,000 files). For those of you who are curious, these are the books from project Gutenberg.

How To Combine Multiple Text Files (.txt) Into One Big File 6

Now, click on Open.

Next, you need to select the destination file. This is the file that contains all the text from the small files.

You can see that the path to the destination file is displayed in the text field at the left of the select button.

Now, simply click on combine now. The program will go ahead and combine your files into one file. In my case, all over 32,000 files are combined into one and the destination file is over 250MB! That’s a lot for a .txt file. In fact, there are more than 7 million line of text inside that file.

How To Combine Multiple Text Files (.txt) Into One Big File 7

If you are a Java developer,  you can check out the repo here on Github here to modify it to your needs. If you are an user, you can download the ready built app here to start combining your .txt files:

Click here to download the executable app.

Posted on Leave a comment

How To Set Sale Price For Woocomerce Products

How To Set Sale Price For Woocomerce Products 8

WooCommerce has made selling on WordPress super easy. You can add a product and sell it in just a few minutes. As a common matter of stores, we have sale events. So, how do you set the sale price for your products? Let’s find out.

The quickest way to set sale price for your product (or to change the sale price if you have already set it) is to go to Products->All products on your dashboard menu. There, you can see the list of all your products. Now, hover your cursor over the product you want to edit the sale price:

How To Set Sale Price For Woocomerce Products 9

Now, click on Quick Edit. You will see the quick edit screen appears:

How To Set Sale Price For Woocomerce Products 10

As you can see, there is a box for your to enter the sale price. If you set a sale price, make sure you also set the regular price and the regular price must be greater than the sale price (it’s obvious, isn’t it).

Finally, click on the update button and you are done. Your customers now will see that your product has a sale offer. Hopefully, your sales will skyrocket soon!

 

Posted on Leave a comment

How To Disable A Shipping Method In Woocommerce

How To Disable A Shipping Method In Woocommerce 11

WooCommerce comes with a few shipping methods and with plugins, you can add more. So, you can have literally unlimited shipping options.  Having multiple shipping methods seems to be a good thing since it gives the customers more options. However, if you know that your customers will use only a certain shipping methods, having more than that can cause confusion.  In this post, we are going to find out how to disable a shipping method in Woocommerce so your customers will have only the methods that suit them.

How To Disable A Shipping Method In Woocommerce

First, go to Woocommerce->Settings and click on Shipping.

woocommerce shipping screen

In the first screen, you can see the list of shipping zones. If you don’t know what shipping zones are, they are the area you can define to apply different shipping policies. This is a very nice option of WooCommerce. For example, you want to apply free shipping in Asia and a flat rate $10 in Europe, you can add two zones Asia and Europe and apply the appropriate shipping methods to those zones.

Now, one zone can have multiple shipping method. For example, my customers in Asia will see this when they checkout:

How To Disable A Shipping Method In Woocommerce 12

Pretty confusing, right? Now, I would like to remove the Free shipping option, here is what I’ll do:

  1. Click on the shipping zone I want to modify its shipping methods, in my case, I will click on Asia.

How To Disable A Shipping Method In Woocommerce 13

As you can see, all the options are listed in the next screen. To disable any shipping method, simply click on the toggle button to turn it off. Here, I’m going to turn off free shipping. Don’t forget to click on Save changes.

If I go and check the checkout page now, the Free shipping method is no longer available:

How To Disable A Shipping Method In Woocommerce 14

That’s it! Now you know how to enable and disable a shipping method for a particular zone in Woocommerce. Thanks for reading and if you have any comments, please leave it below.