~ Featured + SureCart
To implement this feature in WordPress using Meta Box for the “Featured” checkbox on your “listing” custom post type, SureCart for handling the subscriptions (1 month, 6 months, annual), and Bricks Builder for displaying the user’s listings with purchase links, follow these steps. This assumes you have the plugins installed and activated, your “listing” post type is registered (e.g., via a plugin like Toolset or custom code), and users are logged in to view their own listings.
Step 1: Set Up the SureCart Product and Variations
- Go to SureCart > Products in your WordPress admin and create a new product called “Featured Listing Subscription.”
- Set the product type to Subscription (this enables recurring billing).
- Under Pricing, add three variations (prices):
- 1 Month: Recurring every 1 month (e.g., $10/month).
- 6 Months: Recurring every 6 months (e.g., $50/6 months).
- Annual: Recurring every 12 months (e.g., $100/year).
- For each price, note the Price ID (visible when editing the product—click “Copy Links” next to the price to grab it).
- Optionally, create a dedicated checkout form (SureCart > Forms > Add New) for this product to customize the flow, but the default instant checkout works fine for links.
This creates buyable subscription options. Each purchase will generate a subscription tied to the customer.
Step 2: Add a Custom Field to the Checkout Form for Passing the Listing ID
To associate the purchase with a specific listing, add a hidden custom field to capture the listing ID (passed via URL).
- Go to SureCart > Forms and edit your default checkout form (or create a new one and assign it to the product).
- In the form builder, add a Text Field block.
- Set the field type to Hidden (via advanced settings if available, or use CSS to hide it: display: none;).
- Set the field name to listing_id (this is key for accessing it later).
- Save the form and assign it to your “Featured Listing Subscription” product if using a custom form.
This field will receive the listing ID from the purchase link URL and store it as part of the order/subscription data.
OTTOKIT
Step 3: Set Up WP Webhooks to Update the Meta Box Checkbox on Subscription Events
You’ll use the free WP Webhooks plugin (with Automator add-on for no-code workflows) to listen for SureCart events and update the “Featured” checkbox in Meta Box.
- Install and activate WP Webhooks (and WP Webhooks Automator for workflows).
- Go to WP Webhooks > Add New and create a workflow:
- Trigger: Select SureCart > “Subscription Created” (this fires on new subscription purchases; WP Webhooks supports this via SureCart’s webhooks integration).
- Action: Select Meta Box > “Set Meta Data.”
- Configure the trigger:
- Connect your SureCart account (it uses webhooks—SureCart sends POST data to your site’s endpoint).
- The payload includes the subscription object, order details, and custom fields (like listing_id from the checkout).
- Configure the action:
- Post ID: Pull dynamically from the trigger data—use the listing_id custom field value from the subscription/order payload (e.g., {subscription_order_custom_fields_listing_id} or similar; test via WP Webhooks’ data viewer).
- Meta Key: Your Meta Box field ID for the “Featured” checkbox (e.g., featured_listing).
- Meta Value: Set to 1 (true/checked) on creation.
- Add another workflow for renewals:
- Trigger: SureCart > “Subscription Renewed.”
- Action: Same as above—reset the checkbox to 1 to keep it active.
- For expiration/cancellation:
- Add a workflow: Trigger SureCart > “Subscription Canceled” or “Subscription Completed.”
- Action: Meta Box > “Set Meta Data” with value 0 (unchecked).
- Test by purchasing a subscription—ensure your webhook endpoint (auto-generated by WP Webhooks) is added in SureCart > Settings > Webhooks (point it to your site’s URL + /wp-json/wp-wh/v1/webhooks/deliver).
This automates updating the checkbox based on subscription status. If you prefer code, hook into surecart/subscription_created (PHP action) to run update_post_meta($listing_id, ‘featured_listing’, 1);.
Step 4: Display User’s Listings in Bricks Builder with Purchase Links
Create a page/template in Bricks to show the logged-in user’s listings in a query loop, with conditional “Purchase Featured” buttons/links if the checkbox is unchecked.
- In Bricks Builder, add a Container element to your page/template.
- Enable Use Query Loop on the Container (this turns it into a repeater).
- Open the Query controls (loop icon):
- Query Type: Posts.
- Post Type: Select “listing” (your custom post type).
- Author: Set to “Current User” (dynamic) to filter only the logged-in user’s posts.
- Posts Per Page: e.g., -1 (all) or 10.
- Order By: Published Date (Descending).
- For advanced filtering (e.g., only non-featured), use the PHP Query Editor (enable in Bricks settings > Custom Code): text
$user_id = get_current_user_id(); return [ 'post_type' => 'listing', 'author' => $user_id, 'posts_per_page' => -1, 'meta_query' => [ [ 'key' => 'featured_listing', // Your Meta Box field ID 'value' => '1', 'compare' => '!=', // Exclude already featured ], ], ];(Adjust if you want to show all and conditionalize buttons instead.)
- Inside the Container (loop item), add dynamic elements:
- Heading for title: Content = {post_title} (dynamic data).
- Image for featured image: Source = Featured Image.
- Text for excerpt: {post_excerpt}.
- For the purchase link(s): Add a Button (or set Container to link).
- Link Type: Dynamic Data > Custom URL.
- URL: /checkout?line_items[0][price_id]=YOUR_1MONTH_PRICE_ID&listing_id={post_id} (replace YOUR_1MONTH_PRICE_ID with the actual ID; use {post_id} for dynamic listing ID).
- Repeat for 6-month and annual buttons with their price IDs: e.g., /checkout?line_items[0][price_id]=YOUR_6MONTH_PRICE_ID&listing_id={post_id}.
- Label: “Get Featured for 1 Month” (static or dynamic).
- Conditional visibility (for buttons): On the Button, use Conditions > If > Post Meta > featured_listing = 0 (show only if unchecked).
- If featured, add a badge: Div with text “Featured!” and condition featured_listing = 1.
- Add Pagination (WordPress group) below the Container, linked to the query.
Publish the page/template. Logged-in users will see their listings; clicking a button takes them to prefilled SureCart checkout with the listing ID passed. On success, WP Webhooks updates the checkbox.
Additional Tips
- Security: Ensure users can only purchase for their own listings (author check is already in the query). Use nonces if adding custom PHP.
- Expiration Handling: For precision, replace the checkbox with date metas (e.g., featured_start and featured_end) via Meta Box, and query/check against current_time. Update dates on renew/cancel.
- Testing: Use SureCart’s test mode. View webhook payloads in WP Webhooks to confirm listing_id arrives (it should be in order.custom_fields or similar in the subscription payload).
- Styling: In Bricks, use CSS classes for responsive grid layout on the Container (e.g., Flexbox, 3 columns).
If you run into issues (e.g., exact payload key for listing_id), share error logs or webhook samples for troubleshooting. This setup keeps it simple—no full custom coding needed beyond the query PHP.
56 web pages
