Support » Plugin: Pushover for WooCommerce » Add event name

  • Resolved puntorosso

    (@puntorosso)


    Hi, we use WooCommerce together with the plugin Tickera to sell concert tickets.
    The product names (ticket categories) are almost the same for every concert (like “General”, “VIP” etc., so when we receive the push notification we don’t know from which event they are.

    Tickera cannot affect the title of WooCommerce products. However, it does store the event ID as product post meta and it is stored to the database with _event_name meta key.

    Wouldn’t be possible to add at least a shortcode for the “note” field or the category?
    This way we could use these fields to identify the related concert.

    Thanks

    • This topic was modified 1 year ago by puntorosso.
Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Daniel Espinoza

    (@growdev)

    hello @puntorosso,

    Thanks for the detailed question. Are you familiar with using WordPress filters?

    There is a filter in the notify_new_order() method that can be used to modify the Title or the Message before the notification is sent. I will need to add $order_id to the $args array so you can pull the _event_name meta.

    How does that sound?

    Thread Starter puntorosso

    (@puntorosso)

    Sounds great!
    Thank you very much for your prompt response

    Thread Starter puntorosso

    (@puntorosso)

    I have contacted the Tickera’s developers and they suggested that, in order to add the event title on the product name, your plugin should have a hook that forward the product ID.
    They would use then this hook to query the event ID and then, based on that, the event title.
    ​Thanks

    Plugin Author Daniel Espinoza

    (@growdev)

    I will deploy version 1.0.18 today and it will have the $order_id in the hook.
    Here is a gist that will add product meta to the notification:

    https://gist.github.com/growdev/03a5dbeca1a436165a7cc214075c94ad

    <?php
    
    /**
     * Hook into Pushover send notification on new order and add something to the title from order.
     *
     * @hook 'wc_pushover_notify_new_order'
     * @param $args
     * @return mixed
     */
    function sp_wc_pushover_notify_new_order( $args ) {
    	if ( isset( $args['order_id'] ) ) {
    		$order_id = $args['order_id'];
    		$meta     = get_post_meta( $order_id, '_billing_country', true );
    		if ( $meta ) {
          // Add to title
    			$args['title'] .= ' Country is ' . $meta;
          // Modify the message
          //$args['message'] = '';
          // Modify the URL
          //$args['url'] = '';
    		}    
    	}
    	return $args;
    }
    add_filter( 'wc_pushover_notify_new_order', 'sp_wc_pushover_notify_new_order', 10 );
    Thread Starter puntorosso

    (@puntorosso)

    Perfect! A great solution.

    Thanks a lot for your help.
    Best

    Plugin Author Daniel Espinoza

    (@growdev)

    You’re welcome. Version 1.0.18 is now available.

    Thread Starter puntorosso

    (@puntorosso)

    The Tickera’s developers integrated your plugin using this snippet and it works perfectly. Thanks again for your help. Best

    
    function tc_event_title_pushover( $args ) {
        if ( isset( $args['order_id'] ) ) {
            $order_id = $args['order_id'];
            $order = wc_get_order( $order_id );
            $items = $order->get_items();
            
            foreach ( $items as $item ) {
            $product_id = $item->get_product_id();
                $event_id = get_post_meta($product_id, '_event_name', true);
                $event_title = get_the_title($event_id);
            }
            
            if ( $item ) {
                $args['title'] .= ' for '.$event_title;
            }
            }
        return $args;
    }
    add_filter( 'wc_pushover_notify_new_order', 'tc_event_title_pushover', 10 );
    
    • This reply was modified 1 year ago by puntorosso.
    • This reply was modified 1 year ago by puntorosso.
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Add event name’ is closed to new replies.