Last active
August 1, 2024 13:24
-
-
Save flyingwebie/3472182998fd5dc6eeffe253679b61e6 to your computer and use it in GitHub Desktop.
WSForm: Pull data from MetaBox Settings data and populate Select or Checkbox
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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