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
@elias1435
elias1435 / custom.js
Created January 2, 2023 09:46
How to check if the URL contains a given string?
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
if (window.location.href.indexOf("checkout/?add-to-cart=1375&quantity=1") > -1) {
titleClass = document.querySelector(".find_class_to_add_new_class");
titleClass.classList.add("display-none-info");
}
});
</script>
@elias1435
elias1435 / current-user-name.php
Last active December 22, 2022 05:28
display current user name with shortcode. this code will go in functions.php
function show_loggedin_function( $atts ) {
global $current_user, $user_login;
get_currentuserinfo();
add_filter('widget_text', 'do_shortcode');
if ($user_login)
return 'Welcome ' . $current_user->display_name . '!';
else
return '<a href="' . wp_login_url() . ' ">Login</a>';
@elias1435
elias1435 / style.css
Created December 21, 2022 16:31
Checkbox Button Too Small On iPhone
input[type=checkbox],
input[type=radio] {
width: auto;
flex: 0 0 16px;
}
@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;
}
@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.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
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 / 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 / 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 / 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;
}