Skip to content
  • Quick Ref
  • Contact
  • About
wpcanyon.com

wpcanyon.com

Tag: WooCommerce

WooCommerce: Add ‘Click & Collect’ without a plugin

Posted on August 19, 2025August 19, 2025 By Admin No Comments on WooCommerce: Add ‘Click & Collect’ without a plugin

WooCommerce: Add ‘Click & Collect’ without a plugin

If you want to offer your customers a convenient “Click & Collect” option in WooCommerce without installing extra plugins, this guide will show you how to do it quickly and cleanly. By customizing WooCommerce’s built-in local pickup shipping method, you can create a seamless in-store pickup experience without the overhead of additional plugins.

Quick Fix: Customize Local Pickup for ‘Click & Collect’

  1. Enable the Local Pickup shipping method in WooCommerce settings.
  2. Rename “Local Pickup” to “Click & Collect” via a filter in your theme’s functions.php.
  3. Optionally, add instructions or pickup details on the checkout page.
  4. Test the checkout flow to ensure the option appears and works as expected.

Why This Happens

WooCommerce includes a “Local Pickup” shipping method by default, designed for customers who want to pick up their orders instead of having them shipped. However, the default label and messaging might not suit your branding or customer experience goals. Instead of installing a plugin that adds a new shipping method, you can simply repurpose and rename the existing local pickup option. This approach keeps your site lightweight and maintains compatibility with WooCommerce updates.

Step-by-step: Add ‘Click & Collect’ Without a Plugin

  1. Enable Local Pickup Shipping Method

    Go to WooCommerce > Settings > Shipping. Select your shipping zone or create a new one if needed. Click Add shipping method and choose Local Pickup.

  2. Rename Local Pickup to Click & Collect

    Add the following code snippet to your active theme’s functions.php file or a site-specific plugin:

    add_filter( 'woocommerce_shipping_method_title', 'rename_local_pickup_to_click_collect', 10, 2 );
    function rename_local_pickup_to_click_collect( $title, $method ) {
        if ( 'local_pickup' === $method-id ) {
            $title = 'Click & Collect';
        }
        return $title;
    }
  3. Add Pickup Instructions on Checkout (Optional)

    To provide customers with pickup instructions, add this snippet to display a custom message when “Click & Collect” is selected:

    add_action( 'woocommerce_review_order_after_shipping', 'display_click_and_collect_instructions' );
    function display_click_and_collect_instructions() {
        $chosen_methods = WC()-session-get( 'chosen_shipping_methods' );
        if ( ! empty( $chosen_methods ) && in_array( 'local_pickup', $chosen_methods ) ) {
            echo '<div class="woocommerce-info">Please collect your order from our store during business hours.</div>';
        }
    }
  4. Test Your Checkout

    Visit your store’s checkout page, add a product to the cart, and select the “Click & Collect” shipping option. Confirm the label change and that the instructions appear if you added them.

UX Tips for ‘Click & Collect’

  • Clear Pickup Location: Include your store address and opening hours in the instructions or confirmation emails.
  • Order Ready Notification: Consider adding an email or SMS notification to inform customers when their order is ready for pickup.
  • Pickup Time Slots: For advanced setups, you might later integrate a time slot selector, but this requires custom development or plugins.
  • Visual Indicators: Use icons or badges to highlight the “Click & Collect” option at checkout for better visibility.

Works on

Environment Compatibility
Web Servers Apache, Nginx, LiteSpeed
Hosting Panels cPanel, Plesk, Managed WordPress Hosting
WooCommerce Versions WooCommerce 3.0 and above
PHP Versions PHP 7.2 and above

FAQ

  1. Can I add multiple pickup locations without a plugin?

    WooCommerce’s default local pickup method supports only one pickup location per shipping zone. To manage multiple locations, you would need custom code or a plugin.

  2. Will this method affect shipping calculations?

    No. Local Pickup is treated as a shipping method with zero cost by default, so it won’t interfere with shipping rates or taxes unless customized.

  3. How can I change the pickup instructions text?

    Edit the message inside the display_click_and_collect_instructions function in your functions.php file.

  4. Is this solution update-safe?

    Yes. Since it uses WooCommerce’s built-in shipping method and standard filters, it is safe through WooCommerce updates. Just keep your theme or custom plugin updated.

  5. Can I style the pickup instructions?

    Yes. The instructions are wrapped in a div with the woocommerce-info class, which you can target with CSS in your theme.

…
WooCommerce How‑tos

WooCommerce: Disable coupons on sale items only

Posted on August 19, 2025August 19, 2025 By Admin No Comments on WooCommerce: Disable coupons on sale items only

