Skip to content

Extending the plugin

The plugin is built to be extended through filters rather than by editing or forking it. The Pro version is built the same way: it subclasses the public renderer and contributes through these seams.

  1. Source detection decides what a URL is: its extension, whether it is an embeddable service, and what embed URL it maps to. One class, WCDP_Document_Source, answers this for both the admin and the front end, so they cannot disagree about whether a link will render.
  2. Renderer resolution decides how a document is shown. PDFs render locally through pdf.js; other formats route to the Google viewer. WCDP_Renderer answers this.

Filter wcdp_document_sources to add a cloud service. Add a key with patterns (regular expressions), an embed_template, and a type. Do not ship a second detector; this is the one place detection lives.

Filter wcdp_supported_extensions to change which uploaded file types are eligible. Return the full list you want. Pro answers this filter to remove formats a store owner deselected, and preserves any format that setting never offered, so it does not discard other extensions on the hook.

Answer wcdp_renderer_for_document with your own renderer key, then handle that key when the preview URL is built. A local viewer, like the bundled pdf.js one, is what makes page limits, watermarks, and download protection possible, none of which can be done inside a third party iframe.

  • wcdp_preview_hook moves the automatic placement to a different WooCommerce action. The default fires inside the add to cart form; a fallback on woocommerce_single_product_summary at priority 35 catches products with no form, and renders only when nothing has rendered yet, so changing the filter does not produce two previews.
  • The shortcode and the block place the preview anywhere, including themes that never fire the WooCommerce hook.
  • wcdp_load_assets opts a page into the stylesheet and script.

wcdp_public_instance replaces the renderer object outright, which is how Pro takes over. Prefer a template override to reimplementing a render method: a theme override is silently dead if an extension re-authors the markup instead of using the template.

Read a product’s documents through WCDP_Documents::get( $product_id ), which returns a normalised list of name and url. It accepts both the current and the legacy Pro URL sub-key, so no store loses its documents across a free to Pro move.