Home โ€บ Modules โ€บ phyto_care_card

phyto_care_card

Generate downloadable PDF care guides per WooCommerce product โ€” light, water, humidity, temperature, media, dormancy โ€” served on-demand and optionally attached to order confirmation emails.

Plant Science v1.0.0 WooCommerce Browse Source on GitHub โ†—
modules/phyto-care-card/
Direct path in the repo โ†’ all PHP, SQL, templates, and assets
Open on GitHub โ†—

Overview

Phyto Care Card bridges the gap between selling a plant and ensuring the buyer can actually keep it alive. Specialty plant retailers โ€” particularly those selling tissue-culture deflasks, rare aroids, or carnivorous plants that need specific growing conditions โ€” frequently get post-purchase support requests simply because customers did not have access to the right care information at the right time.

This plugin solves that directly. An admin fills in a structured set of care fields (light, watering, humidity, temperature, potting media, fertilisation, dormancy notes, and special tips) on the product edit screen. A formatted A4 PDF care guide is built on demand from those fields โ€” no external library, no composer dependency, no third-party service. Customers can download it straight from the product page, and it can be automatically attached to the WooCommerce order completion email so they receive it the moment their order ships.


Care Fields

Fill in the Plant Care Card meta box on any product edit page:

Field NameMeta KeyTypeNotes
Light Requirements_phyto_cc_light_reqSelectFull Sun / Partial Shade / Bright Indirect / Low Light / Grow Light
Watering_phyto_cc_wateringTextFree text, e.g. “Water when top 2 cm dry”
Humidity_phyto_cc_humidityTexte.g. “60โ€“80% RH”
Temperature Min (ยฐC)_phyto_cc_temp_minNumberDecimal allowed
Temperature Max (ยฐC)_phyto_cc_temp_maxNumberDecimal allowed
Potting Media_phyto_cc_potting_mediaTexte.g. “Chunky bark + perlite 60/40”
Fertilisation_phyto_cc_fertilisationTexte.g. “Half-strength balanced NPK fortnightly”
Dormancy Notes_phyto_cc_dormancy_notesTextareaFull dormancy description
Special Care Tips_phyto_cc_special_tipsTextareaAcclimation notes, common mistakes, extras
Attach to Order Email_phyto_cc_attach_emailCheckboxAttach PDF to customer_completed_order email

The download button on the product page only appears when at least one care field is non-empty โ€” so products without care data are unaffected.


PDF Layout

The care guide is built as a raw PDF 1.4 document using PHP string concatenation. No external library or Composer dependency is required. Standard PDF fonts only: Helvetica and Helvetica-Bold.

Header bar โ€” Forest-green (#1a3c2b) rectangle spanning the full page width. “Plant Care Guide” is set in white Helvetica-Bold 18pt. The product name appears below in white Helvetica 13pt. “PhytoCommerce” branding sits in the top-right corner in sage (#7dab8a) at 8pt.

Two-column grid โ€” The six short fields are laid out in two columns of three rows each:

  • Left column: Light, Water, Humidity
  • Right column: Temperature, Potting Media, Fertilisation

Each pair shows the field label in Helvetica-Bold 9pt (forest green) followed by the value in Helvetica 9pt (black).

Full-width sections โ€” Dormancy Notes and Special Care Tips each appear below the two-column grid with a section heading in Helvetica-Bold. Long text is word-wrapped at 110 characters per line.

Footer โ€” “Generated by PhytoCommerce ยท phyto-evolution.github.io/PhytoCommerce” in 7pt grey Helvetica, separated by a light rule.


Download URL

https://yourstore.com/care-card/{product_id}/

The URL resolves via a custom WordPress rewrite rule registered at plugin activation. No server-level .htaccess editing is needed. The PDF is served with:

  • Content-Type: application/pdf
  • Content-Disposition: inline; filename="care-guide-{product-slug}.pdf"

After activation, visit Settings โ†’ Permalinks and click Save Changes to flush the rewrite rules.


Email Attachment

  1. Open the product edit screen in WP Admin.
  2. In the Plant Care Card meta box, tick Attach this care card PDF to the customer completed-order email.
  3. Save the product.

When a customer’s order status changes to Complete, the plugin iterates over every order item. For each product that has the email-attachment flag enabled and at least one care field populated, the PDF is generated and written to:

{wp-uploads}/phyto-care-cards/product-{id}.pdf

The file path is appended to WooCommerce’s email attachment array. Duplicate product IDs within the same order are deduplicated automatically.


Hooks

phyto_cc_fields_output

Filter the rendered care-fields HTML block before it is output on the product page. Return an empty string to suppress the block for specific products or contexts.

/**
 * @param string $output     Rendered HTML for the care-field section.
 * @param int    $product_id WooCommerce product ID.
 */
add_filter( 'phyto_cc_fields_output', function( $output, $product_id ) {
    // Example: suppress for a specific product.
    if ( 99 === $product_id ) {
        return '';
    }
    return $output;
}, 10, 2 );

phyto_cc_attach_email

Filter the array of file paths appended to the order completion email after the plugin has added its PDFs.

/**
 * @param array    $attachments File paths appended by the plugin.
 * @param WC_Order $order       The completed order.
 */
add_filter( 'phyto_cc_attach_email', function( $attachments, $order ) {
    // Example: skip attachment for wholesale orders.
    if ( $order->get_meta( '_is_wholesale' ) ) {
        return array();
    }
    return $attachments;
}, 10, 2 );

Source Layout

phyto-care-card/
โ”œโ”€โ”€ phyto-care-card.php                          # Bootstrap, constants, rewrite rule, WC check, activation hooks
โ”œโ”€โ”€ includes/
โ”‚   โ”œโ”€โ”€ class-phyto-care-card-admin.php          # Product meta box โ€” care fields + save/sanitise
โ”‚   โ”œโ”€โ”€ class-phyto-care-card-frontend.php       # Download button + PDF serve endpoint
โ”‚   โ”œโ”€โ”€ class-phyto-care-card-generator.php      # Raw PDF 1.4 builder โ€” no external library
โ”‚   โ””โ”€โ”€ class-phyto-care-card-email.php          # Attach PDF to customer_completed_order email
โ”œโ”€โ”€ assets/css/frontend.css                      # Download button styles
โ””โ”€โ”€ README.md

PrestaShop Equivalent

The PrestaShop version of this module is phyto_care_card in the modules/ directory. The meta key naming convention (_phyto_cc_*) is designed to mirror the PrestaShop field structure to simplify any future cross-platform data migration.

View Full Source โ†— โ† Back to All Modules