Skip to content

Instantly share code, notes, and snippets.

View faisalahammad's full-sized avatar
🎯
Focusing

Faisal Ahammad faisalahammad

🎯
Focusing
View GitHub Profile
@faisalahammad
faisalahammad / replace-thumbnails-with-fullsize-images.php
Last active February 27, 2025 15:07
This code snippet uses jQuery to replace product thumbnail images with their full-size versions in the WordPress admin products list page. It ensures that whenever the page loads or the product list is refreshed, the thumbnails are updated to show larger images.
<?php
/**
* Use jQuery to replace product thumbnails with full-size images in admin
* @author: Faisal Ahammad
*/
function replace_admin_thumbnails_with_fullsize_js() {
$screen = get_current_screen();
if (!$screen || $screen->base !== 'edit' || $screen->post_type !== 'product') {
return;
}
@faisalahammad
faisalahammad / woocommerce-display-only-free-shipping-method-when-available.php
Last active February 2, 2025 06:53
Hide all paid shipping methods in WooCommerce when free shipping is available. Just drop this code in your functions.php or custom plugin and you're good to go! Perfect for stores that want to encourage free shipping usage.
<?php
add_filter('woocommerce_package_rates', 'hide_shipping_when_free_is_available', 100);
function hide_shipping_when_free_is_available($rates) {
$free = array();
// Find free shipping methods
foreach ($rates as $rate_id => $rate) {
if ('free_shipping' === $rate->method_id) {
$free[$rate_id] = $rate;
@faisalahammad
faisalahammad / disable-wordpress-rss-feeds.php
Created January 8, 2025 03:40
This code snippet disables all feed types in WordPress (RSS, Atom, RDF) and displays a custom message directing users to the homepage. Ideal for sites that do not want to offer feed capabilities.
function wpb_disable_feed() {
wp_die( __('No feed available, please visit our <a href="' .
get_bloginfo('url') . '">homepage</a>!') );
}
add_action('do_feed', 'wpb_disable_feed', 1);
add_action('do_feed_rdf', 'wpb_disable_feed', 1);
add_action('do_feed_rss', 'wpb_disable_feed', 1);
add_action('do_feed_rss2', 'wpb_disable_feed', 1);
add_action('do_feed_atom', 'wpb_disable_feed', 1);
@faisalahammad
faisalahammad / wordpress-disable-all-admin-notices.php
Created January 7, 2025 07:38
WordPress snippet to completely disable and remove all admin notices, dashboard notifications, update nags, and plugin notices. Works with all WordPress versions, prevents third-party plugins from showing notices, and follows WordPress coding standards. Can be used in themes, plugins, or with Code Snippets plugin.
<?php
/**
* Disable Admin Notices WordPress
* Description: Completely removes all admin notices from the WordPress dashboard,
* including core WordPress notices and those added by plugins and themes.
* @author Faisal Ahammad <[email protected]>
*/
// Exit if accessed directly
if (!defined('ABSPATH')) {
@faisalahammad
faisalahammad / ninja-forms-disable-sundays-and-past-dates-advanced-datepicker.js
Last active September 5, 2024 12:55
A simple code snippet to disable Sundays and prevent past dates in the Ninja Forms Advanced Datepicker add-on. This solution uses Flatpickr to ensure only future dates can be selected and Sundays are excluded. Perfect for booking forms or scheduling systems where past dates and Sundays aren't valid.
/**
* Ninja Forms - Disable Past Dates and Sundays in Advanced Datepicker
* @author Faisal Ahammad
*/
jQuery(document).ready(function ($) {
function initCustomDatePicker() {
var customDatePicker = Marionette.Object.extend({
initialize: function () {
this.listenTo(Backbone.Radio.channel("flatpickr"), "init", this.modifyDatepicker);
@faisalahammad
faisalahammad / remove-thousand-separator-wordpress-pagination.php
Created September 4, 2024 18:24
A simple way to remove the default thousand separator from WordPress pagination. If you’re tired of seeing those pesky commas in your page numbers, this quick snippet will clean them up for you. Just drop it into your theme’s functions.php and enjoy cleaner pagination links!
<?php
/**
* Remove thousand separator from WordPress pagination
* @author Faisal Ahammad
*/
/**
* @param $output
* @return mixed
@faisalahammad
faisalahammad / woocommerce-merge-email-phone-checkout.php
Created September 4, 2024 06:31
This WooCommerce customization merges the email and phone fields into a single input on the checkout page. Customers can provide either an email address or a Bangladeshi phone number, simplifying the checkout process. The code also includes validation to ensure correct input formats and saves the data appropriately.
<?php
/**
* WooCommerce Merge Email and Phone on Checkout
* @author Faisal Ahammad
*/
add_filter( 'woocommerce_checkout_fields', 'customize_checkout_fields_checkout' );
/**
@faisalahammad
faisalahammad / woocommerce-login-with-phone-or-email.php
Created September 4, 2024 06:00
Enable WooCommerce users to log in using either their phone number or email address. This code snippet overrides the default WooCommerce login logic, allowing for flexible login options and improving the user experience on the account login page.
<?php
/**
* Woocommerce Add Phone Number To Login Account
* @author Faisal Ahammad
*/
// Enable login with phone number or email
add_filter( 'authenticate', 'login_with_phone_or_email', 20, 3 );
@faisalahammad
faisalahammad / woocommerce-account-signup-with-phone-number.php
Created September 4, 2024 05:57
Add a phone number field to the WooCommerce account registration form. This code snippet validates and saves the phone number during user sign-up, allowing users to register with both a phone number and email address for enhanced account creation.
<?php
/**
* Woocommerce Add Phone Number Field To Registration Form
* @author Faisal Ahammad
*/
add_action( 'woocommerce_register_form', 'add_phone_field_to_registration' );
function add_phone_field_to_registration()
@faisalahammad
faisalahammad / ninja-forms-check-duplicate-email-address-display-warning.js
Created August 26, 2024 06:12
Display Warning Message and Disable Submit Button in Ninja Forms When Emails Match. This script checks if two email fields in a Ninja Forms form have matching values. If they do, it displays a warning message and disables the submit button, enhancing form validation. Ideal for WordPress users working with Ninja Forms who need to prevent identica…
/**
* Ninja Forms - Compare Two Field Email Address and Display Error
* @author Faisal Ahammad
*/
/**
* Form ID: replace the #nf-form-1-cont form ID with your desire form ID
* Email 1 class: add student_email or different class to the field "Email field setting → Display → Element"
* Email 2 class: add agent_email or different class to the field "Email field setting → Display → Element"
* Warning Message class: add warning_message or different class to the "HTML field setting → Display → Container"