Skip to content

Instantly share code, notes, and snippets.

View nfmohit's full-sized avatar

Nahid F Mohit nfmohit

View GitHub Profile
@nfmohit
nfmohit / wpmudevcurltest.php
Last active October 21, 2017 05:09
WPMU DEV cURL Test
<?php
if (isDEVAvailible('http://premium.wpmudev.org'))
{
echo "<h1>premium.wpmudev.org is Up and running!</h1>";
}
else
{
echo "<h1>Woops, nothing found at premium.wpmudev.org.</h1>";
}
@nfmohit
nfmohit / optionalcheckoutfields.php
Last active October 21, 2017 05:08
Making Woocommerce checkout fields optional
<?php
add_filter( 'woocommerce_default_address_fields' , 'custom_override_default_address_fields' );
function custom_override_default_address_fields( $address_fields ) {
$address_fields['address_1']['required'] = false;
$address_fields['address_2']['required'] = false;
$address_fields['postcode']['required'] = false;
$address_fields['state']['required'] = false;
$address_fields['city']['required'] = false;
$address_fields['country']['required'] = false;
@nfmohit
nfmohit / woocustomthankyou.php
Last active October 21, 2017 05:07
Woocommerce redirect users to custom Thank You page
<?php
add_action( 'woocommerce_thankyou', 'bbloomer_redirectcustom');
function bbloomer_redirectcustom( $order_id ){
$order = new WC_Order( $order_id );
$url = 'http://yoursite.com/custom-url';
if ( $order->status != 'failed' ) {
wp_redirect($url);
@nfmohit
nfmohit / woosalesloop.php
Last active October 21, 2017 05:07
Show Woocommerce Sales Amount after Each Product in the Loop
<?php
add_action( 'woocommerce_after_shop_loop_item', 'wc_product_sold_count', 11 );
function wc_product_sold_count() {
global $product;
$units_sold = get_post_meta( $product->id, 'total_sales', true );
echo '<p>' . sprintf( __( 'Units Sold: %s', 'woocommerce' ), $units_sold ) . '</p>';
}
@nfmohit
nfmohit / prositestyles.css
Created October 21, 2017 05:05
Styling Pro Sites Pricing Tables according to Demo
#prosites-checkout-table .period-selector-container {
width: 100% !important;
text-align: center;
}
.period-selector-container label > input + .period-option {
padding: 9px;
height: 3em;
font-size: 14px
}
#prosites-checkout-table .pricing-column .title {
@nfmohit
nfmohit / prosite-default-period.php
Created November 12, 2017 03:35
Makes the 'Annual' period default in Pro Sites
<?php
function defaultPrositePeriod() {
?>
<script type="text/javascript">
jQuery( document ).ready( function( $ ) {
$('#prosites-checkout-table .period-selector-container input[checked="checked"]').prop('checked', false);
$('#prosites-checkout-table .period-selector-container input[value="price_12"]').prop('checked', true);
$('#prosites-checkout-table .summary .price_3').css('display', 'none');
$('#prosites-checkout-table .summary .price_1').css('display', 'none');
$('#prosites-checkout-table .summary .price_12').css('display', 'block')
@nfmohit
nfmohit / restricted-page-redirect.php
Last active November 22, 2017 04:59
Redirect to a desired page if the user is not logged in and trying to access a specific page(s)
<?php
function intranet_loggedout_redirect()
{
if( is_page( 'intranet' ) && ! is_user_logged_in() )
{
wp_redirect( home_url( '/community/' ) );
die;
}
}
add_action( 'template_redirect', 'intranet_loggedout_redirect' );
@nfmohit
nfmohit / woo3cols.php
Last active November 22, 2017 04:58
Make Woocommerce product grid into 3 columns with CSS
<?php
add_action('wp_head', 'woo3cols');
function woo3cols() {
echo '<style>.woocommerce ul.products li.product {clear: none !important;width: 32% !important;float: none !important;display: inline-block;vertical-align: top;}</style>';
}
@nfmohit
nfmohit / google-map.php
Last active November 22, 2017 06:16
Upload this file to wp-content/mu-plugins (Create a 'mu-plugins' directory if its not there already)
<?php
function dermoesteticamiori_gmaps() {
wp_enqueue_script( 'googlemaps_js', 'http://www.dermoesteticamiori.it/vip/wp-content/uploads/google-map.js');
}
add_action( 'wp_enqueue_scripts', 'dermoesteticamiori_gmaps' );
@nfmohit
nfmohit / google-map.js
Last active November 22, 2017 06:07
Upload this file to wp-content/uploads
(function($) {
$(document).ready(function(){
var marker;
var image = 'images/map-marker.png';
function initMap() {
var myLatLng = {lat: 39.79, lng: -86.14};
// Specify features and elements to define styles.
var styleArray = [
{"featureType":"all","elementType":"labels.text.fill","stylers":[{"saturation":36},{"color":"#000000"},{"lightness":40}]},{"featureType":"all","elementType":"labels.text.stroke","stylers":[{"visibility":"on"},{"color":"#000000"},{"lightness":16}]},{"featureType":"all","elementType":"labels.icon","stylers":[{"visibility":"off"}]},{"featureType":"administrative","elementType":"geometry.fill","stylers":[{"color":"#000000"},{"lightness":20}]},{"featureType":"administrative","elementType":"geometry.stroke","stylers":[{"color":"#000000"},{"lightness":17},{"weight":1.2}]},{"featureType":"landscape","elementType":"geometry","stylers":[{"color":"#000000"},{"lightness":20}]},{"featureType":"poi","elementType":"geometry","stylers":[{"color":"#000000"},{"lightness":21}]},