Skip to content

Instantly share code, notes, and snippets.

View alokstha1's full-sized avatar

Alok Shrestha alokstha1

View GitHub Profile
@alokstha1
alokstha1 / script.js
Created August 2, 2017 11:44
Compare two dates in jquery
function myStringToDate(str) {
var arr = str.split("-"); // split string at slashes to make an array
var yyyy = arr[2] - 0; // subtraction converts a string to a number
var jsmm = arr[1] - 1; // subtract 1 because stupid JavaScript month numbering
var dd = arr[0] - 0; // subtraction converts a string to a number
return new Date(yyyy, jsmm, dd); // this gets you your date
}
var from_date = myStringToDate(jQuery('#from-date').val());
@alokstha1
alokstha1 / functions.php
Last active July 18, 2017 07:54
Woocommerce hook after checkout
<?php
add_action( 'woocommerce_thankyou', 'woo_after_checkout', 10, 1 );
function woo_after_checkout( $order_id ) {
$order_detail = new WC_Order( $order_id );
$order_detail->get_billing_email();
$order_detail->get_billing_first_name();
$order_detail->get_billing_last_name();
$order_detail->get_billing_company();
foreach ( $order_detail->get_items() as $item_id => $item ) {
$product = $item->get_product();
@alokstha1
alokstha1 / Sql.txt
Last active May 10, 2017 08:53
Update sql after site transfer
UPDATE wp_options SET option_value = replace(option_value, 'http://live.com', 'http://localhost/example') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'http://live.com','http://localhost/example');
UPDATE wp_posts SET post_content = replace(post_content, 'http://live.com', 'http://localhost/example');
@alokstha1
alokstha1 / functions.php
Created May 1, 2017 05:59
Defer Parsing of Javascript
<?php
function cpm_defer_parsing_of_js ( $url ) {
if ( FALSE === strpos( $url, '.js' ) ) return $url;
if ( strpos( $url, 'jquery.js' ) ) return $url;
return "$url' defer='defer";
}
add_filter( 'clean_url', 'cpm_defer_parsing_of_js', 11, 1 );
@alokstha1
alokstha1 / functions.php
Created March 10, 2017 04:26
Remove Filters of class files with out invoking class.
<?php
function remove_class_filter( $tag, $class_name = '', $method_name = '', $priority = 10 ) {
global $wp_filter;
// Check that filter actually exists first
if ( ! isset( $wp_filter[ $tag ] ) ) return FALSE;
if ( is_object( $wp_filter[ $tag ] ) && isset( $wp_filter[ $tag ]->callbacks ) ) {
// Create $fob object from filter tag, to use below
$fob = $wp_filter[ $tag ];
$callbacks = &$wp_filter[ $tag ]->callbacks;
} else {
@alokstha1
alokstha1 / functions.php
Last active December 14, 2016 10:31
Embed Vimeo video customization
<?php
function my_oembed_fetch_url( $provider, $url, $args ) {
if ( strpos( $provider, 'vimeo.com' ) !== false) {
if ( isset( $args['autoplay'] ) ) {
$provider = add_query_arg( 'autoplay', absint( $args['autoplay'] ), $provider );
@alokstha1
alokstha1 / functions.php
Created December 1, 2016 05:47
Set post featured thumbnail
<?php
$upload_dir = wp_upload_dir();
$image_data = file_get_contents($image_url);
$filename = basename($image_url);
if(wp_mkdir_p($upload_dir['path'])) $file = $upload_dir['path'] . '/' . $filename;
else $file = $upload_dir['basedir'] . '/' . $filename;
file_put_contents($file, $image_data);
$wp_filetype = wp_check_filetype($filename, null );
@alokstha1
alokstha1 / template.php
Created November 16, 2016 10:46
Numeric pagination
<?php
echo paginate_links( array(
'base' => @add_query_arg('paged','%#%'),
'format' => '?paged=%#%',
'current' => (get_query_var('paged')) ? get_query_var('paged') : 1,
'mid-size' => 1,
'total' => $cat_posts->max_num_pages
) );
@alokstha1
alokstha1 / Terminal
Created September 23, 2016 07:48
Sublime Text-installer
Firstly install Sublime -text Installer
sudo apt-get purge sublime-text-installer
Than
sudo dpkg -i sublime-text_build-3124_amd64.deb
@alokstha1
alokstha1 / Script.js
Created September 23, 2016 07:46
Fixed sidebar with respect to header and footer
// SCRIPT FOR PRODUCT SIDEBAR STICKY (EXPANDABLE)
function collision($div1, $div2) {
if ( $div1.length > 0 && $div2.length > 0 ) {
var x1 = $div1.offset().left;
var y1 = $div1.offset().top;
var h1 = $div1.outerHeight(true);
var w1 = $div1.outerWidth(true);
var b1 = y1 + h1;
var r1 = x1 + w1;
var x2 = $div2.offset().left;