Support » Plugin: WooBuddy -> WooCommerce BuddyPress Integration » Need some correction

  • I am plugin developer I am using your plugin thank you for your best product.. I Have created plugin for buddyboss or buddypress custom notification your plugin have conflict
    with sending notification

    Let me explain you

    file location wc4bp\class\wc4bp-notifications.php (line number 28)
    Here the function

    add_filter( 'bp_notifications_get_notifications_for_user', 'wc4bp_format_purchased_notifications', 10, 5 );
    function wc4bp_format_purchased_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) {
        if ( 'send_purchase_notification' === $action ) {
    		if( ! empty( $item_id ) ){
              $order         = wc_get_order( $item_id );
    			$names         = array();
    			$message       = __( 'The user %s has bought %s','wc4bp' );
    			foreach( $order->get_items() as $item_id => $item ){
    				$names[]   = '<a href="' . $item->get_product()->get_permalink() . '">' . $item->get_product()->get_name() . '</a>';
    				$user_link = bp_core_get_userlink( $order->get_customer_id() );
    			}
    			$notification  = sprintf( $message,$user_link, implode( ', ',$names ) );
    		}
            
        }
        
    	return $notification;
    }

    observation : debug undefine notification variable when notification not found you need to return under the your action if condition another main point when I fired same filter so anther filter not working because you haven’t return $action after end function I modify your function below

    add_filter( 'bp_notifications_get_notifications_for_user', 'wc4bp_format_purchased_notifications', 10, 5 );
    function wc4bp_format_purchased_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) {
        if ( 'send_purchase_notification' === $action ) {
    		if( ! empty( $item_id ) ){
              $order         = wc_get_order( $item_id );
    			$names         = array();
    			$message       = __( 'The user %s has bought %s','wc4bp' );
    			foreach( $order->get_items() as $item_id => $item ){
    				$names[]   = '<a href="' . $item->get_product()->get_permalink() . '">' . $item->get_product()->get_name() . '</a>';
    				$user_link = bp_core_get_userlink( $order->get_customer_id() );
    			}
    			$notification  = sprintf( $message,$user_link, implode( ', ',$names ) );
    		}
            return $notification;
        }
        return $action;
    	
    }

    Please make these correction on your next update please here you can check buddyboss-plateform plugin also followed same instruction

    function bbp_format_buddypress_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) {
    
    	// New reply notifications
    	if ( 'bbp_new_reply' === $action ) {
    		$topic_id    = bbp_get_reply_topic_id( $item_id );
    		$topic_title = bbp_get_topic_title( $topic_id );
    		$topic_link  = wp_nonce_url(
    			add_query_arg(
    				array(
    					'action'   => 'bbp_mark_read',
    					'topic_id' => $topic_id,
    					'reply_id' => $item_id,
    				),
    				bbp_get_reply_url( $item_id )
    			),
    			'bbp_mark_topic_' . $topic_id
    		);
    		$title_attr  = __( 'Discussion Replies', 'buddyboss' );
    
    		if ( (int) $total_items > 1 ) {
    			$text   = sprintf( __( 'You have %d new replies', 'buddyboss' ), (int) $total_items );
    			$filter = 'bbp_multiple_new_subscription_notification';
    		} else {
    			if ( ! empty( $secondary_item_id ) ) {
    				$text = sprintf( __( 'You have %d new reply to %2$s from %3$s', 'buddyboss' ), (int) $total_items, $topic_title, bp_core_get_user_displayname( $secondary_item_id ) );
    			} else {
    				$text = sprintf( __( 'You have %1$d new reply to %2$s', 'buddyboss' ), (int) $total_items, $topic_title );
    			}
    			$filter = 'bbp_single_new_subscription_notification';
    		}
    
    		// WordPress Toolbar
    		if ( 'string' === $format ) {
    			$return = apply_filters( $filter, '<a href="' . esc_url( $topic_link ) . '" title="' . esc_attr( $title_attr ) . '">' . esc_html( $text ) . '</a>', (int) $total_items, $text, $topic_link );
    
    			// Deprecated BuddyBar
    		} else {
    			$return = apply_filters(
    				$filter,
    				array(
    					'text' => $text,
    					'link' => $topic_link,
    				),
    				$topic_link,
    				(int) $total_items,
    				$text,
    				$topic_title
    			);
    		}
    
    		/**
    		 * @todo add title/description
    		 *
    		 * @since BuddyBoss 1.0.0
    		 */
    		do_action( 'bbp_format_buddypress_notifications', $action, $item_id, $secondary_item_id, $total_items );
    
    		return $return;
    	}
    
    	if ( 'bbp_new_at_mention' === $action ) {
    		$topic_id    = bbp_get_reply_topic_id( $item_id );
    
    		if ( empty( $topic_id ) ) {
    			$topic_id = $item_id;
    		}
    
    		$topic_title = bbp_get_topic_title( $topic_id );
    		$topic_link  = wp_nonce_url(
    			add_query_arg(
    				array(
    					'action'   => 'bbp_mark_read',
    					'topic_id' => $topic_id,
    					'reply_id' => $item_id,
    				),
    				bbp_get_reply_url( $item_id )
    			),
    			'bbp_mark_topic_' . $topic_id
    		);
    		$title_attr  = __( 'Discussion Mentions', 'buddyboss' );
    
    		if ( (int) $total_items > 1 ) {
    			$text   = sprintf( __( 'You have %d new mentions', 'buddyboss' ), (int) $total_items );
    			$filter = 'bbp_multiple_new_subscription_notification';
    		} else {
    			if ( ! empty( $secondary_item_id ) ) {
    				$text = sprintf( __( '%3$s mentioned you in %2$s', 'buddyboss' ), (int) $total_items, $topic_title, bp_core_get_user_displayname( $secondary_item_id ) );
    			} else {
    				$text = sprintf( __( 'You have %1$d new mention to %2$s', 'buddyboss' ), (int) $total_items, $topic_title );
    			}
    			$filter = 'bbp_single_new_subscription_notification';
    		}
    
    		// WordPress Toolbar
    		if ( 'string' === $format ) {
    			$return = apply_filters( $filter, '<a href="' . esc_url( $topic_link ) . '" title="' . esc_attr( $title_attr ) . '">' . esc_html( $text ) . '</a>', (int) $total_items, $text, $topic_link );
    
    			// Deprecated BuddyBar
    		} else {
    			$return = apply_filters(
    				$filter,
    				array(
    					'text' => $text,
    					'link' => $topic_link,
    				),
    				$topic_link,
    				(int) $total_items,
    				$text,
    				$topic_title
    			);
    		}
    
    		/**
    		 * @todo add title/description
    		 *
    		 * @since BuddyBoss 1.0.0
    		 */
    		do_action( 'bbp_format_buddypress_notifications', $action, $item_id, $secondary_item_id, $total_items );
    
    		return $return;
    	}
    
    	return $action;
    }
    add_filter( 'bp_notifications_get_notifications_for_user', 'bbp_format_buddypress_notifications', 10, 5 )
Viewing 1 replies (of 1 total)
  • Romeli

    (@romelirodriguez)

    Hi @ankitdev000, thanks a lot for you correction I really appreciate it.

    We will implement the changes to correct this issue in the next version of the plugin.

    Regards,
    Romeli

Viewing 1 replies (of 1 total)
  • The topic ‘Need some correction’ is closed to new replies.