Skip to content

Instantly share code, notes, and snippets.

View AchalJ's full-sized avatar

Achal Jain AchalJ

View GitHub Profile
@AchalJ
AchalJ / htaccess
Created July 8, 2015 08:41
Redirect HTTP to HTTPS
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
@AchalJ
AchalJ / wc_sort_by_stock
Created July 8, 2015 08:43
WooCommerce custom function for Sort by Stock
// Sort by stock on front end
add_filter( 'woocommerce_get_catalog_ordering_args', 'custom_woocommerce_get_catalog_ordering_args' );
function custom_woocommerce_get_catalog_ordering_args( $args ) {
$orderby_value = isset( $_GET['orderby'] ) ? woocommerce_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
if ( 'stock' == $orderby_value ) {
$args['orderby'] = 'meta_value';
$args['order'] = 'asc';
$args['meta_key'] = '_stock_status';
}
@AchalJ
AchalJ / author_box
Created July 8, 2015 08:45
Custom Author Box (used with user photo plugin)
add_filter('genesis_author_box', 'custom_author_box');
function custom_author_box() {
if(is_single()) :
?>
<div id="dynamic-below" class="dynamic-wrapper"><span class="screen-reader-text">The following two tabs change content below.</span><ul class="dynamic-list"><li class="dynamic-bio-link active"><a href="#dynamic-bio-below">Bio</a></li><li class="dynamic-latest-posts-link"><a href="#dynamic-latest-posts-below">Latest Posts</a></li></ul>
<div class="dynamic-tabs">
<div class="author-box dynamic-tab" id="dynamic-bio-below">
<div class="dynamic-avatar">
<?php
userphoto_the_author_photo(
@AchalJ
AchalJ / javascript
Created July 8, 2015 08:47
Responsive Navigation (Mobile Menu) - Slide
jQuery(document).ready(function($){
var isDevice = /Mobile|webOs|iPad|IEMobile|Windows Phone/.test(navigator.userAgent);
if (isDevice) {
jQuery('.mobile-menu-button').unbind('click').toggle(function (){
jQuery('.responsive-menu').show().animate({right:'0'},300);
jQuery('.ib-overlay').css('display','block');
jQuery('body').css('overflow','hidden');
}, function (){
jQuery('.responsive-menu').animate({right:'-260px'},300);
jQuery('.ib-overlay').hide();
@AchalJ
AchalJ / add-to-cart.php
Created July 9, 2015 07:10
WooCommerce Custom Add To Cart
<?php
/**
* Custom Loop Add to Cart.
*
* Template with quantity and ajax.
*/
if (!defined('ABSPATH'))
exit; // Exit if accessed directly.
global $product;
@AchalJ
AchalJ / javascript.js
Created July 9, 2015 07:15
WooCommerce Custom Input Quantity
jQuery(document).ready(function($){
$('.cart input[type="number"]').on('change', function(){
$(this).parent().parent().find('button[data-quantity]').attr('data-quantity', parseInt($(this).val()));
});
jQuery.fn.disableSelection = function() {
return this
.attr('unselectable', 'on')
.css('user-select', 'none')
.on('selectstart', false);
@AchalJ
AchalJ / code.php
Created July 14, 2015 11:04
WooCommerce: Change Out of Stock text
add_filter( 'woocommerce_get_availability', 'wcs_custom_get_availability', 1, 2);
function wcs_custom_get_availability( $availability, $_product ) {
// Change Out of Stock Text
if ( ! $_product->is_in_stock() ) {
$availability['availability'] = __('Currently Unavailable', 'woocommerce');
}
return $availability;
@AchalJ
AchalJ / code.php
Created July 16, 2015 05:38
WooCommerce: Hide Out of Stock products from a category
/* Term ID - 10 */
add_filter( 'pre_get_posts', 'hide_out_of_stock_from_cat' );
function hide_out_of_stock_from_cat( $query ) {
if ( $query->is_tax( 'product_cat', 10 ) && $query->is_main_query() ) {
$query->set( 'meta_query', array(array(
'key' => '_stock_status',
'value' => 'outofstock',
'compare' => 'NOT IN'
)));
@AchalJ
AchalJ / CSS.css
Created June 12, 2018 16:10
Content Grid - Custom Layout preset
.pp-content-grid-post {
font-size: 14px;
}
.pp-content-grid-post-image {
padding: 0;
position: relative;
}
.pp-content-grid-post-image a img {
filter: saturate(1.6) contrast(1.1);
opacity: 1;
@AchalJ
AchalJ / getSubHtml.js
Created March 31, 2020 12:19
jQuery extension to get sub HTML of a node
jQuery.fn.getSubHtml = function( startHtml, endHtml, node ) {
var $this = jQuery(this);
var $html = $this.html();
startHtml = startHtml.replace( /<\//g, '<\\/' ).trim();
endHtml = endHtml.replace( /<\//g, '<\\/' ).trim();
var startHtmlRegEx = new RegExp( startHtml );
var endHtmlRegEx = new RegExp( endHtml );