How to add qty plus minus buttons in shopify?

Many Shopify themes of 2019 had a plain box for the quantity on the product page. This adds a minus and a plus button on either side of it, and stops the plus button at the stock of the selected variant, so shoppers can’t choose more than you have. It builds on my earlier post on showing stock quantities for every variant, which prints each variant’s stock into the page as a JavaScript object called inv_qty. ...

July 21, 2019 · 7 min · Harshvardhan Malpani

Sort keys of an array based on order of values in another array – PHP

Sometimes you have a list of records and a separate list that says what order they should be in. For example, $b holds rows that each start with an ID, and $a holds the same IDs in the order you want to show them. PHP’s built-in sort functions order things by their own values, so an order defined by another array needs a little code of its own. This snippet rebuilds $b in the order given by $a. ...

July 17, 2019 · 2 min · Harshvardhan Malpani

How to filter and validate pincode in Indian woocommerce?

By default, WooCommerce only validates the ZIP code of a few countries. WooCommerce stores in India therefore accept any PIN code a customer types in, including ones with the wrong number of digits. Here is how you can enable checking of the PIN code for Indian WooCommerce stores. WooCommerce checks postcodes in WC_Validation::is_postcode(). In the version linked in the reference below, that function only has rules for Brazil, Switzerland, the UK, Portugal and the US, and returns true for every other country. Its result is passed through the woocommerce_validate_postcode filter before it’s used, so you can add your own rule for India there. ...

July 16, 2019 · 2 min · Harshvardhan Malpani

How to show stock quantity for all variants in shopify?

How to show “xxx left in stock” on shopify product page? Showing how many items are left, especially when stock is low, tells customers whether they need to hurry. Many themes don’t show this out of the box, and the tricky part is products with variants: the number has to change when the customer picks a different size or colour, without reloading the page. This needs three pieces: some Liquid in the product template for the first page load, a few lines of JavaScript for variant changes, and some CSS. ...

July 15, 2019 · 4 min · Harshvardhan Malpani

What is DMARC and How to set it up?

DMARC stands for Domain-based Message Authentication, Reporting, and Conformance It can be used as a way to prevent specific type of SPAM. Hence it should be added as TXT record in your DNS zone, just like SPF and DKIM signatures. Example DMARC policies These are some example policies and how they appear in the DNS TXT record. TXT record hostname must be “_dmarc“ The values in these examples are defined in DMARC TXT record values, below. ...

July 3, 2019 · 1 min · Harshvardhan Malpani

Funny php bug due to hashing and is_numeric

So I was working on an automation project and was testing the api to upload entitites. I used get parameters to send data and wrote a wrapper on server to process that. I used hashes (part of hashes to be precise) to identify the requester instead of using real names. some name came up with hash 12200e7973d0eecd8d75da83e816783496e440e22210ee72cb5cf37f7989a8ff I was using first 10 characters of this has which happen to be ...

June 9, 2019 · 2 min · Harshvardhan Malpani

How to reverse the ids in a mysql table column without breaking primary key constraint?

Let me explain the problem scenario: Let us assume we have a table with 4 columns in it out of which 1 is PRIMARY column and rest 3 contain some data. What we want to do is to reverse the primary key IDs for that data keeping the rest of data intact. It is like shifting the first row to end and moving last row to starting. Initial Data id name email anything 1 jacob whatever how to reverse 3 nathan whosoeverisnathan ids in mysql table column 4 jagmohan idontknowjagmohan without breaking 8 monica iamsexy primary key constraint 9 batman idontexistinrealworld i am batman Data after update id name email anything 9 jacob whatever how to reverse 8 nathan whosoeverisnathan ids in mysql table column 4 jagmohan idontknowjagmohan without breaking 3 monica iamsexy primary key constraint 1 batman idontexistinrealworld i am batman Dude, you are just reversing the column, what is so tough in this? So, this seems simple to reverse an array if isolated by key “id“. But you have to understand that this column is the primary key. So if you run a command to change id for “jacob” to “9“. It will give you error: “Duplicate entry for id 9“ ...

June 1, 2019 · 2 min · Harshvardhan Malpani

How to remove sign in popup from Magento 2 checkout page?

Magento2 has this authentication pop-up on the checkout page, which many store owners won’t like to see on their checkout page. It’s the Sign In button that guests see at the top of the checkout, which opens a login box. If you want guests to go straight to the shipping form, it’s a distraction. Customers who have an account can still sign in without it: when someone types a registered email address in the email field of the shipping step, Magento shows a password field there. ...

May 27, 2019 · 3 min · Harshvardhan Malpani

How to show correct item count in Magento 2 Checkout Order summary?

On the Magento 2 checkout page, the order summary in the sidebar has a heading telling the customer how many items are in the cart. That number counts line items, meaning different products, not the quantity. A customer with five of one product and one of another sees 2 rather than 6, which looks wrong to them. The number comes from a small Knockout template, so the fix is to override that template in your theme and make it show the total quantity instead. ...

May 27, 2019 · 3 min · Harshvardhan Malpani

How to dump all options for any attribute in Magento 2 programmatically?

Sometimes you just need a list of every option of a dropdown attribute, such as all manufacturers or all colours, with their option IDs: to check for duplicates, to map values for an import, or to hand to someone else. The admin shows the options on the attribute’s edit page, but not in a form you can copy easily. This script prints them as a simple two-column table, sorted by label. ...

May 21, 2019 · 3 min · Harshvardhan Malpani