Skip to content

Instantly share code, notes, and snippets.

View AchalJ's full-sized avatar

Achal Jain AchalJ

View GitHub Profile
@AchalJ
AchalJ / get_current_post_terms.php
Created June 19, 2020 09:30
Shortcode to get current post terms in HTML | WordPress
add_shortcode('get_current_post_terms', function( $atts ) {
$atts = shortcode_atts( array(
'taxonomy' => 'category',
'limit' => '1',
'fields' => 'slugs',
'separator' => ',',
'print' => 0
), $atts );
global $post;
@AchalJ
AchalJ / jquery.sticky.js
Last active July 1, 2020 19:08
jQuery Extension to make an element sticky on scroll
/**
* Sticky 1.0.0
* https://github.com/AchalJ
*
* Copyright (c) 2020 Achal Jain
*
* Licensed under the MIT License
*/
(function(factory) {
if ( typeof define === 'function' && define.amd ) {
@AchalJ
AchalJ / functions.php
Created July 6, 2020 10:23
PP Header / Footer support for Ascend Premium theme
// PP Header / Footer.
add_filter( 'pp_header_footer_theme_slug', 'acsend_pp_header_footer_slug' );
function acsend_pp_header_footer_slug( $slug ) {
return 'ascend_premium';
}
add_action( 'pp_header_footer_after_setup', 'acsend_pp_header_footer_setup' );
function acsend_pp_header_footer_setup( $slug ) {
if ( 'ascend_premium' === $slug || 'ascend_premium_child' === $slug ) {
add_action( 'wp', 'acsend_pp_header_footer_init' );
@AchalJ
AchalJ / woo-product-get-price-shortcode.php
Created August 19, 2020 07:30
Shortcode to get WooCommerce Product Price
add_shortcode( 'woo_wc_get_product_price', function( $args ) {
if ( ! isset( $args['id'] ) || empty( absint( $args['id'] ) ) ) {
return;
}
if ( ! function_exists( 'wc_get_product' ) ) {
return;
}
$id = absint( $args['id'] );
$product = wc_get_product( $id );
@AchalJ
AchalJ / code.php
Created August 29, 2020 10:07
WP Allow User Registration from specific domain emails
add_filter( 'pre_user_email', function( $email ) {
$allowed_domains = array(
'example.com',
'yoursite.com',
);
if ( ! is_email( $email ) ) {
return $email;
}
@AchalJ
AchalJ / code.php
Last active September 24, 2020 06:23
Extend Beaver Builder PowerPack Registration Form
// Add fields.
add_filter( 'pp_rf_fields', function( $fields, $settings, $id ) {
if ( isset( $fields['consent'] ) ) {
$consent = $fields['consent'];
unset( $fields['consent'] );
}
$fields[] = array(
'name' => 'meta_address_field',
'label' => 'Address',
'type' => 'textarea',
@AchalJ
AchalJ / adv-menu.php
Created February 26, 2021 13:59
Add extra elements in Advanced Menu
// Advanced Menu - off-canvas before menu items
// First, add pp-adv-menu--extra ID to module setting > Advanced tab > ID field.
// Then add the following code in your current theme's functions.php
function wpba_demo_offcanvas_menu_before( $type, $settings, $id )
{
if ( $settings->id != 'pp-adv-menu--extra' ) {
return;
}
?>
<style>
@AchalJ
AchalJ / layout.css
Created March 24, 2021 17:21
PowerPack Content Grid - Equal Align Button
.pp-post-equal-align .pp-post-body {
height: 100%;
}
.pp-post-equal-align:not(.pp-content-alternate) .pp-post-body {
display: flex;
flex-direction: column;
}
.pp-post-equal-align .pp-post-info {
height: 100%;
}
@AchalJ
AchalJ / functions.php
Created April 8, 2021 07:02
Add an extra field to PowerPack's Registration Form module
add_filter( 'pp_rf_fields', function( $fields, $settings, $id ) {
if ( isset( $fields['consent'] ) ) {
$consent = $fields['consent'];
unset( $fields['consent'] );
}
$fields[] = array(
'type' => 'text',
'name' => 'company_name',
'label' => 'Company Name',
@AchalJ
AchalJ / code.php
Created May 7, 2021 09:32
Beaver Themer - WooCommerce: Add Stock Status field connection
add_action( 'fl_page_data_add_properties', 'ac_add_field_connections' );
function ac_add_field_connections() {
FLPageData::add_post_property( 'woocommerce_product_stock_status', array(
'label' => __( 'Product Image with Gallery Slider', 'woopack' ),
'group' => 'woocommerce',
'type' => 'string',
'getter' => 'ac_get_product_stock_status',
) );
}