Where are customizer settings stored in db for wordpress theme?

How to clone customizer settings in child theme from parent theme? The customizer data is stored in table wp_options under option_name theme_mods_THEME-NAME you can view all such settings via the following query: SELECT * FROM `wp_options` WHERE `option_name` LIKE "theme_mods_%" In some cases, you just want to use parent theme’s settings in newly added child theme. If that is your case too, use the following queries to utilize and close those settings for your child theme also. ...

May 6, 2021 · 1 min · Harshvardhan Malpani

Fixing broken “screen options” in wordpress site

SELECT * from wp_usermeta where `meta_key` like 'edit_%_per_page' So probably you chose “Number of items per page” as 1000 or 200 and now the page doesnt load anymore because your database ran out of memory. If that is the case, run the above query on phpmysql or any other way, edit the numbers and fixed!

January 18, 2021 · 1 min · Harshvardhan Malpani

Gravityforms limit submission – once for user, unlimited for guest

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 public function context() { // rule targets specific user, if this user is different we don't need to test the rule if ( $this->user_id != 'all' ) { if ( $this->user_id != get_current_user_id() ) { return false; } } if($this->user_id == "all") { if(get_current_user_id()===0) { return false; } } return true; } File: gp-limit-submissions/includes/GPLS_Rule_User.php ...

October 22, 2020 · 1 min · Harshvardhan Malpani

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 edit wordpress woocommerce order api responses (legacy + latest)

<?php //// FOR LEGACY API ONLY add_filter('woocommerce_api_order_response', 'harsh_add_shipping_phone_legacy', 99, 1); function harsh_add_shipping_phone($order_data) { $order_data["billing_address"]["email"] = "XXXX"; $shipping_phone = get_post_meta($order_data["id"],"_shipping_phone",1); if($shipping_phone!==false && strlen($shipping_phone)) { $order_data["billing_address"]["biller_phone"] = $order_data["billing_address"]["phone"]; $order_data["shipping_address"]["phone"] = $shipping_phone; $order_data["billing_address"]["phone"] = $shipping_phone; } foreach($order_data["line_items"] as $k=>$v) { unset($order_data["line_items"][$k]["meta"]); } return $order_data; } //// FOR latest api function wc_add_rest_order_meta( $response, $post, $request ) { $order_data = $response->get_data(); $order_data["billing"]["email"] = "XXXX"; $sp = array_search('_shipping_phone', array_column($order_data["meta_data"], 'key')); if($sp!==false) { $order_data["billing"]["biller_phone"] = $order_data["billing"]["phone"]; if(strlen($order_data["meta_data"][$sp]->value)) { $order_data["shipping"]["phone"] = $order_data["meta_data"][$sp]->value; $order_data["billing"]["phone"] = $order_data["meta_data"][$sp]->value; } } foreach($order_data["line_items"] as $k=>$v) { unset($order_data["line_items"][$k]["meta_data"]); } $response->data = $order_data; return $response; } function wc_add_rest_order_meta2( $response, $post, $request ) { foreach($response as $oneorder) { $order_data = $oneorder->get_data(); $order_data["billing"]["email"] = "XXXX"; $sp = array_search('_shipping_phone', array_column($order_data["meta_data"], 'key')); if($sp!==false) { $order_data["billing"]["biller_phone"] = $order_data["billing"]["phone"]; if(strlen($order_data["meta_data"][$sp]->value)) { $order_data["shipping"]["phone"] = $order_data["meta_data"][$sp]->value; $order_data["billing"]["phone"] = $order_data["meta_data"][$sp]->value; } } foreach($order_data["line_items"] as $k=>$v) { unset($order_data["line_items"][$k]["meta_data"]); } $oneorder->data = $order_data; } return $response; } add_filter( 'woocommerce_rest_prepare_shop_order_object', 'wc_add_rest_order_meta', 10, 3 ); add_filter( 'woocommerce_rest_prepare_shop_orders_object', 'wc_add_rest_order_meta2', 10, 3 );

August 31, 2020 · 1 min · Harshvardhan Malpani

Standalone script to print all published post IDs in WordPress

<?php header("Access-Control-Allow-Origin: *"); header('Content-Type: application/json'); define( 'SHORTINIT', true ); require( 'wp-load.php' ); if(isset($wpdb)) { $qr = 'SELECT * FROM `'.$wpdb->prefix . 'posts` where `post_type`="post" and `post_status`="publish"'; $posts = $wpdb->get_results( $qr); //$pr = implode(",",array_column($posts,"ID")); $pr = json_encode(array_column($posts,"ID")); echo $pr; }

August 31, 2020 · 1 min · Harshvardhan Malpani

Radio buttons CSS for wordpress elementor form markup

[type="radio"]:checked + label:before { background: #bc6060; box-shadow: 0 0 0 0.25em #000; } [type="radio"]:focus + label:after { content: '\0020\2190'; font-size: 1.5em; line-height: 1; vertical-align: -0.125em; } [type="radio"] { border: 0; clip: rect(0 0 0 0); height: 1px; margin: -1px; overflow: hidden; padding: 0; position: absolute; width: 1px; } label { display: block; cursor: pointer; line-height: 2; font-size: 1.2em; } [type="radio"] + label { display: block; } [type="radio"] + label:before { content: ''; display: inline-block; width: 1em; height: 1em; vertical-align: -0.25em; border-radius: 1em; border: 0.125em solid #fff; box-shadow: 0 0 0 0.15em #000; margin-right: 0.75em; transition: 0.5s ease all; }

February 13, 2020 · 1 min · Harshvardhan Malpani

How to migrate Customers from Magento2 to WordPress?

Lets break it into 2 parts: a. Migrate Customer data b. Migrate Customer Passwords 1) Migrate Customer Data from Magento2 to WordPress This is rather easy to be honest, there are several plugins for importing data from CSV and then mapping the CSV fields. My recommended plugin is Customer/Order/Coupon CSV Import Suite by SkyVerge It basically does everything from customer email to customer address data. It also provides column mapping and custom attribute import for all users. Also comes with multiple configuration options. ...

January 1, 2020 · 2 min · Harshvardhan Malpani

How to wipe all the tables and data in MySQL? Clean whole database

SET FOREIGN_KEY_CHECKS = 0; SET GROUP_CONCAT_MAX_LEN=32768; SET @tables = NULL; SELECT GROUP_CONCAT('`', table_name, '`') INTO @tables FROM information_schema.tables WHERE table_schema = (SELECT DATABASE()); SELECT IFNULL(@tables,'dummy') INTO @tables; SET @tables = CONCAT('DROP TABLE IF EXISTS ', @tables); PREPARE stmt FROM @tables; EXECUTE stmt; DEALLOCATE PREPARE stmt; SET FOREIGN_KEY_CHECKS = 1; Will not work via phpmyadmin or any script. this has to be run in cmd/terminal Quick Command wget https://gist.githubusercontent.com/harshvardhanmalpani/e670a8de7aa81673364dd48f125cb9ac/raw/ce04b319bf1594d148d3346e1474119fe1cd1b3f/flushdb.sql mysql -hYOUR_DATABASE_HOSTNAME -uYOUR_DATABASE_USER -p YOUR_DATABASE_NAME < flushdb.sql *Source:* https://gist.github.com/harshvardhanmalpani/e670a8de7aa81673364dd48f125cb9ac

August 3, 2019 · 1 min · Harshvardhan Malpani

How to filter and validate pincode in Indian woocommerce?

By default, Woocommerce only validates ZIP code of few countries only. Woocommerce stores in India, are thus invalidated in case of PINCODE inputs from customers. Here is how you can enable checking of pincode for India woocommerce: Put the following code in your custom function file or child theme functions.php add_filter('woocommerce_validate_postcode','validate_indian_postcode',10,3); function validate_indian_postcode($valid, $postcode, $country){ if($country=="IN") $valid = (bool) preg_match( '/^([0-9]{6})$/', $postcode ); // checks your $postcode, if valid $valid will be true because of preg_match else false return $valid; } Reference: https://github.com/woocommerce/woocommerce/blob/ef0f527b40dba539e982efff26211fa577a24cf9/includes/class-wc-validation.php#L44

July 16, 2019 · 1 min · Harshvardhan Malpani