Support

Home Forums Event Espresso Premium Hook Filter Calling to New Page

Hook Filter Calling to New Page

Posted: June 11, 2018 at 1:17 pm


Jarred

June 11, 2018 at 1:17 pm

1) How can I change link of “proceed to registration” button of the popup on MER? we want to change the link so we can send the user to our custom page from there he can login or process to checkout as a guest

Is there is any hook/filter to modify “Proceed to Registration” Link?


Josh

  • Support Staff

June 11, 2018 at 1:38 pm

Hi Jarred,

I checked and there actually is not a filter hook to modify the URLs within the cart modal that pops up. What they could do instead is use the
FHEE__EEH_Template__display_template__template_path filter hook to load in a custom template for the cart modal (instead of the default template). The custom template could have your custom URL instead of pointing to the registration page URL.


Jarred

June 11, 2018 at 1:56 pm

Thank you Josh, he said that was very helpful.

I will keep this ticket open for now in case he has any more questions.

Thanks.


Jarred

June 18, 2018 at 12:26 pm

New Question from Developer

Can you ask EE4 team for filters and hook for transactions? so we can add points in database when transaction is complete.

Thanks


Jarred

June 18, 2018 at 12:31 pm

We are creating a points rewards addon where anytime a person buys they receive points that can then later be used towards a discount.

For example

.01 cents equals 1 point.

Another example
When customer saves up 10,000 points, they will be able to deduct $5.00 off at checkout.

Hopefully that helps clarify what they want the hooks & filters for

New Question from Developer

Can you ask EE4 team for filters and hook for transactions? so we can add points in database when transaction is complete.

Thanks


Jarred

June 18, 2018 at 1:05 pm

Also, is there a place to download all the hooks action and filters. Similar to the description on this link https://eventespresso.com/features/hooks-actions-filters/

Thanks.


Josh

  • Support Staff

June 18, 2018 at 1:32 pm

Hi Jarred,

Your developer needs to install the Debug Bar plugin and its companion Debug Bar Actions & Filters add-on. Then they’ll have a list of all the hooks and filters available from Event Espresso in each request.

Along with the above, if they open up the Event Espresso 4 plugin into their IDE, they can do a search for AHEE_ (action hooks) and FHEE_ (filter hooks).


Jarred

June 18, 2018 at 2:14 pm

Hey Josh, they said that’s very helpful, but can you tell us what the exact filter or hook is that’s used when CUSTOMER makes a payment?


Josh

  • Support Staff

June 18, 2018 at 2:22 pm

There are actually many. I can point you to 3:

AHEE__EE_SPCO_Reg_Step_Finalize_Registration__process_reg_step__completed
AHEE__EE_Transaction_Processor__update_transaction_and_registrations_after_checkout_or_payment
AHEE__EE_Payment_Processor__update_txn_based_on_payment

If none of the above are something they can use and they see a place within the core plugin where they could use a hook, the developer is encouraged to do a pull request.


Jarred

June 18, 2018 at 3:21 pm

Can you also asked him that How we apply discount using our points system in existing ee4 registration process?

Is there any hook or filter which we can use to allow discount based on our points system.


Jarred

June 18, 2018 at 3:23 pm

Thanks Josh for the answer below

There are actually many. I can point you to 3:

AHEE__EE_SPCO_Reg_Step_Finalize_Registration__process_reg_step__completed
AHEE__EE_Transaction_Processor__update_transaction_and_registrations_after_checkout_or_payment
AHEE__EE_Payment_Processor__update_txn_based_on_payment

If none of the above are something they can use and they see a place within the core plugin where they could use a hook, the developer is encouraged to do a pull request.


Josh

  • Support Staff

June 18, 2018 at 3:33 pm

Can you also asked him that How we apply discount using our points system in existing ee4 registration process?
Is there any hook or filter which we can use to allow discount based on our points system.

I’m sorry but these questions are too vague to give a specific answer. I can point you in the general direction of the Promotions add-on. If they can review the code within the Promotions add-on they’ll see how that add-on applies discounts within the registration process.


Jarred

June 24, 2018 at 9:54 am

Hi Josh,

From my guy building rewards program.

how to get cart object in ajax request in custom plugin.
I try to get cart object in our points rewards plugin. But get error from cart object.


Tony

  • Support Staff

