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 / hide-variations-for-specific-products-vaspfw.php
Created November 17, 2025 04:43
Custom code to hide variations for selected products when using the Variations as Single Products plugin.
/**
* Hide variations for specific products when using Variations as Single Products plugin
* Add product slugs to the $target_products array below
*/
add_filter( 'posts_clauses', 'vaspfw_hide_specific_variations', 99998, 2 );
function vaspfw_hide_specific_variations( $clauses, $query ) {
global $wpdb;
// Only apply to variation queries
if ( ! isset( $query->query_vars['vaspfw_single_variation_filter'] ) ||
@shameemreza
shameemreza / add-us-tariff-to-shipping.php
Created November 5, 2025 16:18
Applies a percentage-based import tariff to shipping costs for orders going to the United States. Code based on: https://woocommerce.com/document/add-a-surcharge-to-cart-and-checkout-uses-fees-api/#section-3
/**
* Add US tariff surcharge to shipping costs.
*
* Custom implementation to apply US tariffs on shipping charges
* to work alongside the WooCommerce Customs Fees plugin.
*
* @since 1.0.0
* @author Shameem Reza
*/
@shameemreza
shameemreza / fix-woocommerce-rtl-currency-position.php
Created September 17, 2025 04:43
Forces the currency symbol to display before the price and applies CSS to ensure consistent left alignment across all price contexts (cart, checkout, product pages, mini cart).
/**
* Add this code to your theme's functions.php file
* or use a code snippets plugin
*
* This fixes the currency symbol positioning for WooCommerce on RTL sites
*/
// Fix WooCommerce currency position for RTL sites
add_filter( 'woocommerce_price_format', function( $format, $currency_pos ) {
// Only apply to RTL sites with ILS currency
@shameemreza
shameemreza / product-addons-sold-individually.php
Created September 11, 2025 03:11
Fix for Product Add-Ons bypassing the Sold individually setting in WooCommerce.
/**
* Fix for Product Add-ons bypassing Sold individually setting
* Add this to the theme's functions.php or as a custom plugin
*/
add_filter( 'woocommerce_add_to_cart_validation', 'enforce_sold_individually_with_addons', 999, 5 );
function enforce_sold_individually_with_addons( $passed, $product_id, $quantity, $variation_id = 0, $variations = array() ) {
// Get the product
$product = wc_get_product( $variation_id ? $variation_id : $product_id );
@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
Created August 3, 2025 05:34
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 in regular order view
add_action( 'woocommerce_after_order_itemmeta', function( $item_id, $item, $order ) {
if ( is_admin() && $item->is_type( 'line_item' ) ) {
$product = $item->get_product();
if ( $product && method_exists( $product, 'get_global_unique_id' ) ) {
$unique_id = $product->get_global_unique_id();
if ( $unique_id ) {
echo '<div class="woocommerce-item-meta" style="color: #888; font-size: 12px;"><strong>Global ID:</strong> ' . esc_html( $unique_id ) . '</div>';
}
}
@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 ) ) {