ID, 'post_id' ); } // add the meta box only if reservations are enabled if ( get_option( 'dbem_rsvp_enabled' ) && $em_event->can_manage( 'manage_bookings', 'manage_others_bookings' ) ) { add_meta_box( 'aem-event-referral-rate', __( 'Affiliates', 'affiliates-events-manager' ), array( __CLASS__, 'meta_box_affiliates' ), 'event', 'normal', 'high' ); // We do not add it to recurring events (posts of type 'event-recurring') as these can't really be booked. // Recurring events just create normal events and that is where we would set a rate. } } /** * Meta box output * * @param object $post */ public static function meta_box_affiliates( $post ) { $referral_rate = get_post_meta( $post->ID, self::REFERRAL_RATE, true ); $referral_rate = isset( $referral_rate ) ? $referral_rate : self::REFERRAL_RATE_DEFAULT; $output = '

'; $output .= esc_html__( 'Booking Referral Rate', 'affiliates-events-manager' ); $output .= '

'; $output = '

'; $output .= wp_nonce_field( self::SET_EVENT_OPTIONS, self::EVENT_NONCE, true, false ); $output .= ''; $output .= ''; $output .= '

'; $output .= '

'; $output .= wp_kses( __( 'Example: Set the referral rate to 0.1 if you want your affiliates to get a 10% commission on each booking.', 'affiliates-events-manager' ), array( 'strong' => array() ) ); $output .= '

'; // @codingStandardsIgnoreStart echo $output; // @codingStandardsIgnoreEnd } /** * Save referral rate as post_meta * * @param int $post_id * @param object $post * @param bool $update */ public static function save_post_event( $post_id, $post, $update ) { if ( !current_user_can( AFFILIATES_ADMINISTER_OPTIONS ) ) { wp_die( esc_html__( 'Access denied.', 'affiliates-events-manager' ) ); } if ( self::EVENT_POST_TYPE != $post->post_type ) { return; } if ( isset( $_POST[self::REFERRAL_RATE] ) ) { if ( wp_verify_nonce( $_POST[self::EVENT_NONCE], self::SET_EVENT_OPTIONS ) ) { $referral_rate = floatval( $_POST[self::REFERRAL_RATE] ); if ( $referral_rate > 1.0 ) { $referral_rate = 1.0; } else if ( $referral_rate < 0 ) { $referral_rate = 0.0; } } update_post_meta( $post->ID, self::REFERRAL_RATE, sanitize_text_field( $referral_rate ) ); } } } Affiliates_EM_Booking::init();