Skip to:
Content
Pages
Categories
Search
Top
Bottom

Woocommerce Activity Entry Content & External Product URL


  • nm
    Participant

    @nahummadrid

    Trying to retrieve product url of external product for use in activity entry content. And it seems that the secondary_item_id isn’t available at the time the activity records. Image and title works normally but some reason I can get the product url. (If I use bp_activity_content_before_save and update the product, the product_url does record on update but not on first recording).

    add_filter('bp_before_activity_add_parse_args', 'record_cpt_product_activity_content');
    
    function record_cpt_product_activity_content( $cpt ) {
      
      if ( $cpt['component'] == 'blogs' && $cpt['type'] == 'new_product_post' ){
    
      $post = get_post( $cpt['secondary_item_id'] );
        $postid = $cpt['secondary_item_id'];
        $imgSize = '1x1';
    
      $product = wc_get_product($cpt['secondary_item_id']);
      $url = $product->product_url; 
      $insert_button = ( $url) ? '<a class="btn btn-primary" href="'.esc_url($url).'">Buy</a>' : '';
      
    
        /*template starts*/
    
        $cpt['content'] .= '<div class="card created">';
    
        if(has_post_thumbnail($postid)) {
          
        $cpt['content'] .= '<a href="'.get_permalink($postid).'">'.get_the_post_thumbnail($postid, $imgSize).'</a>';
        
        } 
    
        $cpt['content'] .= '<div class="card-body"><div class="card-title"><a href="'.get_permalink($postid).'">'.get_the_title($postid).'</a></div>
    
            <div class="card-author">
                <a href="'.bp_core_get_user_domain($post->post_author ).'">'.  bp_core_get_username($post->post_author) .'</a>
            </div>';
        
        $cpt['content'] .= '<div class="card_excerpt"><p>'.  wp_trim_words(get_post_field('post_content', $cpt['secondary_item_id'] ), 10, '...').'</p></div>';
       
        $cpt['content'] .= $insert_button;
    
        $cpt['content'] .= '</div></div><!--end-card-->';
    
        /*template ends*/
      }
            
        
        return $cpt;
    }
    
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.
Skip to toolbar