Skip to content

Instantly share code, notes, and snippets.

View imvarunkmr's full-sized avatar

Varun Kumar imvarunkmr

View GitHub Profile
@imvarunkmr
imvarunkmr / gist:500a4600a9b773da0abe
Created May 11, 2015 14:03
Woocommerce: Change text of order button
// Change Order Button Text on checkout page
add_filter( 'woocommerce_order_button_text', create_function( '', 'return "Create Request";' ) );
@imvarunkmr
imvarunkmr / gist:82d2904ee40cfa554340
Last active August 29, 2015 14:21
Woocommerce: Get product categories
<?php
$product_categories = get_terms('product_cat');
foreach ($product_categories as $product_cat) {
echo $product_cat->name;
}
?>
@imvarunkmr
imvarunkmr / wooprodcatimg.php
Last active August 29, 2015 14:21
Woocommerce: Get product category images
$thumbnail_id = get_woocommerce_term_meta( $product_cat->term_id, 'thumbnail_id', true );
// get the image thumbnail for any size
$image = wp_get_attachment_image_src( $thumbnail_id, 'small' );
echo '<img src = "' . $image[0] . '" />';
@imvarunkmr
imvarunkmr / wp-query-ref.php
Created February 28, 2016 06:24 — forked from luetkemj/wp-query-ref.php
WP: Query $args
<?php
/**
* WordPress Query Comprehensive Reference
* Compiled by luetkemj - luetkemj.com
*
* CODEX: http://codex.wordpress.org/Class_Reference/WP_Query#Parameters
* Source: https://core.trac.wordpress.org/browser/tags/3.9/src/wp-includes/query.php
*/
$args = array(
<?php
// Using init action hook to register post type on loading
add_action( 'init', 'slug_book_init');
/**
* Register a book post type
*/
function slug_book_init() {
$labels = array(
'name' => _x( 'Books', 'post type general name', 'textdomain' ),
'singular_name' => _x( 'Book', 'post type singular name', 'textdomain' ),
<?php
add_action( 'wp_enqueue_scripts', 'slug_add_scripts' );
/**
* Register and enqueue scripts and styles.
*/
function slug_add_scripts() {
// enqueuing a stylesheet
// params - $handle, $src, $deps, $version, $media
@imvarunkmr
imvarunkmr / wp-ajax_handlers.php
Last active April 2, 2017 15:45
Ajax handlers for WordPress
<?php
add_action( 'wp_ajax_action_slug', 'action_slug' );
add_action( 'wp_ajax_nopriv_action_slug', 'action_slug' );
function action_slug() {
check_ajax_referer('form_nonce');
$errors = array(); // Array to hold validation errors
$data = array(); // Array to pass back data
@imvarunkmr
imvarunkmr / js-ajax_form_submission.js
Last active April 2, 2017 14:10
Processing an ajax form using jQuery
$('form').submit(function(e) {
// get the form data
formData = $(this).serialize();
formData += '&action=submit_contact_form';
// process the form
$.ajax({
type : 'post',
url : localData.ajax_url,
@imvarunkmr
imvarunkmr / wp-custom_taxonomies.php
Last active April 29, 2017 11:06
Registering a custom taxonomy
<?php
/**
* Add custom taxonomy for project services
*/
add_action( 'init', 'services', 0);
function services() {
$labels = array(
'name' => _x( 'Services', 'taxonomy general name', 'textdomain' ),
'singular_name' => _x( 'Service', 'taxonomy singular name', 'textdomain' ),
## ENABLE GZIP COMPRESSION ##
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript