Skip to content

Keeping track of all the code snippets in the theme functions.php file can be too much. Moved them into a plugin.

Notifications You must be signed in to change notification settings

leoadhemartan/lt-wc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LT WC

Version: 0.1
Author: ltan.dev
Requires: WordPress 5.8+, WooCommerce 6.0+, PHP 8.4+
License: GPL v3 or later

Description

Custom WooCommerce extensions and payment gateway developed by ltan.dev. This plugin provides enhanced payment gateway functionality with configurable fees and custom messaging.

Features

Custom Order Payment Gateway

A flexible payment gateway based on WooCommerce BACS with enhanced features:

  • Configurable Frontend Name - Customize the payment method name shown to customers
  • Custom Success Message - Display a personalized message after successful order placement
  • Customizable Instructions - Add payment instructions on thank you page and emails
  • HPOS Compatible - Fully compatible with WooCommerce High-Performance Order Storage
  • Extensible - Provides filters and actions for developers

Conditional Fees

A powerful fee management system that applies surcharges based on payment methods:

  • Multiple Fees - Add unlimited conditional fees with different configurations
  • Payment Method Restrictions - Apply fees only to specific payment gateways
  • Fee Types:
    • Fixed amount fees (e.g., $5.00)
    • Percentage-based fees (e.g., 3.5%)
  • Tax Support - Make fees taxable or non-taxable
  • Smart Detection - Auto-applies fees when only one payment method is available
  • Admin UI - Intuitive drag-and-drop interface for managing fees
  • Enable/Disable - Toggle individual fees without deleting them

Installation

  1. Upload the lt-wc folder to the /wp-content/plugins/ directory
  2. Activate the plugin through the 'Plugins' menu in WordPress
  3. Go to WooCommerce > Settings > Payments
  4. Enable and configure "Custom Order Payment"

Configuration

Payment Gateway Settings

Navigate to WooCommerce > Settings > Payments > Custom Order Payment

General Settings

  • Enable/Disable - Toggle the payment gateway on/off
  • Title - Payment method name shown on checkout
  • Description - Brief description shown on checkout page
  • Instructions - Detailed instructions for thank you page and emails
  • Success Message - Custom message displayed after order completion

Conditional Fees Settings

Navigate to WooCommerce > LT WC

Configure payment method-based fees that apply automatically at checkout:

Adding a Fee

  1. Click "+ Add Fee" button
  2. Configure the fee settings:
    • Enabled - Toggle fee on/off
    • Fee Name - Name displayed to customers (e.g., "Credit Card Processing Fee")
    • Type - Choose Fixed or Percentage
    • Amount - Enter the fee value
    • Payment Methods - Select which payment methods trigger this fee (multi-select)
    • Taxable - Whether the fee should include tax

Managing Fees

  • Drag & Drop - Reorder fees using the drag handle
  • Remove - Delete fees with the Remove button
  • Enable/Disable - Toggle individual fees without deleting them

Examples

  • Credit Card Fee: 3.5% percentage fee for credit card gateways
  • Bank Transfer Discount: -5.00 fixed fee (discount) for bank transfers
  • Processing Fee: $2.50 fixed fee for all payment methods

Developer Documentation

Hooks & Filters

Actions

// Triggered when plugin initializes
do_action( 'lt_wc_init' );

Filters

// Modify gateway icon
apply_filters( 'lt_wc_custom_order_icon', string $icon_url );

// Modify default order status
apply_filters( 'lt_wc_custom_order_process_payment_order_status', string $status, WC_Order $order );

// Modify gateway availability
apply_filters( 'lt_wc_custom_order_is_available', bool $is_available, LT_WC_Gateway_Custom_Order $gateway );

// Modify conditional fees settings
apply_filters( 'woocommerce_get_settings_lt_wc', array $settings );

// Modify conditional fees data before saving
apply_filters( 'lt_wc_save_conditional_fees', array $fees );

Code Examples

Change Default Order Status

add_filter( 'lt_wc_custom_order_process_payment_order_status', function( $status, $order ) {
    // Change to 'processing' instead of 'on-hold'
    return 'processing';
}, 10, 2 );

Add Custom Gateway Icon

add_filter( 'lt_wc_custom_order_icon', function( $icon ) {
    return get_stylesheet_directory_uri() . '/images/payment-icon.png';
} );

Conditionally Disable Gateway

add_filter( 'lt_wc_custom_order_is_available', function( $is_available, $gateway ) {
    // Disable for orders over $1000
    if ( WC()->cart && WC()->cart->get_total( 'raw' ) > 1000 ) {
        return false;
    }
    return $is_available;
}, 10, 2 );

Add Custom Fee Logic

// Add a fee based on custom conditions
add_action( 'woocommerce_cart_calculate_fees', function() {
    if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
        return;
    }
    
    // Get chosen payment method
    $payment_method = WC()->session->get( 'chosen_payment_method' );
    
    // Add custom fee for specific gateway
    if ( 'custom_gateway_id' === $payment_method ) {
        WC()->cart->add_fee( __( 'Custom Fee', 'text-domain' ), 10.00, true );
    }
} );

Technical Details

Plugin Structure

lt-wc/
├── lt-wc.php                                    # Main plugin file
├── includes/
│   ├── admin/
│   │   └── class-lt-wc-admin-settings.php      # Admin settings page
│   ├── gateways/
│   │   └── class-lt-wc-gateway-custom-order.php # Custom Order Payment Gateway
│   └── class-lt-wc-conditional-fees.php        # Conditional fees manager
├── languages/                                    # Translation files
└── README.md                                     # Documentation

Coding Standards

  • Follows WordPress Coding Standards
  • Compatible with PHPCS WordPress ruleset
  • Security-first approach with proper escaping and sanitization
  • HPOS compatible using WooCommerce CRUD methods
  • Full i18n/l10n support

Security Features

  • ABSPATH guards on all PHP files
  • Output escaping with esc_html(), esc_attr(), esc_url()
  • Input sanitization with sanitize_text_field(), wc_clean()
  • Capability checks for admin operations
  • Nonce verification for form submissions
  • Safe text fields for user-configurable content

Changelog

0.1 - 2025-11-15

  • Initial release
  • Custom Order Payment Gateway with configurable options
  • Conditional Fees system with admin management UI
  • Support for fixed and percentage-based fees
  • Payment method-based fee restrictions
  • Customizable success messages and instructions
  • HPOS compatibility
  • Developer hooks and filters

Support

For support, feature requests, or bug reports, please contact ltan.dev

License

This plugin is licensed under GPL v3 or later.

Copyright (C) 2025 ltan.dev

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

About

Keeping track of all the code snippets in the theme functions.php file can be too much. Moved them into a plugin.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages