WooCommerce

E-commerceWordPressPluginOpen SourceCustomizationPaymentsSEO

E-commerce Platform

WooCommerce

Overview

WooCommerce is a WordPress-based open-source e-commerce plugin. It easily adds e-commerce functionality to existing WordPress sites with high customizability. It continues to grow due to WordPress proliferation and is popular among cost-conscious SMEs due to open-source advantages and WordPress ecosystem integration.

Details

Released in 2011, WooCommerce is now used by over 5 million online stores worldwide. Since it runs on WordPress, it can directly utilize WordPress benefits (SEO, content management, rich themes and plugins). It's completely open source with basic features available for free, and paid extensions can be added as needed.

Key Features

  • WordPress Integration: Easy integration with existing WordPress sites
  • Open Source: Completely free for commercial use
  • High Customizability: Freely customizable with themes and plugins
  • SEO Friendly: Inherits WordPress's standard SEO features
  • Diverse Payment Options: Supports 100+ payment gateways
  • Multi-language & Multi-currency: Supports global business
  • Rich Extensions: Thousands of plugins for feature expansion
  • Developer Friendly: Flexible development with hooks and filters

Supported Payment Methods

  • PayPal, Stripe, Square
  • Credit card payments
  • Bank transfer, cash on delivery
  • Apple Pay, Google Pay
  • Buy-now-pay-later (Klarna, Afterpay, etc.)
  • Cryptocurrency payments

Pros and Cons

Pros

  • Free Usage: Basic features completely free
  • High Customization Freedom: Code-level modifications possible
  • Rich Resources: Abundant themes, plugins, and tutorials
  • Community Support: Active developer community
  • SEO Optimization: WordPress's standard SEO features
  • Ownership: Complete management control on own server
  • Data Control: Freedom in data export and migration

Cons

  • Technical Knowledge Required: Setup and maintenance require technical skills
  • Server Management: Responsibility for hosting, security, and backups
  • Performance: Affected by server performance and plugins
  • Security: Regular updates and measures required
  • Support: Official support only for paid extensions
  • Complexity: Plugin conflicts and version management

Reference Pages

Implementation Examples

1. Basic Setup

<?php
// Basic WooCommerce configuration
add_action('after_setup_theme', 'woocommerce_support');
function woocommerce_support() {
    add_theme_support('woocommerce');
    add_theme_support('wc-product-gallery-zoom');
    add_theme_support('wc-product-gallery-lightbox');
    add_theme_support('wc-product-gallery-slider');
}

// Currency and region settings
add_filter('woocommerce_currency', 'change_woocommerce_currency');
function change_woocommerce_currency() {
    return 'USD'; // US Dollar
}

// Tax settings
add_filter('woocommerce_calc_tax', '__return_true');

2. Product Catalog Management

<?php
// Programmatic product creation
function create_woocommerce_product() {
    $product = new WC_Product_Simple();
    
    // Basic information
    $product->set_name('New Product');
    $product->set_slug('new-product');
    $product->set_regular_price('29.99');
    $product->set_sale_price('24.99');
    $product->set_sku('PROD-001');
    
    // Description
    $product->set_short_description('Short product description');
    $product->set_description('Detailed product description');
    
    // Stock management
    $product->set_manage_stock(true);
    $product->set_stock_quantity(100);
    $product->set_stock_status('instock');
    
    // Categories and tags
    $product->set_category_ids([1, 2]);
    $product->set_tag_ids([1, 2, 3]);
    
    // Save
    $product_id = $product->save();
    return $product_id;
}

// Custom product fields
add_action('woocommerce_product_options_general_product_data', 'add_custom_product_fields');
function add_custom_product_fields() {
    woocommerce_wp_text_input([
        'id' => '_custom_field',
        'label' => 'Custom Field',
        'description' => 'Enter additional information',
        'type' => 'text'
    ]);
}

3. Payment Integration

<?php
// Custom payment gateway
class WC_Custom_Payment_Gateway extends WC_Payment_Gateway {
    public function __construct() {
        $this->id = 'custom_payment';
        $this->has_fields = true;
        $this->method_title = 'Custom Payment';
        $this->method_description = 'Custom payment gateway';
        
        $this->init_form_fields();
        $this->init_settings();
        
        $this->title = $this->get_option('title');
        $this->description = $this->get_option('description');
        
        add_action('woocommerce_update_options_payment_gateways_' . $this->id, 
                  array($this, 'process_admin_options'));
    }
    