June 25, 2018 at 3:51 am

We would need more specific details and/or a code example to see what is happening but to use the cart object you can use:

if ( EE_Registry::instance()->CART instanceof EE_Cart ) {
 $grand_total = EE_Registry::instance()->CART->get_grand_total();
}


Jarred

June 25, 2018 at 1:38 pm

Hi Guys, I have more detail. Can we make this thread private because he wants me to share the custom code he has created for my new plugin. Once marked private I can share the code and question with more detail for you.


Jarred

June 25, 2018 at 1:40 pm

NEVER MIND, if we make it private then my guy cant see this thread.
So please do not make PRIVATE


Jarred

June 25, 2018 at 1:41 pm

From developer

I am trying to get cart object in ajax request and add discount for rewards points as they did for promotions module.

<?php

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

class EE4_Points_Public {
	//initialize Public class
	public function __construct(){

		//Add points rule box on checkout page.
		add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__before_payment_options', array( $this, 'add_points_rewards_form_checkbox' ));
		add_action('wp_ajax_submit_points_discount',array($this,'submit_points_discount'));
		add_action('wp_ajax_nopriv_submit_points_discount',array($this,'submit_points_discount'));

	}

	public function submit_points_discount(){
		
		$return_data = array();
		// get the EE_Cart object being used for the current transaction
		/** @type EE_Cart $cart */

		$cart=EE_Registry::instance()->SSN->CART;

		//$cart = EE_Registry::instance()->SSN;
		//$cart=EE_Registry::instance()->CART;
		
		if ( $cart instanceof EE_Cart ) {
			// and make sure the model cache is
			$cart->get_grand_total()->get_model()->refresh_entity_map_with(
				$cart->get_grand_total()->ID(),
				$cart->get_grand_total()
			);

			// add line item
			if ( $this->generate_redeem_points_line_item()) {
				// ensure cart totals have been recalculated and saved
				$cart->get_grand_total()->recalculate_total_including_taxes();
				$cart->get_grand_total()->save_this_and_descendants();
				/** @type EE_Registration_Processor $registration_processor */
				$registration_processor = EE_Registry::instance()->load_class( 'Registration_Processor' );
				$registration_processor->update_registration_final_prices(
					$cart->get_grand_total()->transaction()
				);
				$cart->save_cart( false );
				$return_data = EED_Promotions::_get_payment_info( $cart );
				$return_data['success'] = EED_Promotions::accept_message();
				EED_Single_Page_Checkout::update_checkout();
			} else {
				EE_Error::add_attention( EED_Promotions::decline_message(), __FILE__, __FUNCTION__, __LINE__ );
			}

		}	
		else{
			EE_Error::add_error(
				sprintf(
					apply_filters(
						'FHEE__EED_Points_Rewards___submit_points__invalid_cart_notice',
						__(
							'We\'re sorry, Currently we are unable to process redeem points. please contact us for more detail',
							'event_espresso'
						)
					)
				),
				__FILE__,
				__FUNCTION__,
				__LINE__
			);
		}

		$this->generate_JSON_response( $return_data );
	}

	/**
	 *    generate_JSON_response
	 *        allows you to simply echo or print an EE_SPCO_JSON_Response object to produce a  JSON encoded string
	 *        ie: $json_response = new EE_SPCO_JSON_Response();
	 *        echo $json_response;
	 *
	 * @access    public
	 * @param array $return_data
	 * @return    void
	 */
	public function generate_JSON_response( $return_data = array() ) {
		$JSON_response = array();
		// grab notices 
		$notices = EE_Error::get_notices( false );
		// add notices to JSON response, but only if they exist
		if ( isset( $notices['attention'] ) ) {
			$JSON_response['attention'] = $notices['attention'];
		}
		if ( isset( $notices['errors'] ) ) {
			$JSON_response['errors'] = $notices['errors'];
		}
		if ( isset( $notices['success'] ) ) {
			$JSON_response['success'] = $notices['success'];
		}
		if ( empty( $JSON_response ) && empty( $return_data ) ) {
			$JSON_response['errors'] = sprintf(
				__(
					'We unable to processed your redeem point request for an unknown reason.',
					'event_espresso'
				)
			);
		}
		// add return_data array to main JSON response array, IF it contains anything
		$JSON_response['return_data'] = $return_data;
		// filter final array
		$JSON_response = apply_filters( 'FHEE__EED_Points_Rewards__generate_JSON_response__JSON_response', $JSON_response );
		// return encoded array
		echo json_encode( $JSON_response );
		exit();
	}

