Zum Inhalt springen

Configuration

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

Anchor is configured on one screen: WooCommerce → Anchor. The bar shows only on single product pages, and the screen has just two controls. Both live in the array option anchor_settings, and both are sanitised and clamped on save by a manage_woocommerce-gated form (so shop managers can save, not only administrators).

The master toggle, stored as enabled (default true). When on, the bar renders on single product pages. When off, the bar never renders and its CSS and JS are not enqueued, there is no orphaned markup and no front-end weight. A fresh install seeds this on, so the bar works immediately.

Stored as scroll_threshold (default 300), an integer in pixels. It is the distance past the native add-to-cart form the shopper must scroll before the bar reveals:

  • Range is 0 to 5000, in steps of 10. Values outside the range are clamped on save (negative becomes 0, over 5000 becomes 5000).
  • A lower value shows the bar sooner; a higher value keeps it hidden longer.
  • The value is passed to the front-end script as anchorConfig.scrollThreshold and used as the IntersectionObserver’s negative top root margin, so the bar appears once the main form has scrolled that many pixels off the top of the viewport.

These are deliberately not settings, because they keep the bar correct and slim:

  • Position is always the bottom edge. The bar is position: fixed; bottom: 0. There is no top option.
  • No per-device toggle. The bar runs on every viewport where it is enabled. (A max-width: 768px rule only tightens spacing on small screens; it does not hide the bar.)
  • The bar shows title, price and button only. There is no thumbnail and no quantity field. On variable products a Choose options button stands in for the button until a variation is selected.
  • It renders on woocommerce_after_single_product (priority 20), so the markup sits after the native form in source order; CSS then fixes it to the viewport. There is no shortcode and no manual placement, the bar is automatic.

The bar quietly renders nothing (rather than a broken control) when:

  • the plugin is disabled, or WooCommerce is inactive, or the page is not a single product page;
  • the product cannot be loaded as a WC_Product;
  • the product is not purchasable and is not a variable product, for example an external/affiliate product without a price. Variable products always render so the shopper can still reach the selectors.

For a simple product that is out of stock or otherwise not purchasable but still a valid product, the bar shows a link button using WooCommerce’s own add-to-cart text (for example Read more) instead of a submit button.

On variable products the bar is variation-aware with no setting. The front-end script listens to WooCommerce’s native found_variation, reset_data and hide_variation jQuery events. When a variation is found it copies that variation’s price_html into the bar, sets the resolved variation_id on the bar’s hidden form, and enables the add button only if the variation is purchasable and in stock. Anchor adds no jQuery of its own, it uses the copy WooCommerce already loads, and if that copy is absent the bar simply stays in its safe Choose options state.

The bar’s styles are built on --anchor-* custom properties, surface and ink colours, the brass accent, radius, gap and padding, so a theme can re-skin Anchor without overriding selectors. The surface and text colours fall back to your theme’s --wp--preset--color--contrast and --wp--preset--color--base where they exist, and the whole palette switches under prefers-color-scheme: light. There is no template override path: the markup is rendered from the plugin’s bundled templates/sticky-bar.php and is not loaded from the theme, so restyle with CSS rather than copying a template.

Anchor stores exactly two options in your own database and contacts no external service:

  • anchor_settings, the array above (enabled, scroll_threshold).
  • anchor_db_version, the schema marker used by the on-boot migrator to seed defaults once.

There is no per-product data and no custom table. Deleting the plugin runs uninstall.php, which removes both options. Nothing else is left behind.

Two extension points let an add-on render its own fields into the same settings screen and option, plus a storefront visibility filter. (These are the merchant/developer-facing hooks; the plugin’s internal boot wiring is not part of the public surface.)

anchor_admin_settings_after_cards, an action fired inside the settings form, after the core card and before the submit button. Receives the resolved settings array and the option name.

add_action( 'anchor_admin_settings_after_cards', function ( array $settings, string $option ) {
?>
<div class="anchor-card">
<h2><?php esc_html_e( 'My add-on', 'my-addon' ); ?></h2>
<label>
<input type="checkbox" name="<?php echo esc_attr( $option ); ?>[my_flag]" value="1"
<?php checked( ! empty( $settings['my_flag'] ) ); ?> />
<?php esc_html_e( 'Enable my feature', 'my-addon' ); ?>
</label>
</div>
<?php
}, 10, 2 );

anchor_sanitize_settings, a filter applied to the sanitised settings before save. The core sanitiser keeps only enabled and scroll_threshold, so an add-on must re-attach its own keys here or they are dropped.

add_filter( 'anchor_sanitize_settings', function ( array $clean, array $raw ) {
$clean['my_flag'] = ! empty( $raw['my_flag'] );
return $clean;
}, 10, 2 );

anchor/bar_visible, a filter evaluated in StickyBar::shouldRender() after the enable toggle and is_product() checks. Return false to skip enqueuing assets and printing the bar on the current product page. Receives the resolved settings array and the current WC_Product (may be null before the global is set).

add_filter( 'anchor/bar_visible', function ( bool $visible, array $settings, ?WC_Product $product ): bool {
if ( ! $visible || ! $product instanceof WC_Product ) {
return $visible;
}
// Example: hide on products in the "clearance" category (term ID 42).
if ( in_array( 42, $product->get_category_ids(), true ) ) {
return false;
}
return $visible;
}, 10, 3 );