Skip to content

Instantly share code, notes, and snippets.

@pareshsojitra
pareshsojitra / functions.php
Created February 2, 2021 12:12 — forked from EvanHerman/functions.php
Localize the jquery datepicker in WordPress using the WP_Locale object
<?php
add_action( 'admin_enqueue_scripts', 'admin_print_js' );
public function admin_print_js() {
global $wp_locale;
//add the jQuery UI elements shipped with WP
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'jquery-ui-datepicker' );
@pareshsojitra
pareshsojitra / woo-checkout.php
Created February 2, 2021 14:35 — forked from Bobz-zg/woo-checkout.php
Pre-populate Woocommerce checkout fields
<?php
/**
* Pre-populate Woocommerce checkout fields
* Note that this filter populates shipping_ and billing_ fields with a different meta field eg 'first_name'
*/
add_filter('woocommerce_checkout_get_value', function($input, $key ) {
global $current_user;
switch ($key) :
@pareshsojitra
pareshsojitra / functions.php
Created February 2, 2021 14:35 — forked from zainaali/functions.php
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'),
var searchBox = new google.maps.places.SearchBox(document.getElementById('searchinput'));
google.maps.event.addListener(searchBox, 'places_changed', function() {
var place = searchBox.getPlaces()[0];
if (!place.geometry) return;
if (place.geometry.viewport) {
map.fitBounds(place.geometry.viewport);
} else {
@pareshsojitra
pareshsojitra / disable-plugins-when-doing-local-dev.php
Created February 7, 2021 14:58 — forked from hansschuijff/disable-plugins-when-doing-local-dev.php
Disables specified WordPress plugins when doing local development
<?php
/*
Plugin Name: Disable plugins when doing local dev
Description: If the WP_LOCAL_DEV constant is true, disables plugins that you specify
Version: 0.1
License: GPL version 2 or any later version
Author: Mark Jaquith
Author URI: http://coveredwebservices.com/
*/
<?php
/**
* Plugin Name: YOUR PLUGIN NAME
*/
include( dirname( __FILE__ ) . '/lib/requirements-check.php' );
$your_plugin_requirements_check = new YOUR_PREFIX_Requirements_Check( array(
'title' => 'YOUR PLUGIN NAME',
'php' => '5.4',
@pareshsojitra
pareshsojitra / home-page-redirect.php
Created February 7, 2021 15:00 — forked from markjaquith/home-page-redirect.php
If user is logged in, and on the front page, redirect to /?firstName=FIRST&lastName=LAST
<?php
function home_page_first_last_name_redirect() {
if ( is_front_page() && is_user_logged_in() && ! isset( $_GET['firstName'] ) ) {
$user = wp_get_current_user();
$url = add_query_arg( array(
'firstName' => $user->first_name,
'lastName' => $user->last_name,
));
wp_redirect( $url );
@pareshsojitra
pareshsojitra / wp-update-plugins-git.sh
Created February 7, 2021 15:01 — forked from markjaquith/wp-update-plugins-git.sh
Update all WordPress plugins using WP-CLI and make a separate git commit for each one
#!/bin/bash
PLUGINS=$(wp plugin list --update=available --field=name | tr -d '\r');
wp plugin update-all;
for plugin in $PLUGINS; do
git add -A "wp-content/plugins/$plugin";
git commit -m "Update plugin: $plugin";
done;
@pareshsojitra
pareshsojitra / detect-device.php
Created February 7, 2021 15:01 — forked from squarestar/detect-device.php
Detect Mobile Browser
<?php
/**
* Based on this: http://detectmobilebrowsers.com/
*/
$isMobile = false;
$useragent = filter_input(INPUT_SERVER, 'HTTP_USER_AGENT');
if(preg_match('/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i',$useragent)||preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|