WooCommerce: Disable Coupons on Sale Items Only

If you want to prevent customers from using coupons on products that are already on sale, WooCommerce does not offer a built-in setting for this. The quick fix is to add a custom code snippet that disables coupon usage only when the cart contains sale items. This ensures discounts don’t stack, protecting your margins while still allowing coupons on regular-priced products.

Quick Fix: Disable Coupons on Sale Items with a Filter Snippet

add_filter( 'woocommerce_coupons_enabled', 'disable_coupons_on_sale_items', 10, 2 );
function disable_coupons_on_sale_items( $enabled, $cart ) {
    if ( ! is_admin() && $cart ) {
        foreach ( $cart-get_cart() as $cart_item ) {
            if ( $cart_item['data']-is_on_sale() ) {
                return false; // Disable coupons if any sale item is in the cart
            }
        }
    }
    return $enabled;
}

Why This Happens

WooCommerce’s coupon system applies discounts regardless of whether products are on sale. Many store owners want to avoid stacking discounts because:

  • It reduces profit margins excessively.
  • It can cause confusion with pricing and promotions.
  • It may violate promotional rules or terms.

By default, WooCommerce does not differentiate coupon applicability based on product sale status. The snippet above hooks into the coupon enablement process and disables coupons if any sale item is detected in the cart.

Step-by-Step: How to Disable Coupons on Sale Items Only

  1. Access your theme’s functions.php file or use a code snippets plugin.

    Editing functions.php is common, but using a plugin like “Code Snippets” is safer and easier to manage.

  2. Copy and paste the following code snippet:
add_filter( 'woocommerce_coupons_enabled', 'disable_coupons_on_sale_items', 10, 2 );
function disable_coupons_on_sale_items( $enabled, $cart ) {
    if ( ! is_admin() && $cart ) {
        foreach ( $cart-get_cart() as $cart_item ) {
            if ( $cart_item['data']-is_on_sale() ) {
                return false; // Disable coupons if any sale item is in the cart
            }
        }
    }
    return $enabled;
}
  1. Save the changes.
  2. Clear any caching plugins or server cache.

    This ensures the new code takes effect immediately.

  3. Test the functionality.

    Add a sale item to your cart and try applying a coupon. The coupon should be disabled. Then try with only regular-priced items to confirm coupons still work.

Testing

  1. Add a product on sale to your cart.
  2. Attempt to apply a valid coupon code.

    The coupon should not apply, and WooCommerce will typically show a message that coupons are disabled or invalid.

  3. Remove the sale item and add a regular-priced product.
  4. Apply the same coupon code again.

    This time, the coupon should apply successfully.

  5. Test with multiple items, mixing sale and regular products.

    Coupons should be disabled if any sale item is present.

Works on

Environment Compatibility
Web Servers Apache, Nginx, LiteSpeed
Hosting Panels cPanel, Plesk, DirectAdmin
WooCommerce Versions WooCommerce 3.0 and above (tested on latest versions)
WordPress Versions WordPress 5.0 and above

FAQ

  • Q: Can I disable coupons only on specific sale products?
    A: Yes, you can modify the snippet to check product IDs or categories before disabling coupons.
  • Q: Will this snippet affect admin users or backend coupon testing?
    A: No, the snippet excludes admin area checks, so coupons remain enabled in the backend.
  • Q: What if I want to allow coupons on sale items but limit the discount amount?
    A: You would need a more advanced custom function or a plugin that controls coupon discount rules.
  • Q: Can I combine this with other coupon restrictions?
    A: Yes, but ensure your custom code snippets do not conflict. Test thoroughly after adding multiple restrictions.
  • Q: Is there a plugin that does this without custom code?
    A: Some premium WooCommerce plugins offer advanced coupon restrictions, but the snippet is a lightweight and free solution.
…
WooCommerce How‑tos

WooCommerce Stripe: pending payments stuck — causes & fixes

Posted on August 19, 2025August 19, 2025 By Admin No Comments on WooCommerce Stripe: pending payments stuck — causes & fixes

WooCommerce Stripe: Pending Payments Stuck — Causes & Fixes

If you are using WooCommerce with the Stripe payment gateway, you might encounter an issue where payments remain stuck in a “pending” status indefinitely. This problem prevents orders from completing and can disrupt your store’s sales flow. The quick fix usually involves ensuring that Stripe webhooks are correctly configured and that WooCommerce’s scheduled tasks (cron jobs) are running properly.

