Skip to content

Instantly share code, notes, and snippets.

View AchalJ's full-sized avatar

Achal Jain AchalJ

View GitHub Profile
@AchalJ
AchalJ / shortcode.php
Created May 7, 2021 09:33
WooCommerce Display Stock Status with custom text through Shortcode
add_shortcode( 'woo_product_stock_status', function( $atts ) {
$atts = shortcode_atts(
array(
'id' => get_the_ID(),
'show_instock' => 'yes',
'show_outofstock' => 'yes',
'instock_text' => __( 'In Stock' ),
'outofstock_text' => __( 'Out of Stock' ),
),
$atts, 'woo_product_stock_status'
@AchalJ
AchalJ / layout.css
Created May 25, 2021 09:57
PowerPack Content Grid - Replicate Style 6 with Custom Layout (Beaver Themer)
.pp-post {
height: 100%;
}
.pp-post-body {
display: flex;
flex-direction: column;
justify-content: space-between;
height: 100%;
margin-top: 0;
}
@AchalJ
AchalJ / code.php
Created July 13, 2021 08:52
PowerPack Content Grid - Stop scroll to grid on Filter - specific page
add_filter( 'pp_cg_scroll_to_grid_on_filter', function( $should_scroll ) {
if ( is_page( 4399 ) ) { // Please change the Page ID here.
$should_scroll = false;
}
return $should_scroll;
} );
@AchalJ
AchalJ / shortcode.php
Last active August 20, 2021 17:18
ACF Gallery field - Custom Shortcode
add_shortcode( 'custom_acf_gallery', function( $atts ) {
$gallery_data = get_field( 'gallery' ); // change the field name accordingly.
ob_start();
if ( ! empty( $gallery_data ) ) {
?>
<div class="pp-post-gallery">
<?php
foreach ( $gallery_data as $image_data ) {
@AchalJ
AchalJ / code.php
Created September 21, 2021 16:53
WooCommerce - Change variable product button text
add_filter( 'woocommerce_product_add_to_cart_text', function( $text, $product ) {
if ( 'variable' === $product->get_type() ) {
$text = __( 'Read More' );
}
return $text;
}, 11, 2 );
@AchalJ
AchalJ / css.css
Created September 23, 2021 10:14
WooPack Product Grid - Custom Layout with Hover Styles
.woopack-product-grid {
overflow: visible;
}
.woopack-product-image {
position: relative;
padding: 0;
border: 0;
}
.woopack-product-image a {
display: block;
@AchalJ
AchalJ / code.php
Created October 4, 2021 08:48
PP Content Grid - Add WooCommerce Sorting drop-down
// Add sort by Title.
add_filter( 'woocommerce_catalog_orderby', 'custom_sorting_options_wc', 99 );
add_filter( 'woocommerce_default_catalog_orderby_options', 'custom_sorting_options_wc', 99 );
function custom_sorting_options_wc( $order_by ) {
$new_options = array(
'title' => __( 'Sort by Name: A to Z' ),
'title-desc' => __( 'Sort by Name: Z to A' ),
);
$order_by = array_merge( $order_by, $new_options );
@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.
@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 / 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 ) {