1. Home
  2. ReHub Theme
  3. Advanced tips and customizations
  4. How to use woocommerce as classified site

How to use woocommerce as classified site

What is difference between classified shop and regular shop? Classified site doesn’t sell anything. Vendors (sellers) just add products and their contacts. When buyer wants to buy something, he contacts with vendor.

Now, I will show you some simple ways to do this.

1 way – Private messages (Buddypress)

When user clicks on contact button, he goes to private messages and can send message to vendor.

To do such logic, you need to enable Buddypress plugin and Message extension (in Settings – Buddypress)

Then, inside in functions.php of child theme or grandchild plugin, add next code (How to customize your theme)

function woocommerce_template_single_add_to_cart() {
  global $product, $post;
  $link = $class_show = '';
    if(class_exists( 'BuddyPress' )){
    	if ( bp_is_active( 'messages' )){
    		$author_id=$post->post_author;
    		$link = (is_user_logged_in()) ? wp_nonce_url( bp_loggedin_user_domain() . bp_get_messages_slug() . '/compose/?r=' . bp_core_get_username($author_id) .'&ref='. urlencode(get_permalink())) : '#';
      $class_show = (!is_user_logged_in() && rehub_option('userlogin_enable') == '1') ? $class_show.' act-rehub-login-popup' : '';    		
    	}
    }		
  echo '<p class="cart">';
  echo '<a href="'.$link.'" class="single_add_to_cart_button button alt '.$class_show.'">Contact with author';
  echo'</a></p>';		
}

Private messages are available only for Logged Users, if user is guest, he will see popup form to register or login (how to configure popup form in theme)

This code will change default button of products on product page to “Contact” button. You can change also label in button in code (Change “Contact with author”)

There are also inner buttons in archives. You can disable them at all in  Theme option – shop settings  or you can also change buttons on contact button with next code

add_filter('woocommerce_loop_add_to_cart_link', 'rh_change_woo_btn_in_archives');
function rh_change_woo_btn_in_archives(){
  global $product, $post;
  $link = $class_show = '';
    if(class_exists( 'BuddyPress' )){
    	if ( bp_is_active( 'messages' )){
    		$author_id=$post->post_author;
    		$link = (is_user_logged_in()) ? wp_nonce_url( bp_loggedin_user_domain() . bp_get_messages_slug() . '/compose/?r=' . bp_core_get_username($author_id) .'&ref='. urlencode(get_permalink())) : '#';
      $class_show = (!is_user_logged_in() && rehub_option('userlogin_enable') == '1') ? $class_show.' act-rehub-login-popup' : '';    		
    	}
    }		
  return '<a href="'.$link.'" data-product_id="'.$post->ID.'" class="re_track_btn woo_loop_btn btn_offer_block product_type_external'.$class_show.'">Contact vendor</a>';
}

 2 way – Contact form in Popup

Second way doesn’t require user registration and profiles and can work only for guests.

First of all, install and activate plugin Contact Form 7. Then, create new form. Now, in settings of form, you can add recepient of email which will be author of product (vendor). To do this, add shortcode

[_post_author_email]

to field, like this

Then, save form and copy shortcode of form.

Next, add this code to functions.php

function woocommerce_template_single_add_to_cart() {
  $link = $class_show = '';
  $idpopup = 'woo_popup'.uniqid();
  $shortcode = '[contact-form-7 id="31386" title="Untitled"]';		
  echo '<p class="cart">';
  echo '<a href="#" class="single_add_to_cart_button button alt csspopuptrigger" data-popup="'.$idpopup.'">Contact with author';
  echo'</a></p>';
  echo '<div class="csspopup" id="'.$idpopup.'"><div class="csspopupinner"><span class="cpopupclose" href="#">×</span><div class="woo_cform7_popup">'.do_shortcode($shortcode).'</div></div></div>';		
}

Place your shortcode of form in line

$shortcode = '[contact-form-7 id="31386" title="Untitled"]';

That’s all. In archives of shop, I recommend to disable buttons at all, because several same contact forms on one page can have bugs. To disable buttons, go to  Theme option – shop settings – Disable button in product loop? 

You can configure email which will get vendor. For example, I think it’s good to add Product title from which user contacts with vendor. You can add in Message Body field of form next shortcode

-------------

User is interested in [_post_title]

You can check your product here [_post_url]

-------------

Other mailtags can be found here

To make product submit from frontend – Use RH Frontend PRO plugin (bundled), get it from Rehub – plugins. If you use Buddypress, you can add form to User profile You can also add submit page link in user dropdown menu. Also check some docs for RH Frontend PRO

Add user phone in product

If you have any plugin on site where user can add own phone and you want to show this phone on site in product page, you can use next shortcode to retrieve any meta field from user’s profile

If you want to get user meta from user profile, use
[rh_get_profile_data usermeta=_phone userid=author]

This will show user meta _phone for author of post or product

Now, you can use this shortcode in custom code areas of product

Was this article helpful to you? Yes No

How can we help?