Quick Fix: Set Up Stripe Webhooks and Verify WooCommerce Cron

  1. Log in to your Stripe Dashboard.
  2. Navigate to Developers > Webhooks.
  3. Create a new webhook endpoint with your WooCommerce webhook URL:
    https://yourdomain.com/?wc-api=wc_stripe
  4. Select the following events to listen for:
    • payment_intent.succeeded
    • payment_intent.payment_failed
    • charge.refunded
    • charge.failed
    • checkout.session.completed
  5. Save the webhook and copy the signing secret.
  6. Go to WooCommerce > Settings > Payments > Stripe and paste the webhook secret.
  7. Ensure your WordPress cron is running by installing a plugin like WP Crontrol or setting up a real cron job on your server.
  8. Manually trigger WooCommerce scheduled tasks or wait for the next cron run to update payment statuses.

Why This Happens

WooCommerce Stripe payments rely on Stripe’s webhook notifications to update order statuses automatically. When a customer completes payment, Stripe sends an event to your site’s webhook URL. WooCommerce listens for these events and updates the order status accordingly.

If webhooks are missing, misconfigured, or blocked, WooCommerce never receives payment confirmation. As a result, payments stay in a “pending” state. Additionally, if WordPress cron jobs are disabled or not running, scheduled tasks that check payment statuses and update orders won’t execute, causing delays or stuck statuses.

Step-by-Step: Fix WooCommerce Stripe Pending Payments

  1. Verify your webhook URL in Stripe:
    https://yourdomain.com/?wc-api=wc_stripe

    This URL must be publicly accessible and use HTTPS.

  2. Create or update the webhook in Stripe:
    • Log in to Stripe Dashboard > Developers > Webhooks
    • Click Add endpoint
    • Enter the URL above
    • Select these events:
      payment_intent.succeeded
      payment_intent.payment_failed
      charge.refunded
      charge.failed
      checkout.session.completed
    • Save and copy the webhook secret key
  3. Add the webhook secret to WooCommerce:
    1. Go to WordPress Admin > WooCommerce > Settings > Payments > Stripe
    2. Find the Webhook secret field
    3. Paste the copied webhook secret
    4. Save changes
  4. Ensure WordPress cron is running:
    • Install the WP Crontrol plugin
    • Go to Tools > Cron Events and check for WooCommerce scheduled tasks like woocommerce_scheduled_subscription_payment or woocommerce_cancel_unpaid_orders
    • If cron is disabled, enable it by editing wp-config.php and removing or setting define('DISABLE_WP_CRON', false);
    • Alternatively, set up a real server cron job to call wp-cron.php every 5-10 minutes:
    * * * * * wget -q -O - https://yourdomain.com/wp-cron.php?doing_wp_cron /dev/null 2&1
  5. Manually trigger webhook events or wait for cron:
    • In Stripe Dashboard, you can resend webhook events to test
    • Wait for WordPress cron to run and update order statuses
    • Check WooCommerce orders to confirm payment status updates

Checking Logs for Troubleshooting

Logs help identify webhook delivery issues or errors in payment processing.

  • Stripe Logs: In Stripe Dashboard, go to Developers > Logs to see webhook delivery status and errors.
  • WooCommerce Logs: Go to WooCommerce > Status > Logs, select the Stripe log file (e.g., stripe-YYYY-MM-DD.log), and review recent entries.
  • Server Logs: Check your web server error logs for any 4xx or 5xx errors related to the webhook URL.

Works on

Environment Notes
Apache Ensure mod_rewrite is enabled and .htaccess rules allow webhook URL access.
Nginx Configure location blocks to allow access to ?wc-api=wc_stripe endpoint.
LiteSpeed Compatible with Apache .htaccess; verify rewrite rules.
cPanel / Plesk Supports cron jobs and SSL setup needed for webhooks.
Managed WordPress Hosting Check with host if WP cron is disabled and request real cron setup.

FAQ

Q: How do I know if Stripe webhooks are working?
A: Check the Stripe Dashboard under Developers > Webhooks for recent delivery attempts and their status. Successful deliveries show a green checkmark.
…
WooCommerce How‑tos

WooCommerce: Create tiered shipping by product category

Posted on August 19, 2025August 19, 2025 By Admin No Comments on WooCommerce: Create tiered shipping by product category

WooCommerce: Create Tiered Shipping by Product Category

If you run a WooCommerce store, you might want to charge different shipping rates based on product categories. For example, electronics might have a different shipping cost than clothing, or you might want to offer tiered shipping rates depending on the category and order quantity. WooCommerce doesn’t provide tiered shipping by category out of the box, but with a few simple steps, you can set this up quickly.

