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 / calculator.html
Last active December 19, 2017 07:31
Angular Js Pool water calculator
<!DOCTYPE html>
<html>
<!-- CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<!-- JS -->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.3/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.3/angular-animate.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.3/angular-messages.js"></script>
<!--
@zainaali
zainaali / functions.php
Created December 21, 2017 15:24
wp_nav_menu change sub-menu class name
<?php
function new_submenu_class($menu) {
$menu = preg_replace('/ class="sub-menu"/','/ class="yourclass" /',$menu);
return $menu;
}
add_filter('wp_nav_menu','new_submenu_class');
?>
@zainaali
zainaali / links.php
Created January 18, 2018 17:25
find links in a string and replace them with actual html link tags
@zainaali
zainaali / country.js
Last active February 21, 2018 07:42
Extract country from google autocomplete address api
autocomplete.addListener('place_changed', function() {
var place = autocomplete.getPlace();
//Extract country from autocomplete address api
var country;
for(var c = 0; c < place.address_components.length; c += 1) {
var locality = place.address_components[c];
for(var d = 0; d < locality.types.length; d += 1) {
if (locality.types[d] === 'country') {
country = locality.long_name; // confirm that this is the country name
}
@zainaali
zainaali / city.js
Last active February 21, 2018 07:41
Extract city from google autocomplete address api
autocomplete.addListener('place_changed', function() {
var place = autocomplete.getPlace();
//Extract city from autocomplete address api
var city;
for(var a = 0; a < place.address_components.length; a += 1) {
var addressObj = place.address_components[a];
for(var b = 0; b < addressObj.types.length; b += 1) {
if (addressObj.types[b] === 'locality') {
city = addressObj.long_name; // confirm that this is the country name
//console.log(addressObj.long_name); // confirm that this is the country name
@zainaali
zainaali / area.php
Created February 21, 2018 08:01
Calculating area of a polygon drawn on google map
<div class="controls">
<div class="span1 four"><a id="editPoly" class="tracing-control active" title="This is the drawing/tracing tool. Work with this tool to create your outlines."><i class="fa fa-lg fa-pencil icon-pencil icon-large"></i><br>Trace</a></div>
<div class="span1 four"><a id="moveMap" class="tracing-control" title="Click here to move the map. Or click and drag when in Tracing mode."><i class="fa fa-lg fa-arrows icon-move icon-large"></i><br>Edit</a></div>
<div class="span1 four"> <a id="undoDrawing" class="tracing-control" title="Did your tracing not turn out? Click here to undo your last outline."><i class="fa fa-lg fa-undo icon-undo icon-large"></i><br>Undo</a>
</div>
</div>
<?php $yard_size = $_POST['yard_size'];?>
<input type="hidden" name="yard_size" id="yard_size" value="<?php $yard_size?>">
<div id="map" style="display: block; width: 100%; height: 500px;"></div>
@zainaali
zainaali / scroll.js
Last active February 22, 2018 21:07
Make sidebar scroll able along with page and stop at footer
(function($) {
//id of sidebar
var element = $('#sidebar')
originalY = $(element).offset().top;
// Space between element and top of screen (when scrolling)
var topMargin = 20;
// Should probably be set in CSS; but here just for emphasis
element.css('position', 'relative');
$(window).on('scroll', function(event) {
@zainaali
zainaali / scroll.js
Created February 22, 2018 20:48
Make scrolling sidebar along with page and stop at footer
(function($) {
//id of sidebar
var element = $('#sidebar')
originalY = $(element).offset().top;
// Space between element and top of screen (when scrolling)
var topMargin = 20;
// Should probably be set in CSS; but here just for emphasis
element.css('position', 'relative');
$(window).on('scroll', function(event) {
@zainaali
zainaali / functions.php
Last active April 15, 2019 18:47
WooCommerce: Allow adding multiple products and set price to the cart via the add-to-cart query string
application/x-httpd-php functions.php ( PHP script, ASCII text )
<?php
/**
*
* 1. Bond Only - Expedia, Direct, HomeAway
* https://readysethost.co/checkout/?add-to-cart=772:1:2.00&rcode=TST2&fname=Mike&lname=Aubor&email=damiike%40gmail.com
* 2. Booking Only - Booking.com, Direct, HomeAway
* https://readysethost.co/checkout/?add-to-cart=1334:1:1.00&rcode=TST2&fname=Mike&lname=Aubor&email=damiike%40gmail.com
* 3. Booking Deposit Only - Direct, HomeAway
@zainaali
zainaali / functions.php
Created September 22, 2018 11:32
Create Custom Billing Field and pre fill Auto fill checkout default filed and custom filed from user data saved in Woocommerce session
/**
* C.1. Custom Billing Field
*/
add_filter( 'woocommerce_billing_fields' , 'wc_custom_fields' );
function wc_custom_fields( $fields ) {
$fields['billing_reservationcode'] = array(
'type' => 'text',
'required' => true,
'class' => array('reservationcode'),