	/**
	 * get_redeemable_points_discount
	 * searches the cart for any items that this promotion applies to
	 *
	 * @since   1.0.0
	 * @param EE_Line_Item $parent_line_item the line item to create the new promotion line item under
	 * @param EE_Promotion $promotion        the promotion object that the line item is being created for
	 * @param string       $promo_name
	 * @param bool         $affects_tax
	 * @return \EE_Line_Item
	 * @throws \EE_Error
	 */
	public function generate_redeem_points_line_item($promo_name='',$affects_tax = false) {

		$get_discount=EE4_Points_Helper::get_points_discount();

		$promo_name = ! empty( $promo_name ) ? $promo_name : 'Points Reddeem';
		$promo_desc = 'Get $'.$get_discount['discount']." for ".$get_discount['redeem_point'];
		// generate promotion line_item

		$time=time();

		$line_item = EE_Line_Item::new_instance(
			array(
				'LIN_code'       => 'redeem-' . $get_discount['redeem_point'],
				'LIN_name'       => $promo_name,
				'LIN_desc'       => $promo_desc,
				'LIN_unit_price' => $get_discount['discount'],
				'LIN_percent'    => 0,
				'LIN_is_taxable' => $affects_tax,
				'LIN_order'      => 99,
				// we want promotions to be applied AFTER other line items
				'LIN_total'      => $get_discount['discount'],
				'LIN_quantity'   => 1,
				// Parent ID (this item goes towards that Line Item's total)
				'LIN_type'       => 'promotion',
				'OBJ_ID'         => $time,
				// ID of Item purchased
				'OBJ_type'       => 'Promotion'
				// Model Name this Line Item is for
			)
		);
		return $line_item;
	}

	public function add_points_rewards_form_checkbox($before_payment_options){

		if(is_user_logged_in()){

			$balance_points=EE4_Points_Helper::balance_points();

			if($balance_points > 0){

				$get_discount=EE4_Points_Helper::get_points_discount($balance_points);

				EE_Registry::instance()->load_helper( 'HTML' );

				$points_rewards_html='<div class="redeem_container"><h3>Redeem Points</h3>';

				if($get_discount){
					$points_rewards_html.='<p class="redeem_me"><input type="checkbox" name="use_points_rewards" id="use_points_rewards" value="1">&nbsp;Redeem Points. You have <b>'.$balance_points.'</b> points and you will get <b>$'.$get_discount['discount'].'</b> discount.</p>';
				}
				else
				{
					$points_rewards_html.='<p class="redeem_me">You have <b>'.$balance_points.'</b> Points. Insufficient Points to Redeem.</p>';
				}

				$points_rewards_html.="<ul class='redeem_rules'>
				<li>Redeem <b>10,000</b> points for <b>$5</b> off events.</li>
				<li>Redeem <b>20,000</b> points for <b>$10</b> off events.</li>
				<li>Redeem <b>30,000</b> points for <b>$20</b> off events.</li>
				<li>Redeem <b>40,000</b> points for <b>$35</b> off events.</li>
				</ul><ul class='redeem_rules'>
				<li>Redeem <b>50,000</b> points for <b>$45</b> off events.</li>
				<li>Redeem <b>60,000</b> points for <b>$60</b> off events.</li>
				<li>Redeem <b>70,000</b> points for <b>$85</b> off events.</li>
				<li>Redeem <b>80,000</b> points for <b>$120</b> off events.</ul>";

				$points_rewards_html.='</div>';

				$before_payment_options->add_subsections(
					array(
						'rewards_points_form' => new EE_Form_Section_Proper(
							array(
								'layout_strategy' => new EE_No_Layout(),
								'subsections'     => array(
									'rewards_points_content'  => new EE_Form_Section_HTML($points_rewards_html),
									'rewards_points_header' => new EE_Form_Section_HTML(
										EEH_HTML::div( ' ', '', 'clear-float' )
									),
								),
							)
						),
					)
				);	

			}
		}
		return $before_payment_options;
	}

}
new EE4_Points_Public();


Tony

  • Support Staff