Quick Fix: Use Shipping Classes and Shipping Zones with Rules

  1. Create shipping classes corresponding to your product categories.
  2. Assign these shipping classes to products in each category.
  3. Set up shipping zones and add flat rate shipping methods.
  4. Configure tiered shipping costs per shipping class using cost formulas.

This approach leverages WooCommerce’s built-in shipping classes and flat rate shipping method cost formulas to simulate tiered shipping by product category without custom coding.

Why This Happens

WooCommerce’s default shipping system calculates shipping costs based on shipping zones and methods. Shipping classes allow grouping products for shipping cost differentiation, but WooCommerce does not natively support tiered or quantity-based shipping rates by category. By assigning shipping classes that mirror categories and using cost formulas, you can create tiered shipping rates that vary by category and quantity.

This method works because the flat rate shipping method supports cost formulas using placeholders like [qty] (quantity of items) and [cost] (base cost). By combining these with shipping classes, you can create tiered costs per category.

Step-by-step: Create Tiered Shipping by Product Category

  1. Create Shipping Classes
    • Go to WooCommerce > Settings > Shipping > Shipping classes.
    • Click Add shipping class for each product category you want to tier. For example:
      • Electronics
      • Clothing
      • Books
    • Save shipping classes.
  2. Assign Shipping Classes to Products
    • Go to Products > All Products.
    • Edit each product and assign the appropriate shipping class under the Shipping tab.
    • Update products.
  3. Set Up Shipping Zones
    • Go to WooCommerce > Settings > Shipping > Shipping zones.
    • Create or edit a shipping zone that applies to your customers (e.g., United States).
    • Add a Flat rate shipping method to this zone.
  4. Configure Tiered Shipping Costs Per Shipping Class
    • Click Edit on the flat rate shipping method.
    • Set the Cost field for the base rate (e.g., 5 for $5 base shipping).
    • Expand the Shipping class costs section.
    • For each shipping class, enter a cost formula that applies tiered rates. For example:
      • Electronics: 10 + ([qty] - 1) * 3 (first item $10, each additional $3)
      • Clothing: 5 + ([qty] - 1) * 1.5 (first item $5, each additional $1.50)
      • Books: 3 + ([qty] - 1) * 1 (first item $3, each additional $1)
    • Save changes.
  5. Test Your Setup
    • Add products from different categories to your cart.
    • Verify the shipping cost updates according to your tiered rules.

Edge Cases and Additional Tips

  • Multiple Categories per Product: WooCommerce shipping classes are single-select, so if a product belongs to multiple categories, assign the shipping class that best fits your shipping cost strategy.
  • Combining Shipping Classes: WooCommerce sums shipping class costs by default, so if your cart contains multiple classes, the total shipping cost will be the sum of each class’s tiered cost.
  • Free Shipping Thresholds: To offer free shipping for certain categories or order totals, add a Free shipping method to your shipping zone with conditions.
  • Using Plugins: For more complex tiered shipping rules (e.g., weight, volume, or mixed conditions), consider plugins like Table Rate Shipping or Advanced Shipping Packages.

Works On

Environment Compatibility
Web Servers Apache, Nginx, LiteSpeed
Control Panels cPanel, Plesk, DirectAdmin
WooCommerce Versions WooCommerce 3.0 and above
WordPress Versions WordPress 5.0 and above

FAQ

  1. Can I set different tiered shipping rates for multiple categories in one order?

    Yes. WooCommerce sums the shipping costs for each shipping class in the cart, so tiered rates per category will combine automatically.

  2. What if a product belongs to multiple categories?

    Since shipping classes are single-select, assign the shipping class that best matches the shipping cost. For complex cases, consider plugins that support multiple shipping classes or custom rules.

  3. Can I use weight or dimensions in tiered shipping calculations?

    Not with the default flat rate method. For weight or dimension-based tiered shipping, use advanced shipping plugins like Table Rate Shipping.

…
WooCommerce How‑tos

WooCommerce: Force NZD & hide other currencies

Posted on August 19, 2025August 19, 2025 By Admin No Comments on WooCommerce: Force NZD & hide other currencies

WooCommerce: Force NZD & Hide Other Currencies

If you run a WooCommerce store and want to restrict all transactions to New Zealand Dollars (NZD) while hiding other currencies from your customers, this guide will help. By default, WooCommerce allows multiple currencies through plugins or custom setups, but sometimes you need to enforce a single currency for consistency in pricing, accounting, or payment processing.

This tutorial shows you how to force NZD as the only currency on your WooCommerce store and hide any other currencies that might be available. The solution involves adding simple code snippets to your theme or a custom plugin, ensuring your store always displays and processes payments in NZD.

