<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Durgesh Tayade on Medium]]></title>
        <description><![CDATA[Stories by Durgesh Tayade on Medium]]></description>
        <link>https://medium.com/@dwebsoftguy?source=rss-8bd3c61fafff------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*tZ7dlZaJmkW_9eLaE5U4Ag.jpeg</url>
            <title>Stories by Durgesh Tayade on Medium</title>
            <link>https://medium.com/@dwebsoftguy?source=rss-8bd3c61fafff------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 11:34:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dwebsoftguy/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to Modify Existing Elementor Widgets to Match Your Designs]]></title>
            <link>https://medium.com/@dwebsoftguy/how-to-modify-existing-elementor-widgets-to-match-your-designs-fb9bd8d9f8fb?source=rss-8bd3c61fafff------2</link>
            <guid isPermaLink="false">https://medium.com/p/fb9bd8d9f8fb</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[elementor]]></category>
            <category><![CDATA[web-design]]></category>
            <category><![CDATA[wordpress]]></category>
            <category><![CDATA[wordpress-development]]></category>
            <dc:creator><![CDATA[Durgesh Tayade]]></dc:creator>
            <pubDate>Mon, 23 Dec 2019 17:08:08 GMT</pubDate>
            <atom:updated>2019-12-23T17:08:08.299Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*vm67zEaJ126hrKS0T_OCsQ.jpeg" /><figcaption>Credit: https://wptips.dev</figcaption></figure><p>There are many page builders already out, but I personally think that Elementor is better in every way. As a developer, I cannot describe the convenience this plugin provides.</p><p>Before Elementor, if my clients would have a requirement for the custom design, I had to create a custom theme for them which is heavy on cost and time. Typically, clients are short on budget and I would be in a difficult situation.</p><p>Elementor Pro has a Theme Builder which makes it very easy for us to create a custom design theme as per the client’s requirement and in a very cost-effective way. Now I use Elementor for most of the projects.</p><p>But… But…</p><p>Nothing is perfect in this world. <strong>There will always be a case in which the widget or the addons you are using does not match your required design.</strong></p><p>In this tutorial, we are going to learn the process of how to solve such problems. Let’s start!</p><h3>Use-case:</h3><p>The scenario is that we have a website with the Elementor plugin installed. We want to create a section on the homepage which will have 3 columns each including a thumbnail image, a title, a subtitle, and some description.</p><p>Now, we will find the Elementor widget which is a close match to our design. Fortunately, we found one — <strong>the default Image Box</strong>. Image Box will allow us to have a thumbnail image, a title, and a description.</p><p>Below is what we can achieve using the default Image Box:</p><figure><img alt="Complete Section Using Default Image Box Widget" src="https://cdn-images-1.medium.com/max/1024/1*TX2felLdUob3XI74YUWx8w.jpeg" /><figcaption>Complete Section Using Default Image Box Widget</figcaption></figure><p>But we need a subtitle field. This is what we want to finally achieve:</p><figure><img alt="Default Vs Required" src="https://cdn-images-1.medium.com/max/960/1*a4FZL7WsLrsNtjPcsR7NwA.jpeg" /><figcaption>Default Vs Required</figcaption></figure><p>The option to add the subtitle is not available in the default Image Box widget. If the description field would have been a WYSIWYG editor you could have added the subtitle in it and created a similar design. But it’s a normal text box.</p><p>You can, of course, create the same design by using separate widgets and then stack them together but if you are like me who needs strong solutions, below is the process for you.</p><p>Let’s build this step by step.</p><h3>Step 1: Create an Extension containing the Copy of Image Box Widget</h3><p>We don’t want to modify the plugin’s code directly, so we will need to create a plugin that extends the Elementor Plugin.</p><p>Since creating an extension from scratch would make a very long tutorial, we have prepared a starter plugin that already contains the Image Box widget:</p><p><a href="https://github.com/DWebSoft/elementor-extension-wptips-tutorial">Get the Starter Plugin</a></p><p>If you are interested to learn more, read <a href="https://developers.elementor.com/creating-an-extension-for-elementor/">Elementor’s official doc</a> about the step by step process of creating an extension.</p><p>For your reference, these are the necessary steps to copy a default widget into your extension:</p><ol><li>Get the code in Elementor plugin folder &gt; includes &gt; widgets &gt; image-box.php.</li><li>Change the class name, return value of get_name() and get_title(). Otherwise, there will be a conflict with an old and new widget.</li><li>Make sure to use the appropriate namespaces otherwise some classes will not load and you will see a spinner loading in your Elementor Panel. And that won’t give any error which is very hard to debug.</li><li>Then you will need to require this file and register our new widget into init_widgets() of your main extension file.</li></ol><h3>Step 2: Check Whether the New Widget is Installed Properly</h3><p>First, activate the extension plugin. Then create a new page and try adding the new widget which is called “WP Tips Image Box”.</p><p>If you can find the new widget, it is time to get dirty with code.</p><h3>Step 3: Add a new field for Subtitle</h3><p>We are going to add a new field in “Content” tab as shown in the picture below:</p><figure><img alt="Content Tab Options" src="https://cdn-images-1.medium.com/max/960/1*lo3b8dzzvw2XaHD9aySoMQ.jpeg" /><figcaption>Content Tab Options</figcaption></figure><p>Open image-box.php and look for the code below (around line no. 131):</p><pre>widgets/image-box.php</pre><pre>$this-&gt;add_control(<br>  &#39;title_text&#39;,<br>  [<br>    &#39;label&#39; =&gt; __( &#39;Title, Subtitle &amp; Description&#39;, &#39;elementor&#39; ),<br>    ...<br>  ]<br>);</pre><p>After that code, add a control for our new subtitle field:</p><pre>$this-&gt;add_control(<br>  &#39;subtitle_text&#39;,<br>  [<br>    &#39;label&#39; =&gt; __(&#39;Subtitle&#39;, &#39;elementor&#39;),<br>    &#39;type&#39; =&gt; Controls_Manager::TEXT,<br>    &#39;dynamic&#39; =&gt; [<br>      &#39;active&#39; =&gt; true,<br>    ],<br>    &#39;default&#39; =&gt; __(&#39;This is the subtitle&#39;, &#39;elementor&#39;),<br>    &#39;placeholder&#39; =&gt; __(&#39;Enter your subtitle&#39;, &#39;elementor&#39;),<br>    &#39;show_label&#39; =&gt; false,<br>    &#39;label_block&#39; =&gt; true,<br>  ]<br>);</pre><p>Save the file and you should see a new subtitle field in your widget.</p><p>Now, at the end of the Content tab, you can see that we have an option to set an HTML tag for the title. We need to have the same option for our subtitle too.</p><p>Look for the code (around line no. 215):</p><pre>$this-&gt;add_control(<br>  &#39;title_size&#39;,<br>  [<br>    &#39;label&#39; =&gt; __( &#39;Title HTML Tag&#39;, &#39;elementor&#39; ),<br>    &#39;type&#39; =&gt; Controls_Manager::SELECT,<br>    ...<br>  ]<br>);</pre><p>After that code, add a similar option for selecting an HTML tag for the subtitle:</p><pre>$this-&gt;add_control(<br>  &#39;subtitle_size&#39;,<br>  [<br>    &#39;label&#39; =&gt; __( &#39;Subtitle HTML Tag&#39;, &#39;elementor&#39; ),<br>    &#39;type&#39; =&gt; Controls_Manager::SELECT,<br>    &#39;options&#39; =&gt; [<br>      &#39;h1&#39; =&gt; &#39;H1&#39;,<br>      &#39;h2&#39; =&gt; &#39;H2&#39;,<br>      &#39;h3&#39; =&gt; &#39;H3&#39;,<br>      &#39;h4&#39; =&gt; &#39;H4&#39;,<br>      &#39;h5&#39; =&gt; &#39;H5&#39;,<br>      &#39;h6&#39; =&gt; &#39;H6&#39;,<br>      &#39;div&#39; =&gt; &#39;div&#39;,<br>      &#39;span&#39; =&gt; &#39;span&#39;,<br>      &#39;p&#39; =&gt; &#39;p&#39;,<br>      ],<br>    &#39;default&#39; =&gt; &#39;h5&#39;,<br>  ]<br>);</pre><p>Refresh the page and you will see this option at the bottom of the ‘Content’ tab.</p><h3>Step 4: Create options to style the subtitle.</h3><p>If you goto ‘Style’ tab for the new Image Box widget, you will see that we have multiple options to style the title. We need to add similar ones for the subtitle.</p><figure><img alt="Style Tab Options" src="https://cdn-images-1.medium.com/max/960/1*jzmTI90QVJkJlGGVXPJwqA.jpeg" /><figcaption>Style Tab Options</figcaption></figure><p>Let’s create new style controls for the subtitle. Look for the code below ( around line no. 522):</p><pre>widgets/image-box.php</pre><pre>$this-&gt;add_group_control(<br>  Group_Control_Typography::get_type(),<br>  [<br>    &#39;name&#39; =&gt; &#39;title_typography&#39;,<br>    ...<br>  ]<br>);</pre><p>After that code, add similar styling options for the subtitle.</p><pre>$this-&gt;add_control(<br>  &#39;heading_subtitle&#39;,<br>  [<br>    &#39;label&#39; =&gt; __(&#39;Subtitle&#39;, &#39;elementor&#39;),<br>    &#39;type&#39; =&gt; Controls_Manager::HEADING,<br>    &#39;separator&#39; =&gt; &#39;before&#39;,<br>  ]<br>);</pre><pre>$this-&gt;add_responsive_control(<br>  &#39;subtitle_bottom_space&#39;,<br>  [<br>    &#39;label&#39; =&gt; __(&#39;Spacing&#39;, &#39;elementor&#39;),<br>    &#39;type&#39; =&gt; Controls_Manager::SLIDER,<br>    &#39;range&#39; =&gt; [<br>      &#39;px&#39; =&gt; [<br>        &#39;min&#39; =&gt; 0,<br>        &#39;max&#39; =&gt; 100,<br>      ],<br>    ],<br>    &#39;selectors&#39; =&gt; [<br>      &#39;{{WRAPPER}} .elementor-image-box-subtitle&#39; =&gt; &#39;margin-bottom: {{SIZE}}{{UNIT}};&#39;,<br>    ],<br>  ]<br>);</pre><pre>$this-&gt;add_control(<br>  &#39;subtitle_color&#39;,<br>  [<br>    &#39;label&#39; =&gt; __(&#39;Color&#39;, &#39;elementor&#39;),<br>    &#39;type&#39; =&gt; Controls_Manager::COLOR,<br>    &#39;default&#39; =&gt; &#39;&#39;,<br>    &#39;selectors&#39; =&gt; [<br>      &#39;{{WRAPPER}} .elementor-image-box-content .elementor-image-box-subtitle&#39; =&gt; &#39;color: {{VALUE}};&#39;,<br>    ],<br>    &#39;scheme&#39; =&gt; [<br>      &#39;type&#39; =&gt; Schemes\Color::get_type(),<br>      &#39;value&#39; =&gt; Schemes\Color::COLOR_1,<br>    ],<br>  ]<br>);</pre><pre>$this-&gt;add_group_control(<br>  Group_Control_Typography::get_type(),<br>  [<br>    &#39;name&#39; =&gt; &#39;subtitle_typography&#39;,<br>    &#39;selector&#39; =&gt; &#39;{{WRAPPER}} .elementor-image-box-content .elementor-image-box-subtitle&#39;,<br>    &#39;scheme&#39; =&gt; Schemes\Typography::TYPOGRAPHY_1,<br>  ]<br>);</pre><p>Refresh the page and you will see new styling options in the ‘Style’ tab under Content Section.</p><h3>Step 5: Add the HTML markup to display the subtitle on the page.</h3><p>To modify the HTML that is being displayed as an output of the Widget, we need to make changes in the render() function.</p><p>Find the code below in the render function (around line no: 668)</p><pre>if ( ! Utils::is_empty( $settings[&#39;title_text&#39;] ) ) {<br>  $this-&gt;add_render_attribute( &#39;title_text&#39;, &#39;class&#39;, &#39;elementor-image-box-title&#39; );<br>  ...<br>}</pre><p>This code displays the title on the web page.</p><p>After that code, add the code below to render the subtitle:</p><pre>if (!Utils::is_empty($settings[&#39;subtitle_text&#39;])) {<br>  $this-&gt;add_render_attribute(&#39;subtitle_text&#39;, &#39;class&#39;, &#39;elementor-image-box-subtitle&#39;);</pre><pre>  $this-&gt;add_inline_editing_attributes(&#39;subtitle_text&#39;, &#39;none&#39;);</pre><pre>  $subtitle_html = $settings[&#39;subtitle_text&#39;];</pre><pre>  $html .= sprintf(&#39;&lt;%1$s %2$s&gt;%3$s&lt;/%1$s&gt;&#39;, $settings[&#39;subtitle_size&#39;], $this-&gt;get_render_attribute_string(&#39;subtitle_text&#39;), $subtitle_html);<br>}</pre><p>Refresh the page and you will see the subtitle is being displayed.</p><h3>Step 6: Add Javascript code.</h3><p>This is our last step. You can see that if you make any changes to the text or styles of the subtitle, they are not reflected immediately.</p><p>This is because we have not added any Javascript to reflect changes immediately.</p><p>Find the code below in _content_template() function (around line no. 746).</p><pre>if ( settings.title_text ) {<br>  var title_html = settings.title_text;<br>  ...<br>}</pre><p>After that code, add the code below:</p><pre>if ( settings.subtitle_text ) {<br>  var subtitle_html = settings.subtitle_text;</pre><pre>  view.addRenderAttribute( &#39;subtitle_text&#39;, &#39;class&#39;, &#39;elementor-image-box-subtitle&#39; );</pre><pre>  view.addInlineEditingAttributes( &#39;subtitle_text&#39;, &#39;none&#39; );</pre><pre>  html += &#39;&lt;&#39; + settings.subtitle_size  + &#39; &#39; + view.getRenderAttributeString( &#39;subtitle_text&#39; ) + &#39;&gt;&#39; + subtitle_html + &#39;&lt;/&#39; + settings.subtitle_size  + &#39;&gt;&#39;;<br>}</pre><p>Now if you go back and refresh the page, you will see the changes reflected immediately if you try to edit content or styles of the subtitle.</p><p>This is how your final output should look:</p><figure><img alt="Final Output" src="https://cdn-images-1.medium.com/max/1024/1*NriCTueIifkiVTJ_uvv0Rw.jpeg" /><figcaption>Final Output</figcaption></figure><h3>Conclusion</h3><p>I know this was a long tutorial to follow. But once you understand the process for how you should modify the Elementor widget, it will become very easy for you to extend the Elementor the way you want.</p><p>Elementor also provides hooks if you want to add control or sections. But it doesn’t give you much flexibility in terms of adding the controls at specific locations. So I don’t prefer this option.</p><p>I hope you will be much confident in recreating an Elementor Widgets as per your design requirements.</p><p>PS:</p><p>I have originally written this article for <a href="https://wptips.dev/elementor-widgets-to-match-designs/">WPTips.dev</a>.</p><p>If you need any help in implementing above solution or you want me to work on your WordPress Projects, feel free to email me on: dwebsoftguy@gmail.com.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fb9bd8d9f8fb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Try Gatsby for your next client project.]]></title>
            <link>https://medium.com/@dwebsoftguy/try-gatsby-for-your-next-client-project-bf46e701d649?source=rss-8bd3c61fafff------2</link>
            <guid isPermaLink="false">https://medium.com/p/bf46e701d649</guid>
            <category><![CDATA[gatsbyjs]]></category>
            <category><![CDATA[wordpress]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Durgesh Tayade]]></dc:creator>
            <pubDate>Fri, 21 Dec 2018 07:09:48 GMT</pubDate>
            <atom:updated>2018-12-21T07:09:48.380Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*veATTIC3Gub5EOei6hU-zw.png" /><figcaption>Snap from gatsbyjs.org</figcaption></figure><p>If you have not yet tried Gatsby, I would definitely recommend you to try it once.</p><p>Gatsby helps you to create blazing fast websites. You will see how powerful it is.</p><p><a href="https://www.gatsbyjs.org/">https://www.gatsbyjs.org/</a></p><p>Disclaimer: I’m not anyhow affiliated to Gatsby :)</p><p>Basically, Gatsby is a static website generator. It is built using the powerful React framework. So if you have a client who needs a small good looking website, Gatsby should definitely be your first choice. And why not? it helps visitors to navigate between pages WITHOUT a page refresh!</p><p>Isn’t that cool guys?</p><p>Your client will definitely love it.</p><p>Now you say, Durgesh, but our client needs some blog posts too.</p><p>Ok ok. I understand that. I too have such clients. I’m a WordPress developer. So I got that question too.</p><p>But what if I told you that Gatsby allows you to connect your website with any data source. That means I can easily connect that to my WordPress / Joomla / Contentful CMS.</p><p>Believe me, you can manage a complete Gatsby website using WordPress CMS.</p><p>Let me show you some example I’m working on.</p><p><a href="http://durgesh-wordpress.surge.sh/">http://durgesh-wordpress.surge.sh/</a></p><p>This is the website I use to practice Gatsby. All it’s content is managed by WordPress CMS.</p><p>Now you say, it doesn’t look like a complete website. I told you, it’s a practice website.</p><p>So here’s the another example of Gatsby.</p><p><a href="http://appsolutegeek.surge.sh/">AppSoluteGeek</a></p><p>This is the client’s project I’m currently working on. But most of the part functions well. Content is dummy but fetched via Contentful CMS.</p><p>I’m learning it from past 4 months. I really loved it and have started using it in my projects.</p><p>If you want to learn more, I would suggest you to check following links:</p><p><a href="https://www.gatsbyjs.org/">GatsbyJS</a></p><p><a href="https://www.youtube.com/playlist?list=PLLnpHn493BHHfoINKLELxDch3uJlSapxg">https://www.youtube.com/playlist?list=PLLnpHn493BHHfoINKLELxDch3uJlSapxg</a></p><p>If you want any help with this, or want to develop your/clients website using this, drop me an email at contact@durgeshtayade.com</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bf46e701d649" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Add ‘Buy Now’ button in WooCommerce]]></title>
            <link>https://medium.com/@dwebsoftguy/add-buy-now-button-in-woocommerce-804528d41ecf?source=rss-8bd3c61fafff------2</link>
            <guid isPermaLink="false">https://medium.com/p/804528d41ecf</guid>
            <category><![CDATA[woocommerce]]></category>
            <category><![CDATA[wordpress]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[woocommerce-development]]></category>
            <category><![CDATA[wordpress-development]]></category>
            <dc:creator><![CDATA[Durgesh Tayade]]></dc:creator>
            <pubDate>Wed, 07 Mar 2018 18:26:50 GMT</pubDate>
            <atom:updated>2020-05-09T12:08:11.650Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FFmvhMYot0ajVN7rebOkQw.png" /></figure><p><strong>UPDATES — 09th May 2020:</strong> <br><em>First of all, I would like to thank all the readers. This was my first article and it got around 20k views.</em></p><p>I tested the steps written in this article today. This method still works fine.</p><p>In some cases, we need more custom solution depending on the theme. Like in case of AJAX based cart system, we need to make additional changes to theme. This solution doesn’t work in that case.</p><p>For non-tech readers, I found that they still get confused in some steps. So for their convenience, today I quickly created a plugin which provide the functionality described in this article. You can download it here:<br><a href="https://durgeshtayade.com/downloads/add-buy-now-button-woocommerce.zip">https://durgeshtayade.com/downloads/add-buy-now-button-woocommerce.zip</a></p><p>I recommend everyone to download the plugin first and test that. If it works for your theme, that’s great. If not, you can read this article to get the idea of how to modify your theme’s file.</p><p>As this is a separate plugin, we don’t have to modify our theme directly. This way our code is not lost on theme update. <strong>Also, this plugin works with Variable products too!</strong></p><p>Plugin tested on: <br>WordPress: 5.4.1<br>WooCommerce: 4.1.0<br>Storefront theme: 2.5.6</p><p><strong>ARTICLE:</strong></p><p>Before going further I assume that you are already familiar with WooCommerce. If you are just a technology enthusiast, out there to learn something new, I will try to help with some basic foundation for this article.</p><p>WooCommerce in simple as they say:</p><blockquote>A fully customizable, open source eCommerce platform built for WordPress.</blockquote><p>To know more about it click <a href="https://woocommerce.com/">this link</a>.</p><p>To see an actual website using WooCommerce, check the one I am currently developing. <a href="https://damofashions.com/">Go to live demo</a>.</p><p>The workflow of typical WooCommerce website is as follows:</p><ol><li>User clicks on any product displayed on Home/Shop page.</li><li>Now he/she is on ‘Single Product Page’. This page gives more in-depth info about the product.</li><li>Click on ‘Add to Cart’ button. The product is added to cart.</li><li>Visits ‘Cart Page’. Then click on ‘Checkout’ button.</li><li>Fill the details on ‘Checkout Page’ and then proceeds for payment.</li></ol><p>All this functionality is provided for free with WooCommerce and works great for most of the use cases.</p><p>But…</p><blockquote>Every solution can be optimized further…</blockquote><p>Have you figured out some overhead in above workflow?</p><p>Do we really need step 4 if our user just wants to buy that product only?</p><p>We should send him directly to the checkout page. Shouldn’t we?</p><p>So now we got the problem:</p><blockquote>We need to add a simple ‘Buy now’ button aside ‘Add to Cart’ button, which will directly send our user to checkout page instead of cart page.</blockquote><p>Let’s find some solution for this.</p><p>First thing first. Google it. Search for plugins.</p><p>Gotcha!!. found one.</p><p>Ohh, wait. I don’t want the button to be displayed there. It’s style don’t match. It’s looking like something out of box.</p><p>I’m a non-technical person. I’m stuck now. Should I hire a developer?</p><p>Have you been in such situation?</p><p>Don’t worry folks. The solution to it is quite simple. Just follow me along.</p><p><em>I assume that you have access to your theme files.</em></p><p><strong>Note</strong>: We should never update the theme files directly. Instead, use the child theme. If you want to learn how to create one, <a href="https://v4.datafeedr.com/documentation/580">read this article</a>. If your theme provider has provided child theme, upload and activate it. Beware, in some cases, you may have to add Customizer settings again. So always cross check your website after it. If something is broken and you don’t know how to fix it, reactivate your Parent theme and everything will be fine.</p><p>But for purpose of simplicity, I will make changes to parent theme directly. The file we are interested to change should be located at:</p><p><em>/wp-content/themes/your-theme/woocommerce/single-product/add-to-cart/simple.php</em></p><p>If not, just create it keeping same folder structure. If you are using the child theme, create the same folder structure. It will look like:</p><p><em>your-child-theme/woocommerce/single-product/add-to-cart/simple.php</em></p><p>Then copy the code from WooCommerce’s template file ( path given below) and add it to above file.</p><p><em>/wp-content/plugins/woocommerce/templates/single-product/add-to-cart/simple.php</em></p><p>You will see few lines of code here. The part of code we are interested will look as below:</p><pre>&lt;button type=”submit” name=&quot;add-to-cart&quot; value=&quot;&lt;?php echo esc_attr($product-&gt;get_id()); ?&gt;&quot; class=”single_add_to_cart_button button alt”&gt;<br>&lt;?php echo esc_html( $product-&gt;single_add_to_cart_text() ); ?&gt;<br>&lt;/button&gt;</pre><p>Don’t worry if your code looks some different. It’s perfectly fine, as your theme developer has added some extra code. We just have to make sure we find code for ‘Add to Cart’ button.</p><p>Now as per our task, we have to add ‘Buy Now’ button next to it. Just add following code below it.</p><pre>&lt;button type=&quot;submit&quot; name=&quot;add-to-cart&quot; value=&quot;&lt;?php echo esc_attr($product-&gt;get_id()); ?&gt;&quot; class=&quot;single_add_to_cart_button button alt&quot; id=&quot;buy_now_button&quot;&gt;<br>&lt;?php echo esc_html(&#39;Buy Now&#39;); ?&gt;<br>&lt;/button&gt;<br>&lt;input type=&quot;hidden&quot; name=&quot;is_buy_now&quot; id=&quot;is_buy_now&quot; value=&quot;0&quot; /&gt;</pre><p><em>Note: Use the same class used by your theme for the ‘Add to Cart’ button. Or just copy and paste same ‘Add to Cart’ button and make necessary changes.</em></p><p>What this code does is, it will add a new ‘Buy Now’ button after ‘Add to Cart’ button.</p><p>Did you notice the difference between both buttons?</p><ol><li>We have given new button id ‘buy_now_button’, which we will use later while submitting the form.</li><li>We have added extra hidden input field with id ‘is_buy_now’ and value 0. It will help us know if the user has clicked ‘Buy Now’ button.</li></ol><p>I hope everything worked fine for you. If you are a developer, it’s easy for you. I am explaining it in details for non-tech guys.</p><p>Now we have got button in place. If you save and visit your product page, you will see the button added. Now click on it.</p><p>Ohh, wait. It works same as ‘Add to Cart’ button. Right. We are yet to handle the main logic.</p><p>Now we have to add some javascript for our logic to work. Open functions.php file in your theme folder. It will be at:</p><p><em>your-theme/functions.php</em></p><p>or if you are using the child theme, then create it in your child theme folder.</p><p>Add following code at the end of functions.php file:</p><pre>function buy_now_submit_form() {<br> ?&gt;<br>  &lt;script&gt;<br>      jQuery(document).ready(function(){<br>          // listen if someone clicks &#39;Buy Now&#39; button<br>          jQuery(&#39;#buy_now_button&#39;).click(function(){<br>              // set value to 1<br>              jQuery(&#39;#is_buy_now&#39;).val(&#39;1&#39;);<br>              //submit the form<br>              jQuery(&#39;form.cart&#39;).submit();<br>          });<br>      });<br>  &lt;/script&gt;<br> &lt;?php<br>}<br>add_action(&#39;woocommerce_after_add_to_cart_form&#39;, &#39;buy_now_submit_form&#39;);</pre><p>This code adds javascript code below add to cart form. Our javascript code listens for click event on ‘Buy Now’ button. When someone clicks the button, we set the value of hidden input with id ‘is_buy_now’ to 1. We will later use this value to check if ‘Buy Now’ button was clicked or not.</p><p>Note: You can also add this code in main javascript file of your theme. But I preferred to add it here for sake of simplicity.</p><p>Now add following php code at the end of same functions.php file:</p><pre>add_filter(&#39;woocommerce_add_to_cart_redirect&#39;, &#39;redirect_to_checkout&#39;);<br>function redirect_to_checkout($redirect_url) {<br>  if (isset($_REQUEST[&#39;is_buy_now&#39;]) &amp;&amp; $_REQUEST[&#39;is_buy_now&#39;]) {<br>     global $woocommerce;<br>     $redirect_url = wc_get_checkout_url();<br>  }<br>  return $redirect_url;<br>}</pre><p>This is the main code that helps us to redirect the user to checkout page. By default, redirect url is the cart page’s url.</p><p>Remember that we have set hidden input with id ‘is_buy_now’ to value 1. Here we make use of it to differentiate whether user clicked ‘Buy Now’ button or regular ‘Add to Cart’ button.</p><p>So if ‘Buy Now’ button is clicked we set redirect url to checkout page’s url.</p><p>That’s it. We are done!</p><p>Save that file and everything should work fine.</p><p>In summary:</p><ol><li>We added ‘Buy Now’ button aside of ‘Add to Cart’ button to redirect users to checkout page directly.</li><li>To differentiate which button was clicked we used a hidden input element with id ‘is_buy_now’.</li><li>Using this we changed the redirect url to checkout page’s url if ‘Buy Now’ button was clicked.</li></ol><p>If for some case you just need a single button that redirects to the checkout page, you just have to use following code in functions.php file</p><pre>add_filter(&#39;woocommerce_add_to_cart_redirect&#39;, &#39;redirect_to_checkout&#39;);<br>function redirect_to_checkout($redirect_url) {<br>     global $woocommerce;<br>     $redirect_url = wc_get_checkout_url();<br>     return $redirect_url;<br>}</pre><p>No need for that javascript code. Also, don’t forget to rename your ‘Add to Cart’ button in simple.php file(If needed).</p><p><strong>Note that,</strong></p><ul><li>This solution will only work for ‘Simple Products’ and will not work for ‘Variable Products’ or any other product type. For that, you have to use same logic we used in simple.php file in other files that are in the same folder (ex. variation-add-to-cart-button.php)</li><li>This code is only for giving you an idea about the approach you should follow to solve such problems. This solution is not complete and will differ based on the theme you are using e.g some themes use AJAX calls for adding products and this will not work there. Please modify the code accordingly.</li></ul><p>Hope you find this article useful!</p><p>If you got stuck, please feel free contact me:</p><p>dwebsoftguy@gmail.com</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=804528d41ecf" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>