Skip to content

Instantly share code, notes, and snippets.

View zainaali's full-sized avatar

Zain Ali zainaali

  • Lahore Punjab, Pakistan
View GitHub Profile
@zainaali
zainaali / Country.php
Created October 15, 2018 10:23
Country chosen automatically according to the IP of the customer.
<?php
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];}
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
$url = "http://api.wipmania.com/".$ip;
$country = file_get_contents($url);
@zainaali
zainaali / regex.php
Created October 16, 2018 21:56
password must contain only numbers and letters with limit regex
<?php $password = 'abc';
if (!preg_match('/^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{6,12}$/', $password) ) {
$error['password_length'] = "Password must be at least 6 characters, containing at least one latter and one number";
}
@zainaali
zainaali / functions.php
Created November 7, 2018 12:14
Automate JavaScript Preloading in WordPress
add_action('wp_head', function () {
global $wp_scripts;
foreach($wp_scripts->queue as $handle) {
$script = $wp_scripts->registered[$handle];
//-- Weird way to check if script is being enqueued in the footer.
if($script->extra['group'] === 1) {
@zainaali
zainaali / functions.php
Created December 8, 2018 18:05
Prevent customers from ordering from more than 1 Vendors in Woocommerce
//Order only from 1 shop
//https://www.wcvendors.com/help/topic/restrict-clientbuyer-to-order-from-one-vendor-at-a-time/
add_filter( 'woocommerce_add_cart_item_data', 'woo_custom_add_to_cart' );
function woo_custom_add_to_cart( $cart_item_data ) {
global $woocommerce;
$items = $woocommerce->cart->get_cart(); //getting cart items
$_product = array();
foreach($items as $item => $values) {
$_product[] = $values['data']->post;
}
@zainaali
zainaali / add-wc-products-programmatically.php
Created June 18, 2019 15:26 — forked from BKeanu1989/add-wc-products-programmatically.php
adding woocommerce productgs programmatically/ via code
function insert_product ($product_data)
{
$post = array( // Set up the basic post data to insert for our product
'post_author' => 1,
'post_content' => $product_data['description'],
'post_status' => 'publish',
'post_title' => $product_data['name'],
'post_parent' => '',
// ==UserScript==
// @name Aliexpress
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://trade.aliexpress.com/orderList.htm*
// @grant unsafeWindow
// @grant GM_xmlhttpRequest
// @grant GM_setClipboard
@zainaali
zainaali / related-products-by-tag.liquid
Last active February 19, 2021 09:44
manual recommendation products tag based shopify
@zainaali
zainaali / distance.js
Created September 30, 2020 09:52
calculate distance between tow lat lon
// Passed to function: :::
//::: lat1, lon1 = Latitude and Longitude of point 1 (in decimal degrees) :::
//::: lat2, lon2 = Latitude and Longitude of point 2 (in decimal degrees) :::
//::: unit = the unit you desire for results :::
//::: where: 'M' is statute miles (default) :::
//::: 'K' is kilometers :::
//::: 'N' is nautical miles
function distance(lat1, lon1, lat2, lon2, unit) {
if ((lat1 == lat2) && (lon1 == lon2)) {
@zainaali
zainaali / functions.php
Created October 21, 2020 11:26
Create a Stripe Customer with Gravity Forms Stripe Product Feed
add_filter( 'gform_stripe_customer_id', function ( $customer_id, $feed, $entry, $form ) {
if ( rgars( $feed, 'meta/transactionType' ) == 'product' && rgars( $feed, 'meta/feedName' ) == 'Create Customer and Payment' ) {
$customer_meta = array();
$metadata_field = rgars( $feed, 'meta/metaData' );
foreach ($metadata_field as $metadata) {
if ($metadata['custom_key'] == 'Email') {
$email_field = $metadata['value'];
}
@zainaali
zainaali / custom.js
Last active February 19, 2021 09:43
Hide header on specific slide of Revolution Slider
<script>
var revapi = jQuery(document).ready(function() {
jQuery('#rev_slider_2_3').show().revolution({
waitForInit: true,
/* SLIDER SETTINGS CONTINUED */
});
});
// only start the slider once the entire window has loaded
revapi.on('revolution.slide.onchange', function(event, data) {
var get_id1 = data.currentslide[0]['id'];