Skip to content

Instantly share code, notes, and snippets.

View aslamdoctor's full-sized avatar
💭
Always working but happy to talk 👍

Aslam Doctor aslamdoctor

💭
Always working but happy to talk 👍
View GitHub Profile
@aslamdoctor
aslamdoctor / steps.md
Created May 4, 2024 14:35
Switch PHP version on Mac using Brew
  1. Check if grep is installed

grep --version

If it returns below

grep (BSD grep, GNU compatible) 2.6.0-FreeBSD

  1. Then install it using brew
@aslamdoctor
aslamdoctor / woocommerce-delete-failed-orders.sql
Last active April 16, 2024 00:40
WooCommerce : Delete all failed orders
-- Below queries are just to check the failed order records:
SELECT * FROM `wp_woocommerce_order_itemmeta` WHERE order_item_id IN (SELECT order_item_id FROM `wp_woocommerce_order_items` WHERE order_id IN (SELECT ID FROM wp_posts WHERE post_type = 'shop_order' AND post_status='wc-failed'))
SELECT * FROM `wp_woocommerce_order_items` WHERE order_id IN (SELECT ID FROM wp_posts WHERE post_type = 'shop_order' AND post_status='wc-failed')
SELECT * FROM wp_comments WHERE comment_type = 'order_note' AND comment_post_ID IN(SELECT ID FROM wp_posts WHERE post_type = 'shop_order' AND post_status='wc-failed')
SELECT * FROM wp_postmeta WHERE post_id IN ( SELECT ID FROM wp_posts WHERE post_type = 'shop_order' AND post_status='wc-failed')
@aslamdoctor
aslamdoctor / fix-mobile-nav-height.js
Created April 5, 2024 20:33
Fix 100vh issue on mobile
// First we get the viewport height and we multiple it by 1% to get a value for a vh unit
let vh = window.innerHeight * 0.01;
// Then we set the value in the --vh custom property to the root of the document
document.documentElement.style.setProperty('--vh', `${vh}px`);
// We listen to the resize event
window.addEventListener('resize', () => {
// We execute the same script as before
let vh = window.innerHeight * 0.01;
document.documentElement.style.setProperty('--vh', `${vh}px`);
@aslamdoctor
aslamdoctor / cookieHelper.js
Created February 20, 2024 16:30
Javascript Cookie Helper
// Cookie helper functions
const CookieHelper = {
/**
* Set Cookie.
*
* @param {string} name
* @param {string} value
* @param {string} minutes
*/
setCookie( name, value, minutes ) {
@aslamdoctor
aslamdoctor / acrylic hosts.txt
Created May 4, 2020 14:25
Acrylic Hosts File Configuration
Acrylic DNS Proxy (free, open source) does the job. It creates a proxy DNS server (on your own computer) with its own hosts file. The hosts file accepts wildcards.
Download from the offical website
http://mayakron.altervista.org/support/browse.php?path=Acrylic&name=Home
Configuring Acrylic DNS Proxy
To configure Acrylic DNS Proxy, install it from the above link then go to:
Start
@aslamdoctor
aslamdoctor / wsl-lamp.md
Last active December 7, 2023 13:46
Windows 10 - WSL LAMP Stack Setup
@aslamdoctor
aslamdoctor / wp-ajax-loadmore.md
Last active November 22, 2023 00:41
Wordpress - AJAX Load More Steps

Step 1. Load more button

<?php
global $wp_query; // you can remove this line if everything works for you
 
// don't display the button if there are not enough posts
if (  $wp_query->max_num_pages > 1 )
	echo '<div class="misha_loadmore">More posts</div>'; // you can use <a> as well
?>
@aslamdoctor
aslamdoctor / wordpress-navwalker.php
Last active July 24, 2023 15:12
Snippet: Nav walker class in WordPress
<?php
class Topmenu_Walker extends Walker_Nav_Menu {
// Displays start of an element. E.g '<li> Item Name'
function start_el(&$output, $item, $depth=0, $args=array(), $id = 0) {
$object = $item->object;
$type = $item->type;
$title = $item->title;
$description = $item->description;
$permalink = $item->url;
@aslamdoctor
aslamdoctor / wordpress-cf7-mail-tag.php
Created January 5, 2022 10:43
Snippet : Add dynamic data to Contact form 7 email
<?php
add_filter('wpcf7_special_mail_tags', 'add_prospectus_link_to_email', 10, 3);
function add_prospectus_link_to_email($output, $name, $html)
{
$name = preg_replace('/^wpcf7\./', '_', $name); // for back-compat
if ('prospectus' == $name) {
$prospectus = get_field('prospectus', 'options');
return $prospectus['url'];
}
@aslamdoctor
aslamdoctor / woocommerce-search-brands.php
Created February 25, 2021 14:48
Woocommerce : Search into Brands
<?php
//========== Filter Search result ==========
function amd_search_filter($query) {
if(is_admin()) return $query;
if ($query->is_search() && !empty($_GET['s']) ) {
add_filter( 'posts_where', 'amd_brands_where' );
}