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 / restrict-foreign-characters-gravity-forms.php
Created April 18, 2025 12:38
Simple PHP code to restrict Gravity Forms fields to English letters, numbers, spaces, and basic punctuation only. Prevents foreign characters on form submission.
<?php
add_filter('gform_field_validation', function($result, $value, $form, $field) {
// Specify the field IDs you want to restrict (example: 1, 2)
$restricted_field_ids = [1, 2];
if (in_array($field->id, $restricted_field_ids)) {
// If value is an array (like Name field), convert it to a string
if (is_array($value)) {
$value = implode(' ', $value);
}
@faisalahammad
faisalahammad / gravity-forms-placeholder-asterisk.php
Created April 13, 2025 05:42
This snippet auto-appends an asterisk to the placeholder text of required fields in Gravity Forms. It ensures that only fields with placeholders are modified, and prevents double-adding asterisks.
<?php
function gw_required_placeholder_asterisk( $form ) {
foreach ( $form['fields'] as &$field ) {
// Skip fields that don't support placeholders
if ( ! is_callable( [ $field, 'get_entry_inputs' ] ) ) {
continue;
}
// Single input fields
if ( is_array( $field->inputs ) ) {
@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 );