WooCommerce

Installation Methods

Install via WordPress Admin Dashboard

  • Navigate to Plugins → Add New
  • Search for WooCommerce
  • Click Install Now → Activate

Install via WP-CLI

wp plugin install woocommerce --activate

Manual Installation

  1. Download WooCommerce from the official repository
  2. Upload to /wp-content/plugins/
  3. Activate via WordPress admin

Initial Setup Wizard

After activation, WooCommerce provides a guided setup:

  • Store details (location, currency)
  • Payment methods
  • Shipping configuration
  • Recommended features

Updating WooCommerce

Update via Admin Dashboard

  • Go to Dashboard → Updates
  • Update WooCommerce like any plugin

Update via WP-CLI

wp plugin update woocommerce

Best Practices Before Updating

  • Backup database and files

  • Test on staging environment

  • Check compatibility with:

    • Theme
    • Plugins
    • PHP version

Handling Database Updates

WooCommerce may require database migrations after updates.

Trigger Database Update

if ( function_exists( 'wc_update_200_file_paths' ) ) {
    wc_update_200_file_paths();
}

Or via WP-CLI:

wp wc update

Version Check in Code

if ( defined( 'WC_VERSION' ) ) {
    echo WC_VERSION;
}

Settings & Options

WooCommerce settings are accessible via:

  • WooCommerce → Settings

General Settings

Key configurations:

  • Store address
  • Currency
  • Selling locations
  • Tax enable/disable

Example: Get Store Currency

$currency = get_woocommerce_currency();
echo $currency;

Products Settings

Controls:

  • Product types
  • Inventory
  • Downloadable products

Example: Check if Stock Management Enabled

if ( 'yes' === get_option( 'woocommerce_manage_stock' ) ) {
    // Stock management is enabled
}

Tax Settings

  • Enable taxes
  • Configure tax rates
  • Display prices (inclusive/exclusive)

Example: Check if Taxes Enabled

if ( wc_tax_enabled() ) {
    // Taxes are enabled
}

Shipping Settings

  • Shipping zones
  • Methods (Flat rate, Free shipping)
  • Classes

Example: Get Shipping Zones

$zones = WC_Shipping_Zones::get_zones();

foreach ( $zones as $zone ) {
    echo $zone['zone_name'];
}

Payments Settings

  • Enable/disable payment gateways
  • Configure gateways (e.g., COD, Stripe)

Example: Get Available Payment Gateways

$gateways = WC()->payment_gateways->get_available_payment_gateways();

foreach ( $gateways as $gateway ) {
    echo $gateway->id;
}

Accounts & Privacy

  • Guest checkout
  • Account creation
  • Data retention policies

Example: Check Guest Checkout Enabled

$guest_checkout = get_option( 'woocommerce_enable_guest_checkout' );

if ( 'yes' === $guest_checkout ) {
    // Guest checkout is enabled
}

Emails Settings

  • Configure transactional emails
  • Customize sender details

Example: Modify Email Sender Name

add_filter( 'woocommerce_email_from_name', function( $name ) {
    return 'My Store';
});

Advanced Settings

Includes:

  • Page setup (Cart, Checkout, My Account)
  • REST API configuration
  • Webhooks

Example: Get Checkout Page ID

$checkout_page_id = wc_get_page_id( 'checkout' );

Overriding Settings via Code

You can override WooCommerce options programmatically:

update_option( 'woocommerce_currency', 'INR' );

Using Filters & Hooks

Modify Currency Symbol

add_filter( 'woocommerce_currency_symbol', function( $symbol, $currency ) {
    if ( 'INR' === $currency ) {
        $symbol = '₹';
    }
    return $symbol;
}, 10, 2 );

Accessing WooCommerce Core Instance

$woocommerce = WC();