Substitute the default “Sold out” button on a capped buy-up with a custom waitlist
Fires inside templates/account/buyups.php only when a buy-up has subscriber_cap set, live grants are at or above the cap (including lame-duck cancel_at_period_end = 1 rows), and the current user does not already hold a grant. Return any HTML string. Return an empty string to hide the buy-up entirely from sold-out users. Output is echoed inside div class="benecaster-account__buyup-side".
Code
<?php
add_filter( 'benecaster_buyup_soldout_display', function ( string $html, int $buyup_id, int $user_id ): string {
// Return a "Join waitlist" form that posts to a custom REST endpoint.
ob_start();
?>
<form class="my-waitlist" method="post" action="/wp-json/my-plugin/v1/waitlist">
<input type="hidden" name="buyup_id" value="<?php echo esc_attr( (string) $buyup_id ); ?>">
<button type="submit"><?php esc_html_e( 'Join waitlist', 'my-plugin' ); ?></button>
</form>
<?php
return (string) ob_get_clean();
}, 10, 3 );