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>';

October 7, 2020 · 1 min · Harshvardhan Malpani

How to track qty changes in cart?

This is not CMS or software specific. Can be used for shopify, magento, wordpress or any other cart page Assumption: All the cart items have an input field for quantity in case they want to change qty for any item Assumption: All those input fields can be selected using queryselector. Either they have common name attribute or a common class. Purpose: We want to change class of update button to show that he has to press update button because quantities have been altered. ...

July 21, 2019 · 1 min · Harshvardhan Malpani

Magento 2 Multi Select click all code – Tax Rates

Put the following code in console. require(["jquery"],function($){ $( ".mselect-fixed label" ).each(function( index ) { if($(this).children("input").hasClass("mselect-checked")){} else $(this).trigger('click'); }); });

April 26, 2019 · 1 min · Harshvardhan Malpani

Understanding “this” keyword in JavaScript.

‘Hi Everyone! In this article, we are about to discuss **‘this’**keyword in JavaScript. It is a very important part of object-oriented JS programming. Hence it becomes crucial for serious developers to understand **‘this’**keyword. It is also one of the most confused concepts of JavaScript. What is ‘this’? Understanding 'this': To be able to understand what I am about to talk, you should be familiar with the basics of JavaScript. e.x – Variables, Objects, Functions, etc… ...

December 15, 2018 · 3 min · Harshvardhan Malpani

How to remove links of a learndash course which has not started yet? without code changes

jQuery(document).ready(function($){ var nost=0; if($("body").hasClass("single-sfwd-courses")){ toba=''; $("#lessons_list a.notavailable").removeAttr("href"); $("#lessons_list a.notavailable").each(function(){ toba=$(this).parent().parent().attr("class"); toba = toba.replace("lesson post-",''); toba = toba.replace(" is_not_sample no-topics",''); toba = toba.replace(" is_not_sample has-topics",''); $('#learndash_topic_dots-'+toba+" a").removeAttr("href"); }); } });

August 9, 2018 · 1 min · Harshvardhan Malpani

Bulk Add Custom Attribute Options in Magento 1

$jq=new jQuery.noConflict(); var mimim=["Yellow Topaz", "Alexandrite"]; $jq.each(mimim,function(a,b){ $jq("#add_new_option_button").click(); $jq("#matage-options-panel .dynamic-grid tbody tr:nth-child(2) td:nth-child(1) input").val(b); });

May 16, 2018 · 1 min · Harshvardhan Malpani

Magento 2 how to show configurable options stock availability on product page

addtocart.phtml <?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ // @codingStandardsIgnoreFile /** @var $block \Magento\Catalog\Block\Product\View */ ?> <?php $_product = $block->getProduct(); ?> <?php $buttonTitle = __('Add to Cart'); ?> <?php if ($_product->isSaleable()): ?> <div class="box-tocart"> <div class="fieldset"> <?php if ($block->shouldRenderQuantity()): $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $StockState = $objectManager->get('\Magento\CatalogInventory\Api\StockStateInterface');?> <div class="field qty"> <label class="label" for="qty"><span><?= /* @escapeNotVerified */ __('Qty') ?></span></label> <div class="control"> <?php if($_product->getTypeId()=="simple") { ?> <select class="input-text qty" name="qty" id="qty" data-validate="<?= $block->escapeHtml(json_encode($block->getQuantityValidators())) ?>"> <?php $availableQty= $StockState->getStockQty($_product->getId(), $_product->getStore()->getWebsiteId()); for($repli=1;$repli<=$availableQty;$repli++) echo "<option value='$repli'>$repli</option>"; ?> </select> <?php } else { $usedProducts = $_product->getTypeInstance()->getUsedProducts($_product); $productStockd=$objectManager->get('Magento\CatalogInventory\Api\StockRegistryInterface'); $finalconfigqty=[]; foreach ($usedProducts as $child) {$childid=$child->getId(); $productStockObj = $productStockd->getStockItem($childid); $availableQty= round($productStockObj->getData('qty')); $finalconfigqty['c'.$childid]=$availableQty; } echo '<script> var fichoo='. json_encode($finalconfigqty). '</script>'; echo '<select class="input-text qty fichoo" name="qty" id="qty"><option value=1>1</option></select>'; ?> <!--input type="number" name="qty" id="qty" value="<?= $block->getProductDefaultQty() * 1 ?>" title="<?= __('Qty') ?>" class="input-text qty" data-validate="<?= $block->escapeHtml(json_encode($block->getQuantityValidators())) ?>" /--> <?php } ?> </div> </div> <?php endif; ?> <div class="actions"> <button type="submit" title="<?= /* @escapeNotVerified */ $buttonTitle ?>" class="action primary tocart" id="product-addtocart-button"> <span><?= /* @escapeNotVerified */ $buttonTitle ?></span> </button> <?= $block->getChildHtml('', true) ?> </div> </div> </div> <?php endif; ?> <?php if ($block->isRedirectToCartEnabled()) : ?> <script type="text/x-magento-init"> { "#product_addtocart_form": { "Magento_Catalog/product/view/validation": { "radioCheckboxClosest": ".nested" } } } </script> <?php else : ?> <script type="text/x-magento-init"> { "#product_addtocart_form": { "Magento_Catalog/js/validate-product": {} } } </script> <?php endif; ?> Another important file is Magento_ConfigurableProduct/web/js/configurable.js ...

February 16, 2018 · 9 min · Harshvardhan Malpani

How to manage Magento 2 product attribute values options using console

This is an update to my previous script which was used to add custom product attribute values using backend – Add values to product attribute Read the previous^ part to get introduction about how it works. you will have to use browser console (ctrl + shift +j in Google chrome) First of all initialize the array mimim with the final set of values you want to see in backend. The script then automatically removes the extra options first(values which are not in mimim but in present in backend), then it adds the remaining values from mimim (which are in mimim but not at backend) ...

November 22, 2017 · 1 min · Harshvardhan Malpani

Magento 2.1x – Add options in custom product attribute using backend

Go to the attribute edit page using magento 2 admin panel (Stores > Attributes > Product > Edit attribute) Use console – ctrl + shift + J Edit the js array mimim and then paste the following code in console. $jq=new jQuery.noConflict(); var mimim=["Black","Blue","Blue Black"]; $jq.each(mimim,function(a,b){ $jq("#add_new_option_button").click(); $jq("#manage-options-panel tbody tr:last-child td:nth-child(3) input").val(b); });

October 14, 2017 · 1 min · Harshvardhan Malpani

How to unlike all Facebook pages from your profile and Clean your newsfeed

Hello humans, I have tried to keep this tutorial simple and detailed. Please proceed with caution. The following tutorial and the procedure will unlike pages you have liked from your profile, Please be clear about that the fact that the code provided here is clean and does not intend to do any harm to your Facebook account. Note – This code uses jQuery library in its original form. So you do not need to be scared while using this “scary” looking code. ...

May 18, 2017 · 3 min · Harshvardhan Malpani