Skip to content

Instantly share code, notes, and snippets.

View zainaali's full-sized avatar

Zain Ali zainaali

  • Lahore Punjab, Pakistan
View GitHub Profile
// ==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 / 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' => '',
@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 / 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 / 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 / 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 / prefix.html
Last active October 15, 2018 10:20
change Phone prefix on basis of country jQuery
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<select name="select1" id="select1">
<option country-code="pk" value="Pakistan">Pakistan</option>
<option country-code="in" value="India">India</option>
<option country-code="us" value="Usa">USA</option>
<option country-code="uk" value="Uk">United Kingdom</option>
<option country-code="fr" value="France">France</option>
<option country-code="gr" value="Germny">Germny</option>
<option country-code="it" value="Italy">Italy</option>
<option country-code="ch" value="China">China</option>
@zainaali
zainaali / location.php
Last active October 13, 2018 13:52
Detect a Visitor's Country by his IP Address 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);
echo $country;
@zainaali
zainaali / api.php
Created October 7, 2018 20:20
Get lat, lng, address, and square feet from zilow api curl php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "http://www.zillow.com/webservice/GetDeepSearchResults.htm",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
@zainaali
zainaali / functions.php
Created September 28, 2018 08:22
Redirect page after order is placed based on order status Woocommerce
add_action( 'woocommerce_thankyou', 'bbloomer_redirectcustom');
function bbloomer_redirectcustom( $order_id ){
$order = new WC_Order( $order_id );
$url = 'https://siteurl/thank-you-payment/'; //Thank you page
$mem_url = 'https://siteurl/payment-denied/'; // denied page
if ( $order->status == 'pending' ) {
wp_redirect($mem_url);
}
else{