Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
139 views
in Technique[技术] by (71.8m points)

php - WooCommerce Points & Rewards - Add Action

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.

question from:https://stackoverflow.com/questions/65887902/woocommerce-points-rewards-add-action

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...