Learndash woocommerce access

From Lonsdale201/wp-agent-skills · View interactive version

Learndash woocommerce access is an AI agent skill from the GitHub repository Lonsdale201/wp-agent-skills. Build or audit the LearnDash WooCommerce integration that grants/revokes LearnDash course and group access from WooCommerce products, orders, refunds, subscriptions, switches, and order-item changes. Use when code mentions learndash-woocommerce, _related_course, _related_group, LearnDash\WooCommerce

How to use this skill

Skill file

LearnDash WooCommerce access

Use this when WooCommerce products, orders, subscriptions, refunds, or product

variations must grant or revoke LearnDash course/group access.

The LearnDash WooCommerce bridge is not just "on completed order call

ld_update_course_access()". It tracks product relations, variable product

relations, configurable order/subscription statuses, partial refunds,

subscription switches, order item mutations, access expiration, silent queued

enrollment, and a per-user counter so one access source does not remove another.

When to use this skill

Trigger when ANY of these appears:

learndash_woocommerce_silent_course_enrollment_queue, or

learndash_woocommerce_disable_access_removal_on_expiration.

switch, order item added/deleted, customer change, or HPOS.

Product relation model

LearnDash WooCommerce stores related LearnDash objects on the Woo product or

variation:

store relations on each variation.

present, it checks the product ID.

When building a compatible importer/sync, preserve that shape:

update_post_meta( $product_or_variation_id, '_related_course', array_map( 'absint', $course_ids ) );
update_post_meta( $product_or_variation_id, '_related_group', array_map( 'absint', $group_ids ) );

Do not store a scalar ID and do not attach courses only to a variable parent if

the product is sold through variations.

Enrollment status settings

The bridge decides which Woo statuses grant or revoke access through

LearnDash\WooCommerce\Settings\Status_Access. That class reads the LearnDash

Woo settings option learndash_woocommerce_enrollment_status_settings.

Default grant statuses in 2.0.2:

The plugin hooks dynamically:

can remove access only for refunded items.

skipped when learndash_woocommerce_disable_access_removal_on_expiration is

yes.

Do not hard-code completed as the only access status in a compatibility

plugin. Read the status settings or hook after the bridge's own status actions.

Order lifecycle behavior

The bridge grants/removes access from several surfaces:

It declares WooCommerce HPOS compatibility during before_woocommerce_init, so

compatible plugins should use Woo order CRUD (wc_get_order(),

WC_Order::get_items(), order item methods) rather than direct postmeta SQL.

Access counter behavior

The user meta _learndash_woocommerce_enrolled_courses_access_counter prevents

one purchase/refund from revoking access that is still granted by another order

or subscription.

For courses:

or if the existing access has expired and must be reset.

course access only when no counter entry remains for that course.

For groups:

ld_update_group_access() only when the user is not already in the group.

no counter entry remains for that group.

If a custom plugin bypasses the bridge and calls ld_update_course_access() on

every order/refund, it can remove access while another valid order still exists.

Use LearnDash Woo's relationship/status model when the access source is Woo.

Expiration and paid date

When granting from an order, the bridge checks whether the LearnDash course or

group product access already expired relative to the Woo order paid date. It can

remove instead of add access if the product's access window has elapsed.

When a course has no product start date, the bridge can set direct course

access_from from the order paid date through LearnDash's access-date API.

This matters for historical imports and delayed processing.

Silent enrollment queue

When an order contains many related courses/groups, the bridge can enqueue work

in learndash_woocommerce_silent_course_enrollment_queue and process it from

its cron hook. The queue is intentionally non-autoloaded by the upgrade routine.

Do not assume access is synchronous for very large orders. If a custom workflow

needs immediate post-order access, inspect the queue and the bridge threshold

filter learndash_woocommerce_process_silent_course_enrollment_queue_count.

Integration patterns

For a plugin that sells LearnDash access through normal Woo products:

  1. Store _related_course and/or _related_group on the exact product or

variation that is sold.

  1. Let Woo order/subscription status transitions trigger LearnDash Woo.
  2. Use Woo CRUD and HPOS-safe order APIs.
  3. Avoid direct LearnDash grant/revoke calls unless the access source is not a

Woo order/subscription handled by the bridge.

  1. If you must reconcile access, honor the bridge counter before revoking.

For an admin/import tool:

  1. Resolve whether the SKU maps to a product or variation.
  2. Save arrays of integer LearnDash IDs in the expected meta keys.
  3. Trigger normal Woo order status transitions or run a deliberate

reconciliation command.

  1. Log skipped guest orders, invalid users, missing courses/groups, and queued

enrollments.

Common mistakes to reject

refunds, subscription statuses, item changes, and settings.

LearnDash Woo access counter.

clear account-linking flow.

Cross-references

course grant/revoke behavior.

behavior.

from preserving, resetting, or completing learner progress.

payment gateway behavior.

References

Validated against LearnDash WooCommerce 2.0.2 and LearnDash LMS 5.1.9 local

source:

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.