June 25, 2018 at 3:39 pm

The majority of that code has been copied from the promotions add-on and it still calls methods from the promotions add-on as is, for example:

$return_data = EED_Promotions::_get_payment_info( $cart );
$return_data['success'] = EED_Promotions::accept_message();

It’s been altered some and looks like the cart is being pulled in incorrectly, but the original code should have worked fine as is so I’m not sure why that was changed and the commented code attempts used?

Adding the code itself doesn’t really give us any more context as we can’t run it (its not the full code) so we still don’t really have enough details, not without reviewing all the code which is generally not something we will do on the forums.

With a quick glance I can see there’s multiple lines when trying to pull the cart:

$cart=EE_Registry::instance()->SSN->CART;

//$cart = EE_Registry::instance()->SSN;
//$cart=EE_Registry::instance()->CART;

But looking at the promotions add-on where that method was copied from the code that is actually used in that section is:

$cart = EE_Registry::instance()->SSN->cart();

So that should pull the EE_Cart object for you, not the code that has been added above.

We don’t know your what developer is getting returned currently, what is cart being set to show a problem? null?

What have they tried? What other code is running? When the above code is actually running etc. We really need more details of the problem and in-depth details of what the problem is, the specific code they have tried and what is getting returned from the code they have tried.

In short, we need much more detail to help here but so far it looks like the promotions add-on was copied and then incorrectly modified?


Jarred

June 27, 2018 at 11:41 am

Hi Jarred.
I create dynamic promotion code for point reward discount. and try to apply that discount using promotion submit code function.
But it gives a fatal error.
So can you ask Josh or tony that how we apply dynamically created promo code in the site or how to apply promo code automatically?
If we resolved this then we almost finish points and reward system.


Josh

  • Support Staff

June 27, 2018 at 11:56 am

I’m sorry but these questions are too vague to give a specific answer. Does your developer know how to debug his own code? If so, they can start with the stack trace of the fatal error and work from there.


Jarred

June 27, 2018 at 12:32 pm

okay I will have him type on here to better communicate. thanks


Jarred

June 27, 2018 at 12:42 pm

Hi Josh,
Sorry for confusion. Actually, We try to access cart object in our custom ajax function but we get empty value for cart even though cart have events. for avoid this problem.

Here is our code.


add_action('wp_ajax_submit_points_discount',array($this,'submit_points_discount'));
		add_action('wp_ajax_nopriv_submit_points_discount',array($this,'submit_points_discount'));

public function submit_points_discount(){
        if ( EE_Registry::instance()->CART instanceof EE_Cart ) {
             $grand_total = EE_Registry::instance()->CART->get_grand_total();
	}
        ---
        ---
}

or we also try another way to submit our promo code for points rewards by calling promotion submit code method using their class instance like this way in our ajax function. but its didn’t work and its give empty cart value there as well.

EED_Promotions::instance()->submit_promo_code();

Please can you help us. how we can get cart object in our ajax function.

thanks and regards,
Kirit


Josh

  • Support Staff

June 27, 2018 at 1:34 pm

You’ll probably need to write some JavaScript to go along with your AJAX function, correct?


Jarred

June 29, 2018 at 3:18 am

Hi Josh,
One more questions, I added promotion code in cart. but how can i remove promotion code from cart. Look at following screenshot, i not see any option to remove promocode from cart.

https://drive.google.com/file/d/1j14MRnHcJbRPQE0P6nD08CXg5PUFOnlt/view?usp=drivesdk


Josh

  • Support Staff

June 29, 2018 at 8:29 am

There actually are no options to remove applied promotions from the cart. If you remove the event the applied promotions will automatically be removed with the event.


Jarred

July 13, 2018 at 7:11 am

Hi Josh,
Any way to remove promotion from cart using programming?


Josh

  • Support Staff

July 13, 2018 at 7:55 am

A developer could maybe do that (it will depend on their skill level). It’s not something we support.

The support post ‘Hook Filter Calling to New Page’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Support forum for Event Espresso 3 and Event Espresso 4.
Documentation for EE3 and EE4
Documentation for Event Espresso 3

Documentation for Event Espresso 4

Status: closed

Updated by  Josh 1 month ago ago

Topic Tags

Tagged: , ,

Notifications

This topic is: not resolved
Do NOT follow this link or you will be banned from the site!