How to change the Activity Stream Output

WC4BP insert a line into the BuddyPress Activity Stream when a Product receives a review or a Product is bought.

The next image is an example.

If you like to change the HTML of this Activities Streams you will need to implement it from the code. 

Let follow the next example where we build the code to change the HTML output.

Code

Exist 2 filters to customize the Stream output.

Filter to change the HTML output when a Product is bought.
apply_filters('wc4bp_stream_order_complete', $text_output, $user_id_from_order, $order, $order_items, $stream_action);

Parameters details:

  • $text_output --> string to return from the filter implementation
  • $user_id_from_order --> the user id from the Order
  • $order --> the Woocommerce Order
  • $order_items --> the items from the Order
  • $stream_action --> the action name for this Activity Stream is `order_complete`

Example:

class wc4bpChangesActivityStream {
   public function __construct() {
      /** @see class/wc4bp-activity-stream.php:164 */
      add_filter( 'wc4bp_stream_order_complete', array( $this, 'callback_stream_order_complete' ), 10, 5 );
   }

   /**
    * Override the Activity Stream for Order Complete
    *
    * @param string $text_output
    * @param int $user_id_from_order
    * @param WC_Order $order
    * @param WC_ORder_Item[] $order_items
    * @param string $stream_action
    *
    * @return string
    */
   public function callback_stream_order_complete( $text_output, $user_id_from_order, $order, $order_items, $stream_action ) {
      $user_link = bp_core_get_userlink( $user_id_from_order );

      $names = array();
      /** @var WC_Order_Item_Product $item */
      foreach ( $order_items as $item ) {
         $names[] = '<a href="' . $item->get_product()->get_permalink() . '">' . $item->get_product()->get_name() . '</a>';
      }

      return sprintf(
         'The user: %s bought %s',
         $user_link,
         implode( ', ', $names )
      );
   }
}
Filter to change the HTML output when a Product receives a Review.
apply_filters('wc4bp_stream_product_review', $text_output, $user_id, $comment_data, $product, $stream_action);

Parameters details:

  • $text_output --> string to return from the filter implementation
  • $user_id --> the user id who write the Review
  • $comment_data --> the comment WP Object
  • $product --> the Woocommerce
  • $stream_action --> the status of the Order, in this case is `product_review`

Example:

class wc4bpChangesActivityStream {
   public function __construct() {
      /** @see class/wc4bp-activity-stream.php:83 */
      add_filter( 'wc4bp_stream_product_review', array( $this, 'callback_stream_product' ), 10, 5 );
   }

   /**
    * Override the Activity Stream for Product Review
    *
    * @param string $text_output
    * @param int $user_id
    * @param WP_Comment $comment_data
    * @param WC_Product $product
    * @param string $stream_action
    *
    * @return string
    */
   public function callback_stream_product( $text_output, $user_id, $comment_data, $product, $stream_action ) {
      $user_link = bp_core_get_userlink( $user_id );

      return sprintf(
         'The Product: <a href="%s">%s</a> receive a Review from the user %s',
         get_permalink( $comment_data->comment_post_ID ),
         $product->get_title(),
         $user_link
      );
   }
}

Git code example

The above code examples are available in the next repository. These examples are for study, they are not ready to be used in production. 

https://github.com/Themekraft/wc4bp-changes

Customize the Card

To customize the cards, you will need to override a template in your theme. Read more about these topics in the next links.

Help us,  Rate it 

Still need help? Contact Us Contact Us