Skip to content

Instantly share code, notes, and snippets.

View shameemreza's full-sized avatar
🇧🇩
Problem-Solver | WooCommerce Expert | Customer-First Mindset

Shameem Reza shameemreza

🇧🇩
Problem-Solver | WooCommerce Expert | Customer-First Mindset
View GitHub Profile
@shameemreza
shameemreza / ideal-refund-debug.php
Created May 28, 2025 02:19
Debug code for iDEAL refund issue
/**
* Debug code for iDEAL refund issue
*
* This file contains diagnostic code to help identify why the iDEAL refund
* option is missing in WooCommerce Stripe Gateway. Add this to your theme's
* functions.php to see the debugging output in the HTML source.
*/
// Debug code to check if iDEAL gateway is properly registered
add_action('init', function() {
@shameemreza
shameemreza / ideal-refund-solution.php
Last active May 28, 2025 02:25
Solution for WooCommerce Stripe iDEAL Refund
/**
* Solution for WooCommerce Stripe iDEAL Refund
*
* This code adds a "Refund via iDEAL" button to WooCommerce orders paid with iDEAL,
* even when the Stripe gateway isn't properly registered.
*/
add_action('woocommerce_order_item_add_action_buttons', function($order) {
if ($order->get_payment_method() !== 'stripe_ideal') {
return;
}
@shameemreza
shameemreza / fix-login-enter-key-woocommerce.php
Created May 26, 2025 08:45
Fixes the issue where the Enter key doesn't submit the WooCommerce login form when user registration is disabled. Temporary workaround until WooCommerce 9.9.9 (June 2, 2025).
/**
* Fix for WooCommerce login form Enter key not working when registration is disabled
* This is a temporary fix until WooCommerce 9.9.9 is released (June 2, 2025)
*/
function fix_woocommerce_login_enter_key() {
// Only add this script on pages that might have the login form
if (!is_account_page() && !is_checkout()) {
return;
}
@shameemreza
shameemreza / exempt-product-variations-from-object-caching.php
Created May 25, 2025 04:19
Exempt product variations from object caching to fix variation selection buttons
/**
* Exempt product variations from object caching to fix variation selection buttons
*
* This fixes an issue where variation buttons disappear when object caching is enabled
* on Pressable or any other hosting.
*/
add_filter('advanced_post_cache_skip_for_post_type', 'oleomontreal_exempt_variations_from_cache', 10, 2);
function oleomontreal_exempt_variations_from_cache($return_me, $post_type) {
$exempted = array('product_variation');
if (in_array($post_type, $exempted)) {
@shameemreza
shameemreza / reduce-action-scheduler-retention-period.php
Created May 25, 2025 02:19
Reduce Action Scheduler Retention Period to One Week in WooCommerce
add_filter( 'action_scheduler_retention_period', 'wc_action_scheduler_purge' );
/**
* Change Action Scheduler default purge to 1 week
*/
function wc_action_scheduler_purge() {
return WEEK_IN_SECONDS;
}
@shameemreza
shameemreza / automatewoo-generate-coupon-on-purchase.php
Created May 21, 2025 04:00
Generates a unique coupon when a specific product (Bronze, Silver, or Gold Coupon) is purchased and emails it to the customer using AutomateWoo.
/**
* Generate a coupon when a specific product is purchased and email it to the customer.
* @param AutomateWoo\Workflow $workflow
*/
function my_automatewoo_generate_coupon( $workflow ) {
$order = $workflow->data_layer()->get_order();
if ( ! $order ) {
return;
}
@shameemreza
shameemreza / all-attribute-terms-shortcode.php
Created May 20, 2025 09:56
Shortcode to display all attribute terms in WooCommerce, including unused ones, with working filter links.
/**
* Shortcode: [all_attribute_terms attribute="pa_size"]
* Shows all terms for a product attribute, even if not assigned to products.
* Links use WooCommerce's layered nav filter format.
*/
function show_all_attribute_terms( $atts ) {
$atts = shortcode_atts( [
'attribute' => '',
], $atts );
@shameemreza
shameemreza / filter-distance-rate-shipping-by-lowest-cost.php
Created May 7, 2025 06:12
WooCommerce Distance Rate Shipping: Filter to only return the shipping rate with the lowest cost when multiple rates are available.
add_filter( 'woocommerce_package_rates', 'keep_only_lowest_distance_rate', 20, 2 );
function keep_only_lowest_distance_rate( $rates, $package ) {
$lowest_rate_key = '';
$lowest_cost = null;
foreach ( $rates as $rate_key => $rate ) {
if ( is_null( $lowest_cost ) || floatval( $rate->cost ) < $lowest_cost ) {
$lowest_cost = floatval( $rate->cost );
$lowest_rate_key = $rate_key;
add_action( 'woocommerce_cart_calculate_fees', function() {
if ( wcs_cart_contains_renewal() ) {
return;
}
$subscription_box_id = 54;
$cart_contents = WC()->cart->get_cart_contents();
foreach ( WC()->cart->get_cart() as $cart_item ) {
if ( empty( $cart_item[ 'wcsatt_data'][ 'active_subscription_scheme' ] ) ) {
continue;
}
@shameemreza
shameemreza / filter-products-no-vendor.php
Created April 28, 2025 02:00
Adds a "No Vendor" filter link to the WooCommerce Products admin screen for stores using WooCommerce Product Vendors.
// Add custom view for products without a vendor
add_filter( 'views_edit-product', function( $views ) {
$class = ( isset($_GET['no_vendor']) && $_GET['no_vendor'] == 1 ) ? 'current' : '';
$url = add_query_arg( 'no_vendor', '1', admin_url( 'edit.php?post_type=product' ) );
$views['no_vendor'] = "<a href='{$url}' class='{$class}'>No Vendor</a>";
return $views;
});
// Modify the query to show products without vendor when selected
add_action( 'pre_get_posts', function( $query ) {