Integration: WooCommerce pricing packages

What it does

When WooCommerce is active and a customer completes an order containing a GeoDirectory pricing-package product, mam-geodirectory updates every listing the customer authors to use the new package, prorating the expiry date based on the unused balance of their previous subscription.

The integration runs only when the WooCommerce class is loaded; the plugin’s bootstrap conditionalises both the class instantiation and the filter registration on class_exists('WooCommerce').


Activation

  • WooCommerce installed and active.
  • At least one GeoDirectory pricing package with a woocommerce_product_id meta key linking it to a WooCommerce product.
  • The MAM order pipeline fires mam_wc_successful_simple_product_order on order completion (this is mam-main / mam-woocommerce-bridge contract).

What the integration does

mam_gd_woocommerce::mam_wc_successful_simple_product_order($empty, $order):

  1. Reads the user’s currently-active package from their listings — picks the first gd_place listing whose package_id is non-empty and whose expire_date is in the future.
  2. Reads every WooCommerce product ID associated with a GeoDirectory pricing package via geodir_pricing_get_packages + geodir_pricing_get_meta(..., 'woocommerce_product_id').
  3. Walks the order’s items ($mam_order_details global). For each item that is a package product:
    • Sets the global $gd_listing_id to the order item’s list_id.
    • Updates the listing’s post_author to the buyer.
    • Looks up the GeoDirectory package ID via get_package_id_from_product.
    • Calls update_listing_package_data($new_package_id, $old_package_id, $old_expiry).
  4. Returns the upstream pass-through value unchanged.

update_listing_package_data proates the new expiry:

months_remaining = months between now and old expiry
amount_pending   = (old_package.amount / 12) * months_remaining
months_to_add    = round(new_package.amount / max(amount_pending, 1))
new_expiry       = today + months_to_add months

Every gd_place post owned by the buyer is then updated to use the new package_id and expire_date. (Other GD post types are not touched by this function.)


Order return value injection

mam_gd_woocommerce::mam_wc_menu_order_return_vals($result):

When the order processed by the loop above completed, the global $gd_listing_id is set. This filter (mam_wc_menu_order_return_vals) reads that global and injects order_id into the WooCommerce return-value payload. The mobile app uses that order_id to refresh the right listing.


Things to watch for

  • All gd_place listings the user owns are updated. A user with five listings under a single package will have all five rebased on the new package on a single order. This is by design but worth knowing for support cases.
  • Only gd_place. Custom GD post types are not currently updated. If your directory uses a different post type for paid listings, the integration is a no-op for it.
  • Proration math is rough. The annualisation step assumes packages are billed annually (old.amount / 12). For packages with non-annual recurrence, the prorated balance will be off; the runtime does not consult recurring or time_unit here.
  • Order item shape. The integration relies on $mam_order_details having item_id and list_id keys. That global is populated upstream; if the upstream contract changes, this integration silently no-ops.

Steps to enable

  1. Install and activate WooCommerce.
  2. Build a WooCommerce simple product per pricing package.
  3. Set the package’s woocommerce_product_id meta to the product’s ID (typically via the GeoDir Pricing UI).
  4. Test an upgrade: have a test user with a known package buy the upgrade product. Confirm:
    • All their gd_place listings show the new package_id.
    • The expiry date is in the future and prorated against their previous subscription.
    • The order’s order_id matches the listing ID in the WooCommerce return value (helpful for app-side post-purchase deep-linking).

Verification

This article was last verified against:

  • Plugin: mam-geodirectory v2.1.5
  • Plugin: WooCommerce
  • Plugin: GeoDir Pricing Manager
  • Source: includes/mam_gd_woocommerce.php

Re-verify whenever the mam_wc_successful_simple_product_order filter contract changes, the $mam_order_details global shape changes, GeoDirectory’s geodir_pricing_* API changes, or the proration formula in update_listing_package_data is updated.


  • Plugin: mam-geodirectory
  • Recipe: Pricing package fields
  • Form and flow: Claim Listing

Metadata

Field Value
Article type Plugin Overview
Plugin slug mam-geodirectory
Applies to plugin version 2.1.5+
Category Plugin Reference
Audience WordPress admin
Last verified 2026-05-01
Contents

    Need Support?

    Can’t find the answer you’re looking for? Don’t worry we’re here to help!