Skip to content

Instantly share code, notes, and snippets.

View AchalJ's full-sized avatar

Achal Jain AchalJ

View GitHub Profile
@AchalJ
AchalJ / code.js
Created April 13, 2022 06:46
PowerPack Category Post Count animation on reveal
$(window).on('scroll.pp-animate', function() {
var scrollTop = $(window).scrollTop(),
winHeight = $(window).height(),
triggerpoint = winHeight * .8 + scrollTop;
// If module has animation, otherwise remove .fl-animated class here.
$('.animate-post-count.fl-animated .pp-category-count').each(function() {
if ( $(this).hasClass( 'revealed' ) ) {
return;
}
var counterElement = $(this).offset().top;
@AchalJ
AchalJ / code.js
Created March 28, 2022 05:40
WooPack Products Grid layout fix in PowerPack's Modal Box
(function($) {
$(document).on('pp_modal_box_rendered', function(e, $scope) {
if ( $scope.find( '.woopack-products-grid-wrap' ).length > 0 ) {
$scope.find( '.woopack-products-grid-wrap' ).each(function() {
var nodeId = $(this).closest('.fl-module').attr('data-node');
if ( 'undefined' !== typeof window['woopack_' + nodeId] ) {
var obj = window['woopack_' + nodeId];
if ( ! obj.masonry ) {
obj._gridLayoutMatchHeight();
}
@AchalJ
AchalJ / shortcode.php
Created March 25, 2022 16:43
Auto-reset Countdown Timer shortcode
/**
* How to use: [my_custom_timer id="my-timer" time="300" placeholder="00:00"]
*/
add_shortcode( 'my_custom_timer', function( $attrs ) {
// id attribute for the timer HTML.
$id = isset( $attrs['id'] ) && ! empty( $attrs['id'] ) ? $attrs['id'] : 'my-timer';
// set the time to start countdown (in seconds).
$time = isset( $attrs['time'] ) && ! empty( $attrs['time'] ) ? intval( $attrs['time'] ) : 120;
// default placeholder to appear on load
$placeholder = isset( $attrs['placeholder'] ) ? $attrs['placeholder'] : '';
@AchalJ
AchalJ / code.php
Created February 28, 2022 06:32
PowerPack Content Grid - Display taxonomy term thumbnail in post as a fallback image
add_filter( 'pp_post_image_settings_data', function( $data, $settings ) {
global $post;
if ( false !== strpos( $data['photo_src'], 'placeholder.jpg' ) ) {
$terms = get_the_terms( $post->ID, 'category' ); // Here "category" is the post taxonomy slug.
if ( ! is_wp_error( $terms ) && ! empty( $terms ) ) {
$term = $terms[0];
$term_thumb_id = get_term_meta( $term->term_id, 'taxonomy_thumbnail_id', true );
@AchalJ
AchalJ / code.php
Created January 27, 2022 06:55
Shortcode to get taxonomy term description
// Using product_brand taxonomy in this example.
add_shortcode( 'product_brand_desc', function() {
if ( ! is_single() ) {
return;
}
$current_post_terms = wp_get_post_terms( get_the_ID(), 'product_brand', array( 'fields' => 'ids' ) );
$desc = '';
if ( ! is_wp_error( $current_post_terms ) && ! empty( $current_post_terms ) ) {
$current_post_term = $current_post_terms[0];
$desc = get_term_field( 'description', $current_post_term );
@AchalJ
AchalJ / shortcode.php
Created January 19, 2022 17:07
Post Featured Image Shortcode
add_shortcode( 'cg_post_featured_image', function( $attrs ) {
$args = wp_parse_args( $attrs, array(
'linked' => 'yes',
) );
$image = get_the_post_thumbnail( $post, $settings->size, array(
'itemprop' => 'image',
'class' => 'post-featured-image',
) );
@AchalJ
AchalJ / css.css
Created December 23, 2021 09:57
WooPack Products Grid - Custom Layout with Hover Style
.woopack-product-grid {
overflow: visible;
}
.woopack-product-image {
position: relative;
padding: 0;
border: 0;
}
.woopack-product-image a {
display: block;
@AchalJ
AchalJ / functions.php
Created December 17, 2021 06:51
PowerPack Content Grid - Show only rendered products terms in filters
add_action( 'pp_cg_before_posts', function( $settings, $query ) {
if ( 'no' == $settings->post_grid_filters_display || 'none' == $settings->post_grid_filters ) {
return;
}
add_filter( 'pp_cg_filter_terms', function( $terms, $module_settings ) use ( $query ) {
$rendered_terms = array();
$posts = $query->get_posts();
foreach ( $posts as $single ) {
@AchalJ
AchalJ / code.css
Last active December 8, 2021 06:09
Content Grid - Add to Cart with AJAX - WooCommerce
.pp-add-to-cart a.loading {
opacity: 0.5;
pointer-events: none;
}
.pp-add-to-cart a.added_to_cart {
margin-left: 5px;
}
@AchalJ
AchalJ / code.php
Last active November 3, 2021 18:18
WooPack - Product Categories - Multi-level filters
<?php
// Please copy the code below and paste it to your current theme's functions.php
add_filter('pp_category_grid_query_args', function($args, $settings) {
if ( is_tax() || is_category() || is_tag() ) {
$current_object = get_queried_object();
$taxonomy = $current_object->taxonomy;
// Unset or remove variables.