• I am using WooCommerce Points & Rewards plugin and want to extend it with my own actions for building up points.

    I have added the following code to my theme’s functions.php file:

    add_filter( 'wc_points_rewards_action_settings', 'rewards_voucher_settings' );
    function rewards_voucher_settings( $settings ) {
        $settings[] = array(
        'title'    => __( 'Vouchers earned for entering retail code' ),
        'desc_tip' => __( 'Enter the amount to be earned when a customer enters a retail code.' ),
        'id'       => 'rewards_voucher',
        );
        return $settings;
    }
    
    add_action('rewards_voucher_submit', 'rewards_voucher_action' );
    function rewards_voucher_action( ) {
        if ( is_user_logged_in() ){
          $points = get_option( 'rewards_voucher' );
          if ( ! empty( $points ) ) {
            WC_Points_Rewards_Manager::increase_points( get_current_user_id(), $points, 'rewards' );
          }
        }
    }
    
    add_filter('wc_points_rewards_event_description', 'add_rewards_voucher_action_event_description', 10, 3 );
    function add_rewards_voucher_action_event_description( $event_description, $event_type, $event ) {
        $points_label = get_option( 'wc_points_rewards_points_label' );
        switch ( $event_type ) {
          case 'rewards': $event_description = sprintf( __( '%s earned for purchasing retail pack.' ), $points_label ); break;
        }
        return $event_description;
    }

    This has successfully added the appropriate setting in the admin area, what I could use a pointer with is the $event_type as I understand this needs to be the page slug? My page slug is /rewards and I have one form field and a button which when successfully submitted i’d like the points to be added to the logged in user however I don’t seem to have this working using what I have above? This wasn’t using Contact Form 7 or another plugin so unsure if I need to adjust the form action setting or how to get further along.

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘WooCommerce Points & Rewards – Add Action’ is closed to new replies.