Skip to content

Instantly share code, notes, and snippets.

@Faisalawanisee
Created August 27, 2018 09:28
Show Gist options
  • Select an option

  • Save Faisalawanisee/815c751b7d07c93adcfd472f28e27256 to your computer and use it in GitHub Desktop.

Select an option

Save Faisalawanisee/815c751b7d07c93adcfd472f28e27256 to your computer and use it in GitHub Desktop.
Engraving Source Code for Michael - Just Replace "FORMID" with your form ID number and all is good to go.
<?php
add_filter('gform_pre_render_FORMID', 'populate_posts_FORMID');
function populate_posts_FORMID($form) {
?>
<script>
var flag = true;
var checkExist = setInterval(function () {
if (jQuery('form#gform_FORMID').hasClass('cart')) {
jQuery('.engraving_loader').remove();
clearInterval(checkExist);
} else if (flag) {
flag = false;
}
}, 100);
</script>
<?php
global $product;
foreach ($form['fields'] as &$field) {
if ($field->type != 'select') {
continue;
}
$array = (array) $product;
$prefix = chr(0) . '*' . chr(0);
$sku = $array[$prefix . 'data']['sku'];
if (!empty($sku)) {
$choices = array();
$choices[] = array('text' => $sku, 'value' => $sku);
$field->choices = $choices;
}
}
return $form;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment