# niloydebb/wc-buy-now-button architecture

> Architecture diagram of the GitHub repository niloydebb/wc-buy-now-button, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/niloydebb/wc-buy-now-button
- Repository: https://github.com/niloydebb/wc-buy-now-button

## Overview

WC Buy Now Button is a WooCommerce plugin that adds configurable purchase buttons to product pages, archives, shortcodes, and Elementor layouts. The main shopper flow is button rendering, browser-side variation and quantity handling, a nonce-verified AJAX request, cart addition, then a cart or checkout redirect. Admin settings provide defaults and styling; shortcode and automatic template hooks use the shared renderer, while the Elementor widget renders its own markup. Some settings and widget wiring is inferred only from README or partial excerpts, so uncertain links are omitted.

Main entry points: [`wc-buy-now-button.php`](https://github.com/niloydebb/wc-buy-now-button/blob/main/wc-buy-now-button.php) (Plugin bootstrap), [`includes/class-wcbn-settings.php`](https://github.com/niloydebb/wc-buy-now-button/blob/main/includes/class-wcbn-settings.php) (Plugin settings), [`includes/class-wcbn-ajax.php`](https://github.com/niloydebb/wc-buy-now-button/blob/main/includes/class-wcbn-ajax.php) (Buy-now handler), [`includes/class-wcbn-shortcode.php`](https://github.com/niloydebb/wc-buy-now-button/blob/main/includes/class-wcbn-shortcode.php) (Shortcode)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_presentation["Button presentation"]
  node_shortcode["Shortcode"]
  node_autohooks["Product hooks"]
  node_renderer["Button renderer"]
  node_elementor["Elementor widget"]
end

subgraph group_purchase["Purchase processing"]
  node_browser["Button interaction<br/>[wcbn-script.js]"]
  node_ajax["Buy-now handler"]
end

subgraph group_configuration["Settings and assets"]
  node_settings["Plugin settings"]
  node_assets["Asset loader"]
  node_frontendcss["Button styles<br/>[wcbn-style.css]"]
  node_adminjs["Admin script<br/>[wcbn-admin.js]"]
end

subgraph group_platform["WordPress and WooCommerce"]
  node_bootstrap["Plugin bootstrap"]
  node_wcproducts["WooCommerce products"]
  node_cart["WooCommerce cart"]
  node_optionstore[("WordPress options")]
end

node_shopper(("Shopper"))
node_admin(("Store admin"))
node_destination["Cart or checkout"]
node_woocommerce["WooCommerce"]

node_woocommerce -->|"enables plugin"| node_bootstrap
node_bootstrap -->|"boots"| node_settings
node_bootstrap -->|"boots"| node_ajax
node_bootstrap -->|"boots"| node_shortcode
node_bootstrap -->|"boots"| node_autohooks
node_bootstrap -->|"boots"| node_assets
node_bootstrap -.->|"registers widget"| node_elementor
node_shopper -->|"uses shortcode"| node_shortcode
node_shortcode -->|"renders button"| node_renderer
node_shopper -->|"views product page"| node_autohooks
node_autohooks -->|"renders button"| node_renderer
node_shopper -->|"uses widget"| node_elementor
node_shortcode -->|"requests assets"| node_assets
node_renderer -->|"reads defaults"| node_settings
node_autohooks -->|"reads display options"| node_settings
node_settings -->|"stores settings"| node_optionstore
node_admin -->|"configures"| node_settings
node_admin -->|"uses settings UI"| node_adminjs
node_adminjs -->|"saves settings"| node_settings
node_settings -->|"loads admin script"| node_adminjs
node_assets -->|"loads script"| node_browser
node_assets -->|"loads styles"| node_frontendcss
node_browser -->|"posts purchase"| node_ajax
node_ajax -->|"validates product"| node_wcproducts
node_ajax -->|"adds product"| node_cart
node_ajax -->|"returns redirect URL"| node_destination
node_browser -->|"navigates"| node_destination

click node_bootstrap "https://github.com/niloydebb/wc-buy-now-button/blob/main/wc-buy-now-button.php"
click node_shortcode "https://github.com/niloydebb/wc-buy-now-button/blob/main/includes/class-wcbn-shortcode.php"
click node_autohooks "https://github.com/niloydebb/wc-buy-now-button/blob/main/includes/class-wcbn-hooks.php"
click node_renderer "https://github.com/niloydebb/wc-buy-now-button/blob/main/includes/class-wcbn-renderer.php"
click node_elementor "https://github.com/niloydebb/wc-buy-now-button/blob/main/elementor/class-wcbn-elementor-widget.php"
click node_browser "https://github.com/niloydebb/wc-buy-now-button/blob/main/public/js/wcbn-script.js"
click node_ajax "https://github.com/niloydebb/wc-buy-now-button/blob/main/includes/class-wcbn-ajax.php"
click node_settings "https://github.com/niloydebb/wc-buy-now-button/blob/main/includes/class-wcbn-settings.php"
click node_assets "https://github.com/niloydebb/wc-buy-now-button/blob/main/includes/class-wcbn-assets.php"
click node_frontendcss "https://github.com/niloydebb/wc-buy-now-button/blob/main/public/css/wcbn-style.css"
click node_adminjs "https://github.com/niloydebb/wc-buy-now-button/blob/main/public/js/wcbn-admin.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_shortcode,node_autohooks,node_renderer,node_elementor toneBlue
class node_browser,node_ajax toneAmber
class node_settings,node_assets,node_frontendcss,node_adminjs toneMint
class node_bootstrap,node_wcproducts,node_cart,node_optionstore toneRose
class node_shopper,node_admin,node_destination,node_woocommerce toneIndigo
```

## Components

### Button presentation

- [Shortcode](https://github.com/niloydebb/wc-buy-now-button/blob/main/includes/class-wcbn-shortcode.php): `includes/class-wcbn-shortcode.php`
- [Product hooks](https://github.com/niloydebb/wc-buy-now-button/blob/main/includes/class-wcbn-hooks.php): `includes/class-wcbn-hooks.php`
- [Button renderer](https://github.com/niloydebb/wc-buy-now-button/blob/main/includes/class-wcbn-renderer.php): `includes/class-wcbn-renderer.php`
- [Elementor widget](https://github.com/niloydebb/wc-buy-now-button/blob/main/elementor/class-wcbn-elementor-widget.php): `elementor/class-wcbn-elementor-widget.php`

### Purchase processing

- [Button interaction](https://github.com/niloydebb/wc-buy-now-button/blob/main/public/js/wcbn-script.js): `public/js/wcbn-script.js`
- [Buy-now handler](https://github.com/niloydebb/wc-buy-now-button/blob/main/includes/class-wcbn-ajax.php): `includes/class-wcbn-ajax.php`

### Settings and assets

- [Plugin settings](https://github.com/niloydebb/wc-buy-now-button/blob/main/includes/class-wcbn-settings.php): `includes/class-wcbn-settings.php`
- [Asset loader](https://github.com/niloydebb/wc-buy-now-button/blob/main/includes/class-wcbn-assets.php): `includes/class-wcbn-assets.php`
- [Button styles](https://github.com/niloydebb/wc-buy-now-button/blob/main/public/css/wcbn-style.css): `public/css/wcbn-style.css`
- [Admin script](https://github.com/niloydebb/wc-buy-now-button/blob/main/public/js/wcbn-admin.js): `public/js/wcbn-admin.js`

### WordPress and WooCommerce

- [Plugin bootstrap](https://github.com/niloydebb/wc-buy-now-button/blob/main/wc-buy-now-button.php): `wc-buy-now-button.php`
- **WooCommerce products**
- **WooCommerce cart**
- **WordPress options**

### Other components

- **Shopper**
- **Store admin**
- **Cart or checkout**
- **WooCommerce**

## Connections

- WooCommerce → Plugin bootstrap: enables plugin
- Plugin bootstrap → Plugin settings: boots
- Plugin bootstrap → Buy-now handler: boots
- Plugin bootstrap → Shortcode: boots
- Plugin bootstrap → Product hooks: boots
- Plugin bootstrap → Asset loader: boots
- Plugin bootstrap → Elementor widget: registers widget
- Shopper → Shortcode: uses shortcode
- Shortcode → Button renderer: renders button
- Shopper → Product hooks: views product page
- Product hooks → Button renderer: renders button
- Shopper → Elementor widget: uses widget
- Shortcode → Asset loader: requests assets
- Button renderer → Plugin settings: reads defaults
- Product hooks → Plugin settings: reads display options
- Plugin settings → WordPress options: stores settings
- Store admin → Plugin settings: configures
- Store admin → Admin script: uses settings UI
- Admin script → Plugin settings: saves settings
- Plugin settings → Admin script: loads admin script
- Asset loader → Button interaction: loads script
- Asset loader → Button styles: loads styles
- Button interaction → Buy-now handler: posts purchase
- Buy-now handler → WooCommerce products: validates product
- Buy-now handler → WooCommerce cart: adds product
- Buy-now handler → Cart or checkout: returns redirect URL
- Button interaction → Cart or checkout: navigates