Quick Fix: Force NZD & Hide Other Currencies

  1. Add a filter to force WooCommerce currency to NZD.
  2. Remove or disable any multi-currency switchers or plugins.
  3. Optionally, hide currency switcher UI elements if present.
add_filter( 'woocommerce_currency', 'force_woocommerce_currency_to_nzd' );
function force_woocommerce_currency_to_nzd() {
    return 'NZD';
}

This snippet forces WooCommerce to always use NZD as the currency, regardless of user location or any other settings.

Why This Happens

WooCommerce allows currency to be set dynamically, especially when using multi-currency plugins or custom code. These setups can detect user location or preferences and switch currencies accordingly. However, if you want to standardize your store to a single currency (NZD), you need to override this behavior.

Without forcing NZD, customers might see prices in different currencies, which can cause confusion, pricing errors, or payment gateway mismatches. Also, some payment gateways require a consistent currency to function properly.

Step-by-step: Force NZD and Hide Other Currencies

  1. Backup your site. Before making changes, always backup your WordPress files and database.
  2. Access your theme’s functions.php or create a site-specific plugin. You can add the code snippet below to your child theme’s functions.php file or create a custom plugin to keep changes safe from theme updates.
  3. Add the currency filter:
add_filter( 'woocommerce_currency', 'force_woocommerce_currency_to_nzd' );
function force_woocommerce_currency_to_nzd() {
    return 'NZD';
}
  1. Disable multi-currency plugins or features. If you use plugins like WooCommerce Multi-Currency, Currency Switcher, or similar, deactivate or configure them to disable other currencies.
  2. Hide any currency switcher UI elements. If your theme or plugins add currency switchers, remove or hide them via CSS or plugin settings to avoid confusion.
  3. Test your store. Visit your site in incognito mode or different browsers to confirm prices always show in NZD and no other currencies appear.

Payment Gateways

Forcing NZD currency ensures compatibility with payment gateways that require a fixed currency. WooCommerce’s default gateways and popular ones like Stripe and WooPayments support NZD without issues.

If you use Stripe or WooPayments, confirm your Stripe account supports NZD payouts. WooPayments automatically detects the store currency, so forcing NZD avoids currency mismatch errors during checkout.

Works on

  • Web servers: Apache, Nginx, LiteSpeed
  • Hosting panels: cPanel, Plesk, and others
  • WooCommerce versions 4.x and 5.x+
  • Payment gateways: Stripe, WooPayments, PayPal (with NZD support)
  • Compatible with most themes and child themes

FAQ

Q: Will this code affect my multi-currency plugin?
A: Yes. This code overrides WooCommerce’s currency setting globally. You should disable or configure your multi-currency plugin accordingly to avoid conflicts.
Q: Can I force other currencies using the same method?
A: Absolutely. Replace 'NZD' with any valid WooCommerce currency code like 'USD', 'EUR', etc.
Q: What if I want to allow customers to see prices in other currencies but pay in NZD?
This requires a more complex setup with multi-currency plugins that support separate display and payment currencies. The code above forces both display and payment currency to NZD.
Q: Will this affect tax calculations?
No. WooCommerce tax settings remain unchanged. However, ensure your tax rates are configured correctly for NZD pricing.
Q: How do I remove currency switcher widgets from my site?
Check your theme widgets or plugin settings. You can also hide switchers with CSS, for example:
.currency-switcher, .woocommerce-currency-switcher { display: none !important; }
…
WooCommerce How‑tos

Posts pagination

Previous 1 2

Recent Posts

  • Top WordPress Themes for Blogs in 2025
  • WordPress Admin Panel Trick: Adding ID Field to the Posts Listing
  • Solution previous_posts_link and next_posts_link Not Working
  • Show Top Commentators in WordPress Without a Plugin
  • How to Style Admin Comments in WordPress

Recent Comments

    Archives

    • August 2025

    Categories

    • Admin & Blocks
    • Admin & UI
    • Automation
    • Automation & Plugins
    • Comments
    • Comparisons
    • Database & Revisions
    • Developer Snippets
    • Fixes & Errors
    • Media & Thumbnails
    • Queries & Pagination
    • Security
    • Speed & Security
    • Tips & Tricks
    • WooCommerce How‑tos
    • WordPress Snippets
    • WordPress Themes
    • Terms & Conditions
    • Affiliate Disclosure

    Copyright © 2025 wpcanyon.com.

    Powered by PressBook WordPress theme

    Also by the maker of MySurveyReviews.com