Skip to content

Instantly share code, notes, and snippets.

@speedguy
speedguy / wp_forms_calculator
Last active February 6, 2023 23:13
WP Forms Calculator Demo
add_filter ('wpforms_frontend_confirmation_message', 'restrict_form_formula', 10, 2);
function restrict_form_formula($confirmation_message, $form_data) {
if ($form_data['id'] == 642) { /* This number is form id - so that we only process the results for this form */
$monthly_recurring = $_POST['wpforms']['fields'][1]; /* The id for the field you want to use in calculation */
$ad_spent_month = $_POST['wpforms']['fields'][2]; /* The id for the field you want to use in calculation */
$total_budget = $_POST['wpforms']['fields'][3]; /* The id for the field you want to use in calculation */
$calculation = ($monthly_recurring * $ad_spent_month) / $total_budget;
return $calculation;
}
else {
add_filter('excerpt_length','custom_excerpt_length', 999);
function custom_excerpt_length( $length )
{
if (get_post_type() == "my-custompost-type1")
return 100;
}
$id = $_GET['product_id']; //Get the product that we need to show from the URL query string
$WooProduct = new WC_Product_Factory(); //Create a new instance of the Woo product object
$product = $WooProduct->get_product($id); // Get the product details for the product in which we are interested
echo '<h1 class="popup-heading"><a href="'.get_permalink($id).'">'.get_the_title($id).'</a></h1><br />'; //Get the name of the product and link to the actual product
echo $product->post->post_excerpt; // Get the product description (or any other field for that product that you may want - even the images for that product
@speedguy
speedguy / gist:c8b5c5929dbb15736f22
Created May 13, 2014 13:21
Restrict Partial Content Shortcode Demo
[restrict allow_user="2,3,11,5" allow_role="administrator, subscriber"]stuff that is hidden here[/restrict]
[simple-faq style="accordion" category="faq-category-1"]
@speedguy
speedguy / wishlist-user-register
Last active September 28, 2016 02:15
Using user_register hook in Wordpress
add_action('user_register', 'my_new_member');
function my_new_member($user_id) {
global $wpdb;
//Example of how to get the fields submitted via the form
if (isset($_POST['first_name'])) {
$firstname = $_POST['first_name'];
}
else {
$firstname = '';