PlusWaseDevelopers

Plugin hooks and templates

The PlusWase Hub plugin renders the catalog pages itself. A theme or a small plugin can change what they show, replace them, or use PlusWase data anywhere on the site.

Pages the plugin serves

AddressShows
/products/Every product published to the store (sort with ?sort=, search with ?q=).
/products/{slug}/One product: gallery, options, price, add to cart, description, related products.
/collection/{handle}/, /brand/{handle}/, /tag/{slug}/The products of one group.

Pages /page/2/ and on follow each listing. The products are also listed in WordPress's XML sitemap (/wp-sitemap-plw-1.xml).

Reading PlusWase data: plw_api_get()

plw_api_get(string $path, bool $bypass_cache = false, ?int &$status = null): ?array

Calls the catalog API with the store's key and returns the decoded answer, or null. Answers are cached for 30 minutes; when PlusWase cannot be reached the last good answer is served for up to 24 hours. Pass true as the second argument only when you need the live answer (the plugin does it at add to cart and checkout). $status receives the HTTP status of a live call (0 when PlusWase could not be reached).

$product = plw_api_get('/products/racing-hoodie-cotton-gildan');
$collections = plw_api_get('/collections');

Filters

FilterArgumentsUse
plw_api_response$data, $pathChange any catalog answer before it is cached and rendered.
plw_cache_ttl$seconds, $pathHow long an answer is cached (1800 by default).
plw_product_card_html$html, $itemThe HTML of one product card in a listing.
plw_product_page_data$productThe product a product page renders.
plw_listing_per_page$countProducts per listing page (12 by default, 48 at most).
plw_push_payload$payload, $orderThe order sent to PlusWase.

Actions

ActionArgumentsRuns
plw_before_product_page$productBefore the product page markup.
plw_after_product_summary$productUnder the add to cart button.
plw_order_pushed$order, $answerAfter PlusWase took an order in.

Replacing a template

Put a file in your theme and the plugin uses it instead of its own markup, between the theme's header and footer.

Theme fileVariables
pluswase-hub/listing.php$plw_listing (the /products answer), $plw_title, $plw_page
pluswase-hub/product.php$plw_product (the product)

A replacement product template must keep an add to cart that posts to admin-ajax.php with action=plw_add_to_cart, slug, vid (the variation id), qty and a plw_nonce nonce; the plugin re-checks price and stock with PlusWase before adding.

Example: tags and collections under the add to cart button

// In the theme's functions.php (or a small plugin).
add_action('plw_after_product_summary', function (array $product) {
    $links = [];
    foreach ($product['collections'] ?? [] as $c) {
        $links[] = '<a href="' . esc_url(home_url('/collection/' . $c['handle'] . '/')) . '">' . esc_html($c['title']) . '</a>';
    }
    foreach ($product['tags'] ?? [] as $t) {
        $links[] = '<a href="' . esc_url(home_url('/tag/' . $t['slug'] . '/')) . '">#' . esc_html($t['name']) . '</a>';
    }
    if ($links) echo '<p class="my-product-links">' . implode(' · ', $links) . '</p>';
});

// Show 24 products per listing page.
add_filter('plw_listing_per_page', fn() => 24);

Example: a collection on the home page

add_shortcode('plw_collection', function ($atts) {
    $handle = sanitize_title($atts['handle'] ?? '');
    $data = plw_api_get('/products?collection=' . rawurlencode($handle) . '&per_page=8');
    return $data ? plw_grid_html($data['items']) : '';
});
// Then in any page: [plw_collection handle="hoodie"]

Constants

ConstantDefaultMeaning
PLW_API_BASE, PLW_API_KEY, PLW_SHARED_SECRETunsetThe connection, set in wp-config.php instead of the settings page.
PLW_CACHE_TTL1800Seconds a catalog answer is cached.
PLW_STALE_TTL86400Seconds the last good answer is kept for outages.
PLW_HTTP_TIMEOUT8Seconds a catalog call may take.
PLW_PRICE_DRIFT_TOLERANCE0.005A price change smaller than this share leaves a cart's price as it is; a bigger one re-prices the line and tells the buyer.
PLW_NUMBER_POOL_SIZE, PLW_NUMBER_POOL_LOW20, 5Order numbers kept in reserve, and when to ask for more.

Order data the plugin keeps

Each WooCommerce order line sold from PlusWase keeps _plw_vid, _plw_sku, _plw_slug, _plw_image, _plw_permalink, _plw_product_sku and _plw_snapshot (the line as sold, in JSON). The order keeps _plw_order_number (the number buyers see) and, once PlusWase has it, _plw_remote_order_id.