Skip to content

Instantly share code, notes, and snippets.

View shameemreza's full-sized avatar
🇧🇩
I fix the WooCommerce problems that keep merchants stuck.

Shameem Reza shameemreza

🇧🇩
I fix the WooCommerce problems that keep merchants stuck.
View GitHub Profile
@shameemreza
shameemreza / wc-reset-variations-after-add-to-cart.php
Created September 3, 2025 05:21
Automatically reset product variation selections after a successful Add to Cart (AJAX or non-AJAX).
/**
* Reset variation selections after successful add to cart
*/
add_action( 'wp_footer', function() {
if ( ! is_product() ) {
return;
}
?>
<script type="text/javascript">
jQuery(document).ready(function($) {
@shameemreza
shameemreza / custom-add-to-cart-text-bookings.php
Created August 18, 2025 02:09
Forces WooCommerce Bookings products to always show "Add to Cart" as the button text.
add_filter('woocommerce_product_add_to_cart_text', function($text, $product) {
if ($product->get_type() === 'booking') {
return __('Add to Cart', 'woocommerce');
}
return $text;
}, 10, 2);
@shameemreza
shameemreza / fix-duplicate-downloads-in-subscription-items.php
Last active August 7, 2025 01:43
Prevents WooCommerce Subscription Downloads from adding downloadable products as separate line items in subscription orders, while keeping download access intact.
/**
* Hide zero-priced downloadable products from subscription line items.
*/
function wcsd_hide_zero_priced_downloads() {
// Filter the line items display only, not affecting the actual data.
add_filter( 'woocommerce_order_get_items', 'wcsd_filter_subscription_items', 10, 3 );
// IMPORTANT: We're NOT removing the original download_permissions action
// so download permissions are still properly granted.
}
@shameemreza
shameemreza / add-global-id-to-admin-order-view.php
Last active December 16, 2025 07:19
Adds the product’s Global Unique ID to both the regular order view and the order preview in the WooCommerce admin. Useful for stores or integrations that rely on unique product identifiers beyond SKUs.
/**
* Display Global ID (GTIN) in WooCommerce Order Admin
* Works for both simple and variable products (variations)
*
* @since 1.0.0
*/
// Display Global ID in regular order view (order details page)
add_action( 'woocommerce_after_order_itemmeta', function( $item_id, $item, $product ) {
// Only show in admin and for line items
@shameemreza
shameemreza / fix-subscription-tax-admin-one-time.php
Created July 24, 2025 05:24
One-time admin-side script to fix incorrect tax calculations in WooCommerce Subscriptions. Visit each affected subscription in the admin panel to trigger the recalculation. Safe to remove after use.
/**
* Simple one-time fix for WooCommerce Subscription tax calculation.
*
* This function automatically recalculates taxes for subscriptions when viewing them in admin.
* Add this code to your theme's functions.php or a custom plugin, visit each affected
* subscription once, then remove the code.
*
* @since 1.0.0
*/
function hafwpv_fix_subscription_taxes() {
@shameemreza
shameemreza / prevent-autocomplete-renewal-orders-with-shipping.php
Created July 23, 2025 05:55
Prevents WooCommerce from auto-completing subscription renewal orders that have $0 product value but include shipping costs. Forces these orders to remain in processing until manually completed.
/**
* Prevent WooCommerce from auto-completing orders with $0 product total but shipping costs.
*
* @param bool $is_virtual Whether the order contains only virtual products.
* @param WC_Order $order The order object.
* @return bool
*/
function a8c_prevent_zero_value_order_completion( $is_virtual, $order ) {
// Only modify behavior for subscription renewal orders
if ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order ) ) {
@shameemreza
shameemreza / resubscribe-use-current-product-price.php
Created July 17, 2025 09:09
Forces WooCommerce Subscriptions resubscriptions to use the current product price instead of the original subscription price. Applies when resubscribing through the cart and during checkout. Optionally logs the price change and can display a notice to the customer.
/**
* Ensure resubscriptions use current product prices
* Add this to your theme's functions.php or a custom functionality plugin
*/
add_filter( 'woocommerce_add_cart_item', 'update_resubscribe_price', 20, 1 );
add_filter( 'woocommerce_before_calculate_totals', 'update_cart_resubscribe_prices', 20, 1 );
/**
* Update price when a resubscribed product is added to the cart
*
@shameemreza
shameemreza / prevent-resubscribe-out-of-stock-products.php
Created July 17, 2025 06:27
Prevents users from resubscribing to a WooCommerce subscription if it includes any out-of-stock physical products.
/**
* Prevent resubscription to out-of-stock physical products.
* Add this to your theme's functions.php or a custom functionality plugin.
*
* @param bool $can_resubscribe Whether the user can resubscribe to the subscription.
* @param WC_Subscription $subscription The subscription object.
* @param int $user_id The user ID.
* @return bool Whether the user can resubscribe after stock check.
*/
function custom_wcs_resubscribe_stock_check( $can_resubscribe, $subscription, $user_id ) {
@shameemreza
shameemreza / fix-avalara-conditional-shipping-conflict.php
Created July 12, 2025 01:47
Fixes a conflict between the Avalara AvaTax plugin and the WooCommerce Conditional Shipping and Payments extension.
/**
* Fix conflict between Avalara AvaTax and WooCommerce Conditional Shipping and Payments
*
* The issue is that Avalara AvaTax plugin interferes with the calculation of cart totals
* used by the Conditional Shipping and Payments plugin when determining which shipping methods
* to display. This happens specifically on initial page load before any cart updates trigger recalculation.
*
* This filter ensures that the Conditional Shipping and Payments plugin has access to the correct
* cart totals when evaluating shipping method restrictions based on cart total conditions.
*/
@shameemreza
shameemreza / force-distance-rate-shipping-recalc.php
Created July 10, 2025 05:39
Fixes Distance Rate Shipping not updating during checkout when address fields (like city or postcode) change within the same state. Adds JS to trigger recalculation and clears transients server-side to force fresh rate calculation.
/**
* Force recalculation of shipping rates when address fields change during checkout
* Fixes issue with Distance Rate Shipping not updating for address changes within the same state
*/
function wooninja_force_shipping_recalculation() {
if ( ! is_checkout() ) {
return;
}
?>
<script type="text/javascript">