Setting Up WooCommerce for E-commerce on WordPress
WooCommerce is the most common e-commerce plugin for WordPress. Out of box it provides catalog, cart, checkout, order management, and basic analytics. But "out of box" is a template, not a store. Real store requires payment gateway setup, delivery services, taxes, notifications, and interface customization. Basic WooCommerce setup for Russian market takes 2–4 business days.
Installation and Initial Setup
wp plugin install woocommerce --activate
wp wc tool run install_pages --user=1 # creates shop/cart/checkout/account pages
Via WP CLI configure main parameters immediately:
wp option update woocommerce_default_country "RU"
wp option update woocommerce_currency "RUB"
wp option update woocommerce_currency_pos "right_space"
wp option update woocommerce_price_thousand_sep " "
wp option update woocommerce_price_decimal_sep ","
wp option update woocommerce_price_num_decimals "0"
wp option update woocommerce_calc_taxes "yes"
wp option update woocommerce_enable_guest_checkout "yes"
wp option update woocommerce_enable_checkout_login_reminder "yes"
Tax Rates for Russia
// Add tax rates programmatically
$tax_rates = [
[
'country' => 'RU',
'rate' => '20.0000',
'name' => 'VAT 20%',
'priority' => 1,
'compound' => false,
'shipping' => true,
'class' => '', // standard rate
],
[
'country' => 'RU',
'rate' => '10.0000',
'name' => 'VAT 10%',
'priority' => 1,
'compound' => false,
'shipping' => false,
'class' => 'reduced-rate',
],
];
foreach ($tax_rates as $rate) {
WC_Tax::_insert_tax_rate($rate);
}
Setting Up Shipping Methods
WooCommerce operates with shipping zones. Each zone can have several methods:
// Create zone for Russia
$zone = new WC_Shipping_Zone();
$zone->set_zone_name('Russia');
$zone->add_location('RU', 'country');
$zone_id = $zone->save();
// Add method — fixed cost
$instance_id = $zone->add_shipping_method('flat_rate');
$zone->save();
// Configure method via option
update_option("woocommerce_flat_rate_{$instance_id}_settings", [
'enabled' => 'yes',
'title' => 'Shipping to Russia',
'cost' => '350',
'free_min_amount' => '5000', // free over 5000 RUB
]);
Custom Checkout Fields
For Russian market often need additional fields: patronymic, INN for legal entities, delivery comment:
add_filter('woocommerce_checkout_fields', function (array $fields): array {
// Add patronymic
$fields['billing']['billing_patronymic'] = [
'label' => 'Patronymic',
'placeholder' => 'Ivanovna',
'required' => false,
'class' => ['form-row-last'],
'priority' => 25,
];
// INN for legal entities (show via JS when selecting payer type)
$fields['billing']['billing_inn'] = [
'label' => 'INN',
'required' => false,
'class' => ['form-row-wide', 'legal-field'],
'priority' => 90,
];
return $fields;
});
// Save custom fields to order meta
add_action('woocommerce_checkout_update_order_meta', function (int $order_id): void {
if (!empty($_POST['billing_patronymic'])) {
update_post_meta($order_id, '_billing_patronymic', sanitize_text_field($_POST['billing_patronymic']));
}
if (!empty($_POST['billing_inn'])) {
update_post_meta($order_id, '_billing_inn', sanitize_text_field($_POST['billing_inn']));
}
});
Payment Gateway Integration
For Russian market typical options: YooKassa (formerly Yandex.Kassa), Sberbank Acquiring, Tinkoff, Robokassa. Most have ready plugins; if not — implement via WC_Payment_Gateway:
class WC_My_Gateway extends WC_Payment_Gateway {
public function __construct() {
$this->id = 'my_gateway';
$this->method_title = 'My Gateway';
$this->has_fields = false;
$this->supports = ['products', 'refunds'];
$this->init_form_fields();
$this->init_settings();
$this->title = $this->get_option('title');
$this->api_key = $this->get_option('api_key');
$this->secret_key = $this->get_option('secret_key');
add_action('woocommerce_api_my_gateway_callback', [$this, 'process_callback']);
add_action('woocommerce_update_options_payment_gateways_' . $this->id, [$this, 'process_admin_options']);
}
public function process_payment(int $order_id): array {
$order = wc_get_order($order_id);
$amount = (int) ($order->get_total() * 100); // kopeks
$response = wp_remote_post('https://api.gateway.ru/create', [
'body' => json_encode([
'amount' => $amount,
'currency' => 'RUB',
'order_id' => $order_id,
'return_url' => $this->get_return_url($order),
'callback_url'=> home_url('/wc-api/my_gateway_callback'),
'description' => 'Order #' . $order->get_order_number(),
]),
'headers' => [
'Authorization' => 'Bearer ' . $this->api_key,
'Content-Type' => 'application/json',
],
]);
$data = json_decode(wp_remote_retrieve_body($response), true);
if (empty($data['payment_url'])) {
wc_add_notice('Payment initialization error. Try later.', 'error');
return ['result' => 'fail'];
}
$order->update_status('pending', 'Awaiting payment via gateway');
return [
'result' => 'success',
'redirect' => $data['payment_url'],
];
}
public function process_callback(): void {
$body = file_get_contents('php://input');
$payload = json_decode($body, true);
// Verify signature
$sign = hash_hmac('sha256', $payload['order_id'] . $payload['status'], $this->secret_key);
if (!hash_equals($sign, $payload['signature'])) {
status_header(403);
exit('Invalid signature');
}
$order = wc_get_order(absint($payload['order_id']));
if (!$order) exit('Order not found');
if ($payload['status'] === 'paid') {
$order->payment_complete($payload['payment_id']);
$order->add_order_note('Payment confirmed. Payment ID: ' . $payload['payment_id']);
} elseif ($payload['status'] === 'failed') {
$order->update_status('failed', 'Payment rejected by gateway');
}
status_header(200);
exit('OK');
}
}
add_filter('woocommerce_payment_gateways', function (array $gateways): array {
$gateways[] = 'WC_My_Gateway';
return $gateways;
});
Email Notifications
WooCommerce sends emails on order status change. Customize templates: copy from woocommerce/templates/emails/ to your-theme/woocommerce/emails/ and edit.
For custom manager notification:
add_action('woocommerce_order_status_processing', function (int $order_id): void {
$order = wc_get_order($order_id);
$manager = get_option('admin_email');
wp_mail(
$manager,
'New paid order #' . $order->get_order_number(),
sprintf(
"Customer: %s\nAmount: %s\nItems: %d\nAddress: %s",
$order->get_formatted_billing_full_name(),
wc_price($order->get_total()),
$order->get_item_count(),
$order->get_formatted_billing_address()
)
);
});
Typical timelines: WooCommerce "turnkey" setup with one payment gateway, delivery and email templates — 2–3 days. Multiple gateways, custom checkout fields, 1C/warehouse integration — 5–8 days.







