Skip to content

Instantly share code, notes, and snippets.

View navnit-viradiya's full-sized avatar

Navnit Viradiya navnit-viradiya

View GitHub Profile
@navnit-viradiya
navnit-viradiya / functions.php
Created April 30, 2019 10:43
WooCommerce - Add a special field to the checkout, order emails and user/order meta or Load specific custom fields on change country.
<?php
add_action('woocommerce_review_order_before_payment', 'gst_checkout_field');
function gst_checkout_field( $checkout ) {
echo '<div id="gst_checkout_field_sec">';
woocommerce_form_field( 'gst_no', array(
'type' => 'text',
'class' => array('my-field-class orm-row-wide'),
'label' => __('GST No'),
@navnit-viradiya
navnit-viradiya / functions.php
Created April 16, 2019 07:44
Get the right prev/next post link when order posts by menu_order
<?php
function my_previous_post_where() {
global $post, $wpdb;
return $wpdb->prepare( "WHERE p.menu_order < %s AND p.post_type = %s AND p.post_status = 'publish'", $post->menu_order, $post->post_type);
}
add_filter( 'get_previous_post_where', 'my_previous_post_where' );
function my_next_post_where() {
global $post, $wpdb;
return $wpdb->prepare( "WHERE p.menu_order > %s AND p.post_type = %s AND p.post_status = 'publish'", $post->menu_order, $post->post_type);
@navnit-viradiya
navnit-viradiya / wp-query-with-meta-query-and-taxonomy.php
Created September 27, 2018 10:23
WooCommerce search products between price range using WP_Query
<?php
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => -1,
'tax_query' => array(
'relation' => 'AND',
array (
'taxonomy' => 'product_cat',
'field' => 'slug',
@navnit-viradiya
navnit-viradiya / wp-query-with-custom taxonomy.php
Created September 27, 2018 08:07
Wp_query with a custom taxonomy.
<?php
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => -1,
'tax_query' => array(
'relation' => 'AND',
array (
'taxonomy' => 'product_cat',
'field' => 'slug',
@navnit-viradiya
navnit-viradiya / wp-query-with-meta-query.php
Created September 27, 2018 07:56
Wp_query example for meta query with multiple meta field.
<?php
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => -1,
/*'meta_key' => 'ingredients',
'meta_value' => ' ',
'meta_compare' => '!='*/
'meta_query' => array(
'relation' => 'AND',
@navnit-viradiya
navnit-viradiya / faq-example.html
Created September 7, 2018 13:04
FAQ Page with Show and Hide Questions and Answers. Showing First Question Answer on Page Load.
<!DOCTYPE html>
<html>
<head>
<title>faq</title>
<style>
/*FAQS*/
.faq_question {
@navnit-viradiya
navnit-viradiya / character-limit.php
Created August 30, 2018 11:28
Set character limit on get_the_content() or get_the_excerpt() in wordpress
<?php
function break_content($text,$length){
$text = trim($text);
if(strlen($text)<$length+10)
return $text;//don't cut if too short
$break_pos = strpos($text, ' ', $length);//find next space after desired length
$visible = substr($text, 0, $break_pos);
<?php
//Show post category wise shortcode [show_post_category_wise]
add_shortcode('show_post_category_wise','show_post_category_wise_shortcode');
function show_post_category_wise_shortcode(){
$terms = get_terms('category');
$html = '';
if($terms) {
foreach($terms as $term){
@navnit-viradiya
navnit-viradiya / show-category-wise-posts-shortcode.php
Created August 28, 2018 12:57
Show category wise posts for custom post type in wordpress
<?php
//Show post category wise shortcode [show_post_category_wise]
add_shortcode('show_post_category_wise','show_post_category_wise_shortcode');
function show_post_category_wise_shortcode(){
$terms = get_terms('technology');
$html = '';
if($terms) {
foreach($terms as $term){
@navnit-viradiya
navnit-viradiya / countries.js
Created August 21, 2018 08:16
List of Countries with Phone Code as a jQuery Array
var countries = {
"297" : {
"countryName": "Aruba",
"code": "AW",
"phoneCode": "297"
},
"93" : {
"countryName": "Afghanistan",
"code": "AF",
"phoneCode": "93"