AJAX: Favorite Products
The favorites feature has one AJAX action. This page documents its exact contract as implemented.
Action
Section titled “Action”- Action name:
rwcv_mark_product_fav - Registered on
wp_ajax_rwcv_mark_product_favonly. It is not registered forwp_ajax_nopriv_, because the button never renders for visitors and the handler writes user meta.
Localized data
Section titled “Localized data”The frontend script is localized as rwcv_frontend_action with:
ajaxurl: theadmin-ajax.phpURL.nonce: a nonce created with the actionreign-wc-vendor-nonce.read_more: the translatable “Read More” label used by the description toggle.
Request
Section titled “Request”The script sends a POST request with these fields:
| Field | Value |
|---|---|
action |
rwcv_mark_product_fav |
product_id |
the product ID |
product-action |
mark-fav to add, anything else to remove |
nonce |
rwcv_frontend_action.nonce |
Note the field name is product-action (with a hyphen), and the nonce is sent as nonce.
Server handling
Section titled “Server handling”The handler reign_wcvendors_mark_product_favorite():
- Verifies the nonce against
reign-wc-vendor-nonce. On failure it responds withwp_send_json_error()and HTTP 403. - Requires a logged-in user. If not logged in, it responds with
wp_send_json_error()and HTTP 401. - On
mark-fav, adds the product ID to the user’srwcv_my_fav_productsmeta and adds the user ID to the product’srwcv_fav_product_by_usermeta. Otherwise it removes them. - Responds with
wp_send_json_success().
Response
Section titled “Response”On success the payload is:
{ "success": true, "data": { "btn-action": "remove-fav" } }btn-action is the action to use for the next click: remove-fav after adding, mark-fav after removing. On a rejected request the button state is left unchanged by the script.

