Skip to content

Instantly share code, notes, and snippets.

View elias1435's full-sized avatar
🕋
Working from home

Md. Elias elias1435

🕋
Working from home
View GitHub Profile
<?php
// Customize SearchWP Engine used.
add_filter( 'searchwp\native\args', function( $args, $query ) {
$args['engine'] = 'supplemental';
return $args;
}, 15, 2 );
@elias1435
elias1435 / functions.php
Created July 29, 2022 09:53
Elementor - SORT POSTS BASED ON A CUSTOM DATE FIELD
/* Sort Posts by Custom Date Field */
add_action( 'elementor/query/event_sort_date', function( $query ) {
$query->set( 'meta_key', 'event_date' );
$query->set( 'orderby', 'meta_value_num' );
$query->set( 'order', 'ASC' );
});
@elias1435
elias1435 / Archive-product.php
Created August 16, 2022 16:48
Change your woocommerce Product listing with Grid and List view with jQuery
<?php
/**
* The Template for displaying product archives, including the main shop page which is a post type archive
*
* This template can be overridden by copying it to yourtheme/woocommerce/archive-product.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
@elias1435
elias1435 / view-count-jet-block.php
Last active September 12, 2022 16:49
by this code snippet can be add view count for crocoblock jet block plugin. use this snippet to your child theme functions.php
<?php
add_filter( 'single_template', 'update_view_counter' );
function update_view_counter( $single_template ) {
global $post;
$old_count = get_post_meta( $post->ID, 'sk_view_counter', true );
update_post_meta($post->ID, 'sk_view_counter', ($old_count+1));
return $single_template;
}
@elias1435
elias1435 / view-count-elementor-pro-cards-post-skin.php
Created September 12, 2022 16:51
by this code snippet can be add view count for element pro post widget. use this snippet to your child theme functions.php This snippet will only work for skin type "cards" you can change your just change the "cards" below
<?php
add_action( 'elementor/widget/posts/skins_init',function($widget) {
class change_meta_data extends \ElementorPro\Modules\Posts\Skins\Skin_Cards {
public function get_id() {
return 'cards';
}
public function get_title() {
return esc_html__( 'Card', 'elementor-pro' );
}
@elias1435
elias1435 / Elementor Popup once per session || Show after X Sessions Elementor
Last active January 4, 2023 10:41
Elementor Popup once per session || Show after X Sessions Elementor
# Create a Popup
1. Create a standard Elementor Popup
2. Set the Display Conditions for the pages you want to use it on
3. Take a note of the Popup ID
# JavaScript Code
1. In this example add an HTML Widget to the page
2. Copy and paste the code below into the Widget
3. Change the "popupId" constant you the ID of your
@elias1435
elias1435 / functions.php
Last active October 29, 2022 04:21
Remove zoom effect on WooCommerce Single product image | WooCommerce Gallery product images. use this code in your child theme functions.php
function remove_image_zoom_support() {
remove_theme_support( 'wc-product-gallery-zoom' );
}
add_action( 'wp', 'remove_image_zoom_support', 100 );
@elias1435
elias1435 / functions.php
Created October 29, 2022 04:21
disabling the lightbox on WooCommerce Single product image. use this code in your child theme functions.php
function custom_single_product_image_html( $html, $post_id ) {
$post_thumbnail_id = get_post_thumbnail_id( $post_id );
return get_the_post_thumbnail( $post_thumbnail_id, apply_filters( 'single_product_large_thumbnail_size', 'shop_single' ) );
}
add_filter('woocommerce_single_product_image_thumbnail_html', 'custom_single_product_image_html', 10, 2);
@elias1435
elias1435 / functions.php
Created November 20, 2022 05:51
Empty Woocommerce Cart before adding new item | only 1 product add to cart woocommerce, Code goes in function.php file of your active child theme (or theme)
<?php
// before addto cart, only allow 1 item in a cart
add_filter( 'woocommerce_add_to_cart_validation', 'woo_custom_add_to_cart_before' );
function woo_custom_add_to_cart_before( $cart_item_data ) {
global $woocommerce;
$woocommerce->cart->empty_cart();
// Do nothing with the data and return
return true;
}
@elias1435
elias1435 / functions-singular_name.php
Created December 20, 2022 09:50
Change ‘Choose an Option’ variation dropdown label in WooCommerce. Code goes in function.php file of your active child theme (or active theme).
/* OR you can use singular_name instead of name like: */
add_filter( 'woocommerce_dropdown_variation_attribute_options_args', 'filter_dropdown_variation_args', 10 );
function filter_dropdown_variation_args( $args ) {
$args['show_option_none'] = apply_filters( 'the_title', get_taxonomy( $args['attribute'] )->labels->singular_name );
return $args;
}