Load PHP Function after page load
-
Ok so the function below is specifically for the official Woocommerce points and Rewards plugin from there website. They have provided this as an example to add to a plugin I may be building. I’m not there yet with my wordpress PHP skill and need some help. I want to make this function load after a webpage has succesfully loaded. I’m going to be using a Mailchimp form and have the form on success reroute to a page with information and would like to reward to user points for joining the newsletter. Can someone please show me how to correctly either place this in the page or call it with javascript.
<?php // Add the action setting add_filter( 'wc_points_rewards_action_settings', 'points_rewards_newsletter_action_settings' ); function points_rewards_newsletter_action_settings( $settings ) { $settings[] = array( 'title' => __( 'Points earned for newsletter signup' ), 'desc_tip' => __( 'Enter the amount of points earned when a customer signs up for a newsletter via MailChimp.' ), 'id' => 'wc_points_rewards_mailchimp_newsletter_signup', ); return $settings; } // add the event descriptions add_filter( 'wc_points_rewards_event_description', 'add_points_rewards_newsletter_action_event_description', 10, 3 ); function add_points_rewards_newsletter_action_event_description( $event_description, $event_type, $event ) { $points_label = get_option( 'wc_points_rewards_points_label' ); // set the description if we know the type switch ( $event_type ) { case 'mailchimp-newsletter-signup': $event_description = sprintf( __( '%s earned for newsletter signup' ), $points_label ); break; } return $event_description; } // perform the event (of course this depends on your particular plugin/action) add_action( 'wp_mailchimp_new_newsletter_signup', 'points_rewards_newsletter_signup_action' ); function points_rewards_newsletter_signup_action( $newsletter_id ) { // can't give points to a user who isn't logged in if ( ! is_user_logged_in() ) return; // get the points configured for this custom action $points = get_option( 'wc_points_rewards_mailchimp_newsletter_signup' ); if ( ! empty( $points ) ) { // arbitrary data can be passed in with the points change, this will be persisted to the points event log $data = array( 'newsletter_id' => $newsletter_id ); WC_Points_Rewards_Manager::increase_points( get_current_user_id(), $points, 'mailchimp-newsletter-signup', $data ); } }
The page I need help with: [log in to see the link]
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Load PHP Function after page load’ is closed to new replies.