WooCommerce Integration for Developers
Templates
Two templates draw the shop part. Copy one into your theme to change it (a child theme is looked
at first); the plugin’s own is used when there is no copy.
| Template | Theme path | Used for |
|---|---|---|
picker.php | yourtheme/baza-booking-calendar/woocommerce/picker.php | the date/time picker on a booking product’s page |
cart-summary.php | yourtheme/baza-booking-calendar/woocommerce/cart-summary.php | what is booked, under a line of the classic cart and checkout |
Each template receives its data as $args (documented at the top of the file). The path can also be
changed with apply_filters( 'baza_bc_woocommerce_template', $file, $name, $args ).
The picker’s skeleton
The script (modules/woocommerce/assets/woo-picker.js) looks up its places by data-bbc-role and
stops with a console error when one is missing. Required roles:
prev, next, title, grid, slots, extras, total, book, note
Tags, classes, order and anything you add around them are yours. The rows the script draws inside
the roles carry fixed classes you can style: bbc-woo-picker__day (with .is-picked),__slot (.is-picked), __time, __price, __extra, __extras-toggle, __qty, __step,__veil (the loading overlay, blockUI blockOverlay).
CSS variables on .bbc-woo-picker (the script sets the first four from the theme’s own
Add to cart button): --bbc-woo-accent, --bbc-woo-on-accent, --bbc-woo-radius,--bbc-woo-ink, --bbc-woo-gap.
The block cart
The Cart and Checkout blocks (and the mini cart) flatten a line’s details to plain text, so the
summary template is not used there: a line gets one row per day and per extra instead. Change those
rows with the baza_bc_woocommerce_item_rows filter.
Filters and actions
| Hook | Purpose |
|---|---|
baza_bc_woocommerce_template (filter) | Path of a template: ( $file, $name, $args ). |
baza_bc_woocommerce_summary_data (filter) | What the cart summary is made of: ( array $data { days, extras }, array $input ). |
baza_bc_woocommerce_item_rows (filter) | Plain rows of a line (block cart, mini cart, order line): ( array $rows { key, value }, array $input ). |
baza_bc_woocommerce_product_dates (action) | Fired on a booking product’s page where the picker is drawn; ( WC_Product $product ). Draw your own picker here instead (remove the plugin’s with remove_action( ..., [ 'BazaBookingCalendar\BBC_Woo_Cart', 'render_calendar' ] )). |
baza_bc_woocommerce_offline_methods (filter) | Gateway ids that mean “pays later”: default bacs, cheque, cod. |
baza_bc_woocommerce_paid_on_completion (filter) | Gateway ids whose order is paid only when completed (processing is not money): default cod. |
baza_bc_woocommerce_send_shop_emails (filter) | true to send the shop’s own customer emails for booking orders (off by default). |
baza_bc_price_journal_recorded (action) | A price change was written: ( $booking_id, array $entry ). |
baza_bc_internal_booking_meta_prefixes (filter) | Meta key prefixes hidden from the booking panel, letters and calendar events (default bbc_, woo_; keys starting with _ are always hidden). |
What happens, in code
- Product page.
BBC_Woo_Cart::render_calendar()enqueues the picker and printsviews/picker.php. The picker asks the server (publicadmin-ajax.phpactions, no nonce, read-only except the last, which is what a shop’s own add-to-cart link does):
baza_bc_woo_days(product,month=YYYY-MM): days with something free;baza_bc_woo_slots(product,date): that day’s free hours with prices;baza_bc_woo_extras(product): the additional services of the service;baza_bc_woo_quote(product,slots[],extras[id]=qty): the total;baza_bc_woo_add(same): into the cart.
Step 1: Pricing
Always the server’s: BBC_Booking_Create::create( $input, [ 'quote' => true ] ) runs the checks and BBC_Booking_Calculate, and makes nothing. Only slot strings, extra ids and counts are read from the browser.
Step 2: Cart line
WC()->cart->add_to_cart() with line data bbc_booking = { input, total }. woocommerce_before_calculate_totals sets the line’s price (regular price too, no sale; tax status none, the amount is final). woocommerce_check_cart_items asks again at the cart and checkout; a taken time is an error notice, a moved price updates the line.
Step 3: Order
woocommerce_checkout_create_order keeps the forms on the order (meta _bbc_inputs, not on the line). woocommerce_checkout_order_processed / woocommerce_store_api_checkout_order_processed call BBC_Woo_Cart::create_bookings(): one booking per line through BBC_Booking_Create::create( $form, [ 'woo_order' => true ] ) (no gateway, no payment link), pending and holding its time. Order meta _bbc_booking_ids; booking meta woo_order_id. A line that cannot be made throws, which the checkout shows.
Step 4: Following the order
BBC_WooCommerce::order_status_changed(): paid -> booking booked (source woocommerce_webhook); on-hold or an offline method still unpaid -> stays pending; cancelled/failed -> pending bookings rejected; refunded -> booked ones rejected. A booking rejected in the plugin cancels an unpaid order when none of its bookings is left.
Booking meta written by the shop part
All hidden from the panel by the woo_ prefix.
woo_order_id, woo_payment_method (gateway id), woo_payment_title, woo_payment_state (paid, waiting, cancelled, failed, refunded), woo_payment_offline (1 for an offline method), woo_waiting_payment (time it went on hold). A WooCommerce coupon also sets promo_sale and coupon_code.
Price journal
BBC_Price_Journal::record( $booking_id, $kind, $reason, $before, $after, $by = [] ) writes one entry (booking meta bbc_price_journal, and the activity log’s “Price changed” row). $by is [ 'type' => admin|client|shop|system, 'user' => id, 'label' => text ]; omitted, it is whoever is signed in, else the system. BBC_Price_Journal::entries( $id ) reads them.
Licence and compatibility
- Feature key
woocommerce(in every plan) opens the gateway, product type, cart and import. Order status sync is not behind it. - HPOS and the Cart/Checkout blocks are declared compatible.
- Import from WooCommerce Bookings:
BBC_Woo_Import(WooCommerce -> Import bookings). Idempotent through meta_bbc_imported_from_wc.
