public static function replace_codes($copy) { global $a; global $r; global $w; $activity_codes = AC::get_activity_replacement_codes(); preg_match_all('/\\{\\{.*?\\}\\}/', $copy, $matches); foreach ($matches as $match) { foreach ($match as $hook) { if (!is_null($hook)) { $temp = str_replace('}}', '', $hook); if (strstr($temp, '{{a_')) { $tag = str_replace('{{a_', '', $temp); $converted = $a->{$tag}; switch ($tag) { case 'fee': $converted = 'Fee: $' . number_format($converted, 2); break; case 'id': $converted = $a->ID; break; } } if (strstr($temp, '{{r_')) { $tag = str_replace('{{r_', '', $temp); $converted = $r->{$tag}; switch ($tag) { case 'total': $converted = '$' . number_format($converted, 2); break; case 'gratuity': if ($converted == 0) { $converted = ''; } else { $converted = 'Gratuity: $' . number_format($converted, 2); } break; case 'donation': if ($converted == 0) { $converted = ''; } else { $converted = 'Donation: $' . number_format($converted, 2); } break; case 'id': $converted = $r->ID; break; } } if (strstr($temp, '{{w_')) { $tag = str_replace('{{w_', '', $temp); $converted = $w->{$tag}; switch ($tag) { case 'id': $converted = $a->ID; break; } } $copy = str_replace($hook, $converted, $copy); } } } return $copy; }
function stock_meta_box_callback() { echo '<p>Use these codes in email message copy to be replaced by variables.</p>'; echo '<p><strong>Activity Codes</strong></p>'; foreach (AC::get_activity_replacement_codes() as $code) { echo '<code>{{a_' . $code . '}}</code><br />'; } echo '<p><strong>Reservation Codes</strong></p>'; foreach (AC::get_reservation_replacement_codes() as $code) { echo '<code>{{r_' . $code . '}}</code><br />'; } echo '<p><strong>Waitlist Codes</strong></p>'; foreach (AC::get_waitlist_replacement_codes() as $code) { echo '<code>{{w_' . $code . '}}</code><br />'; } }