    public function process_payment($order_id) {
        $order = wc_get_order($order_id);
        
        // Payment processing logic
        $payment_result = $this->process_payment_api($order);
        
        if ($payment_result['success']) {
            $order->payment_complete();
            return array(
                'result' => 'success',
                'redirect' => $this->get_return_url($order)
            );
        } else {
            wc_add_notice($payment_result['message'], 'error');
            return array('result' => 'fail');
        }
    }
}

// Stripe payment integration example
add_action('wp_enqueue_scripts', 'enqueue_stripe_scripts');
function enqueue_stripe_scripts() {
    if (is_checkout()) {
        wp_enqueue_script('stripe-js', 'https://js.stripe.com/v3/');
        wp_enqueue_script('custom-stripe', get_template_directory_uri() . '/js/stripe-checkout.js');
    }
}

4. Order Management

<?php
// Order creation customization
add_action('woocommerce_checkout_create_order', 'custom_checkout_create_order', 10, 2);
function custom_checkout_create_order($order, $data) {
    // Add custom fields to order
    $order->update_meta_data('_custom_order_field', 'Custom Value');
}

// Order status change processing
add_action('woocommerce_order_status_completed', 'send_custom_email');
function send_custom_email($order_id) {
    $order = wc_get_order($order_id);
    
    // Send custom email
    $to = $order->get_billing_email();
    $subject = 'Order Completion Notice';
    $message = 'Thank you for your order.';
    
    wp_mail($to, $subject, $message);
}

// Custom order data export
function export_orders_csv() {
    $orders = wc_get_orders(array(
        'limit' => -1,
        'status' => 'completed'
    ));
    
    $csv_data = array();
    $csv_data[] = array('Order ID', 'Customer Name', 'Total Amount', 'Order Date');
    
    foreach ($orders as $order) {
        $csv_data[] = array(
            $order->get_id(),
            $order->get_billing_first_name() . ' ' . $order->get_billing_last_name(),
            $order->get_total(),
            $order->get_date_created()->date('Y-m-d')
        );
    }
    
    return $csv_data;
}

5. Theme Customization

<?php
// Template override
add_action('woocommerce_single_product_summary', 'custom_product_content', 25);
function custom_product_content() {
    global $product;
    echo '<div class="custom-product-info">';
    echo '<p>Special Price: ' . wc_price($product->get_price()) . '</p>';
    echo '</div>';
}

// Shop page customization
add_action('woocommerce_before_shop_loop', 'custom_shop_header');
function custom_shop_header() {
    echo '<div class="custom-shop-header">';
    echo '<h2>Featured Products</h2>';
    echo '<p>Enjoy our carefully selected products.</p>';
    echo '</div>';
}

// Custom cart button
add_filter('woocommerce_product_add_to_cart_text', 'custom_add_to_cart_text');
function custom_add_to_cart_text() {
    return 'Add to Cart';
}

6. Analytics & SEO Optimization

<?php
// Google Analytics E-commerce tracking
add_action('woocommerce_thankyou', 'add_google_analytics_purchase_tracking');
function add_google_analytics_purchase_tracking($order_id) {
    $order = wc_get_order($order_id);
    
    if (!$order) return;
    
    echo '<script>';
    echo 'gtag("event", "purchase", {';
    echo '"transaction_id": "' . $order->get_id() . '",';
    echo '"value": ' . $order->get_total() . ',';
    echo '"currency": "' . $order->get_currency() . '",';
    echo '"items": [';
    
    foreach ($order->get_items() as $item) {
        $product = $item->get_product();
        echo '{';
        echo '"item_id": "' . $product->get_sku() . '",';
        echo '"item_name": "' . $item->get_name() . '",';
        echo '"quantity": ' . $item->get_quantity() . ',';
        echo '"price": ' . $item->get_total() . '';
        echo '},';
    }
    
    echo ']});';
    echo '</script>';
}

// Add structured data
add_action('wp_head', 'add_product_schema');
function add_product_schema() {
    if (is_product()) {
        global $product;
        
        $schema = array(
            '@context' => 'https://schema.org/',
            '@type' => 'Product',
            'name' => $product->get_name(),
            'description' => wp_strip_all_tags($product->get_description()),
            'image' => wp_get_attachment_url($product->get_image_id()),
            'offers' => array(
                '@type' => 'Offer',
                'price' => $product->get_price(),
                'priceCurrency' => get_woocommerce_currency(),
                'availability' => 'https://schema.org/InStock'
            )
        );
        
        echo '<script type="application/ld+json">';
        echo json_encode($schema);
        echo '</script>';
    }
}