Skip to content

Instantly share code, notes, and snippets.

@flyingwebie
Last active August 15, 2022 10:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flyingwebie/3472182998fd5dc6eeffe253679b61e6 to your computer and use it in GitHub Desktop.
Save flyingwebie/3472182998fd5dc6eeffe253679b61e6 to your computer and use it in GitHub Desktop.
WSForm: Pull data from MetaBox Settings data and populate Select or Checkbox
<?php
// Creation Websites
// Add filter to change form '2' for Web Design prior to rendering
add_filter("wsf_pre_render_2", "fws_create_websites", 10, 1); // <=== CHANGE THE FUNCTION NAME
function fws_create_websites($form) {
// Get MetaBox Custom Fields - Setting Page -- Master Pricing
$setting_page = "master-pricing";
$field_name = "creation_services"; // <=== CHANGE ME WITH THE RIGHT CUSTOM FIELD ID (METABOX)
// Get the select field (ID: 137)
$field = wsf_form_get_field($form, 137); // <=== CHANGE ME WITH THE RIGHT FIELD ID
// Clear the rows in the select field
wsf_field_rows_clear($field);
// Store the Meta Box Group on a variable
$group = rwmb_meta(
$field_name,
["object_type" => "setting"],
$setting_page
);
// Loop the array with a foreach
foreach ($group as $item) {
// Create a new select row
$row = (object) [
// Add one column to the row data
"data" => [$item['price'], $item['service_name']],
];
// Add the row to the select field
wsf_field_row_add($field, $row);
}
// Return the form
return $form;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment