Contents
WooCommerce
The most widespread online shop — a WordPress plugin: products, the cart, orders, payment and shipping.
1.Getting started
- What WooCommerce isMeet WooCommerce: a shop plugin for WordPress, what it adds to the site, what it consists of and what you need to know before starting.
- Installation and first setupHow to install WooCommerce, go through the setup wizard, add the first product and check the shop pages.
- Where data is storedWhere WooCommerce keeps products, orders, customers and settings, what HPOS is and how to reach the data through the WC() object and functions.
- Your own plugin for customizationsHow to create the acme-shop plugin for shop code: the header, the WooCommerce check, the file layout, the HPOS compatibility declaration and where code must not go.
- Hooks: actions and filtersA hooks refresher with WooCommerce examples: how an action differs from a filter, what priority and argument count are and how to find the hook you need.
2.Products
- The product object: readingHow to get a product in code with wc_get_product and read its properties: name, price, SKU, stock, image and link.
- Changing and creating productsHow to change a product with set methods and save, create products in code and keep your own data in product meta.
- Product types and variationsSimple, variable, grouped and external products in WooCommerce: how to tell the product type, read variations and create a variation in code.
- Categories, tags and attributesWooCommerce product taxonomies: product_cat categories, product_tag tags, global pa_ attributes, reading terms with wc_get_product_terms and assigning them to a product.
- Querying productsHow to select products in code: the wc_get_products function, its parameters, pagination, the WC_Product_Query class and searching by your own meta data.
- Custom product fields in the admin panelHow to add your own field to the WooCommerce product editor, save its value, show it in the storefront and as a column in the product list.
3.The storefront
- Catalog and product page hooksHow WooCommerce pages are built: a map of hooks and priorities on the product page and in the catalog, adding, removing and moving blocks.
- The theme: WooCommerce support and stylesHow to create a child theme for the shop, declare WooCommerce support, enqueue your own styles and use the body classes of shop pages.
- Template overridesHow to change a WooCommerce template with a copy in the theme's woocommerce folder, how to render your plugin's own template with wc_get_template and how to track outdated copies.
- Block and classic cart and checkoutHow the block-based WooCommerce cart and checkout pages differ from the classic shortcodes, which hooks work where and how to tell and switch the variant.
4.Cart and checkout
- The cartThe WC()->cart object: how to read items and totals, add and remove a product in code and validate adding to the cart.
- Fees, discounts and the price in the cartHow to add a fee or a discount to the WooCommerce cart with add_fee and change a product's price in the cart with the woocommerce_before_calculate_totals hook.
- Cart item dataHow to carry your own data from the product page into the cart and on into the order: an engraving field, the woocommerce_add_cart_item_data filter and order item meta.
- Checkout fields and validationHow to remove, change and add fields of the classic WooCommerce checkout form, validate input, save a value into the order and what to do in the block checkout.
- CouponsWooCommerce coupons in code: the WC_Coupon object, creating a coupon programmatically, applying it to the cart and a custom condition with the woocommerce_coupon_is_valid filter.
- Price formatting and taxesHow to print prices in WooCommerce: the wc_price function, the shop currency, prices with and without tax through wc_get_price_including_tax and the tax settings.
5.Orders and customers
- Orders: readingThe WC_Order object: how to get an order, read totals, addresses and items and find orders with wc_get_orders.
- Order statusesWooCommerce order statuses, how to change a status in code, which hooks fire on a change and how to add your own status.
- Creating and changing orders, HPOSHow to create an order in code with wc_create_order, change it, keep your own data in order meta and which rules the HPOS storage dictates.
- Customers and the My account areaThe WC_Customer object: reading and changing customer data, your own meta data and adding a tab to the My account area.
- Shop emailsHow WooCommerce emails work: setup in the admin panel, changing the subject and heading with filters, adding content through hooks and overriding an email template.
- A custom emailHow to add your own email to WooCommerce: a class based on WC_Email, an email template in the plugin, registration and sending on an order status change.
6.Settings, payment and shipping
- Your own shop settingsHow to add a section or your own tab to the WooCommerce settings page, describe fields with an array and read saved values with get_option.
- A payment methodHow to write a WooCommerce payment gateway: a class based on WC_Payment_Gateway, settings, the process_payment method, redirecting to the bank page and handling its notification.
- A shipping methodHow to write your own WooCommerce shipping method: a class based on WC_Shipping_Method, shipping zones, instance settings, the calculate_shipping method and the rates filter.
7.Integrations and launch
- The REST APIThe WooCommerce REST API: access keys, product and order endpoints, reading and changing data over HTTP, your own field in a response and a custom route.
- WebhooksWooCommerce webhooks: how to set up sending shop events to an external address, what arrives in the request, how to verify the signature and create a webhook in code.
- Background jobs: Action SchedulerHow to run long work in the background with Action Scheduler in WooCommerce: one-off, delayed and recurring jobs, viewing the queue in the admin panel and running it from the console.
- WP-CLI commandsManaging a WooCommerce shop from the console: wp wc commands for products, orders and customers, service tools and your plugin's own command.
- Performance, caching and launchWhat to check before launching a WooCommerce shop: which pages must not be cached, how not to slow the shop with your own code, the system scheduler and a checklist.