How to add Buy Now button on Product page – WordPress/woocommerce?

Change && to &&

add_filter('woocommerce_add_to_cart_redirect', 'malpani_redirect_checkout_add_cart');

        function malpani_redirect_checkout_add_cart()
        {
            if (isset($_POST["buynow"]) && $_POST["buynow"] === "2") {
                return wc_get_checkout_url();
            }

        }

        add_filter('woocommerce_after_add_to_cart_button', 'malpani_add_buy_button');
        function malpani_add_buy_button()
        {
        echo '<input id="buynowinput" name="buynow" value="1" hidden>
            <button type="button" id="buy_now" class="buy_now button">Buy Now</button>
            <script>
                jQuery(document).ready(function ($) {
                    $("#buy_now").click(function (e) {
                        $("#buynowinput").val(2);
                        $(".single_add_to_cart_button").click();
                        e.stopPropagation();
                        e.preventDefault();
                    })
                });
            </script>';

How to switch your DNS to Google DNS or Cloudflare DNS on Windows 10?

So, this is the scenario. You are using some local ISP which has its own DNS server fulfilling your DNS requests but to speed things up and not rely upon a DNS server which is updated less frequently. For that purpose,we can switch our computer’s DNS to some other public DNS like Google’s or Cloudflare DNS.

Step 1: Right click the Network Icon in your task bar.

Network Icon in Taskbar
Right Click the network icon in taskbar

Step 2: Choose “Open Network & Sharing Settings

Click Open Network & Sharing Settings
Click Open Network & Sharing Settings

Step 3: Click on “Change Adapter Options

change adapter options
change adapter options

Step 4: Right click on the active hardware and select “properties

adapter properties
adapter properties

Step 5: Select “Internet Protocol Version 4 (TCP/IPv4)” and Click Properties button in the bottom

IPv4 Properties

Step 6: Input the IP addresses after choosing “Use the following DNS Server Addresses

put dns ip here
put dns ip here

Step 7: Select OK to close the pop up window. Restart your browser and have a better browsing experience.


Cloudflare’s Public DNS Servers/addresses for IPv4:

1.1.1.1
1.0.0.1

Cloudflare’s Public DNS Servers/addresses for IPv6:

2606:4700:4700::1111
2606:4700:4700::1001

Google’s DNS Servers for IPv4:

8.8.8.8
8.8.4.4

The Google Public DNS IPv6 addresses are:

2001:4860:4860::8888
2001:4860:4860::8844