WordPress.org

Ready to get started?Download WordPress

Forums

WooCommerce - excelling eCommerce
Show a different store/products/prices for each logged in user? (20 posts)

  1. bangbangmobile
    Member
    Posted 1 year ago #

    Hey guys, I have a client who is a custom printer (business cards, mugs, hats, etc.) and they want the ability to display different prices for each of these clients. Also, can I limit which products get shown to clients?

    To give you an example, Company ABC orders mugs at $1 each and Company XYZ orders the exact same mugs for $2 each. Also, Company QRS never orders mugs so there is no reason to display them as options.

    So can I limit which products are shown to which clients, AND can I set specific pricing for each client? (FYI, they manually create each client so they are entering specific details about each and it is not open to the public.)

    Kind of off topic but when a client does login to the system (their profile), does it show their previous orders and give them the ability to hit "reorder" ?

    I am trying to wrap my head around having, basically, a different store for each client.

    Thanks guys!
    Chris

    http://wordpress.org/extend/plugins/woocommerce/

  2. bangbangmobile
    Member
    Posted 1 year ago #

    So the more I think about this the closer I am getting.... could I add custom taxonomies to wooCommerce? I am thinking that if I added a CLIENT taxonomy then gave each client a tax, I could call to the page any client taxonomy that matched the username.... Thoughts?

  3. bangbangmobile
    Member
    Posted 1 year ago #

    Ok I think I should be able to add a Client Attribute with a specific price, the next question is can I call a list of products that have a specific attribute? For example, give me all products that have the Client Attribute that equals "Client ABC" ? Is this possible?

    Could I also call a list of categories that have products with this attribute?

  4. bheadrick
    Member
    Posted 1 year ago #

    attributes are taxonomies, so you'd just modify the loop query with a taxonomy query (and you can include multiple taxonomies within the query)

  5. bangbangmobile
    Member
    Posted 1 year ago #

    bheadrick, so something like this...

    $clientposts = new WP_Query(array( 'clients' => 'companyABC' ) );
      while ($clientposts->have_posts()) : $clientposts->the_post();
      $clientvalue = $clientposts->ID;

    I will give it a try!

    Thanks,
    Chris

  6. bangbangmobile
    Member
    Posted 1 year ago #

    Ok so no luck with the following:

    <?php
    global $current_user;
    get_currentuserinfo();
    $company = $current_user->billing_company;
    
    query_posts(array('post_type' => 'product', 'product_tag' => '$company'));
    if ( have_posts() ) : while ( have_posts() ) : the_post();
    ?>
    
    <?php the_title(); ?>
    
    <?php endwhile; endif; wp_reset_query(); ?>

    To reiterate what I need, since each of my clients will have different pricing on our products, I only want to display Products that have a Variation Attribute that matches my client's Billing Company. For example, display all products with a variation that equals Company ABC.

    I think we are almost there!

  7. bheadrick
    Member
    Posted 1 year ago #

    remove the quotes around $company
    also, I don't think you'd want to use product_tag for your company selector. I'd make it an attribute that's not visible on the product page
    also , keep in mind that the taxonomy name for attributes is going to have a 'pa_' prefix, so an attribute named "clients" would be "pa_clients"

  8. bangbangmobile
    Member
    Posted 1 year ago #

    Ok so since I was using product_tag instead of the taxonomy, I changed the code to this, but still no luck.

    global $current_user;
    // get logged in user's information
    get_currentuserinfo(); 
    
    // get logged in user billing company and convert it to lowercase
    $billing_company = strtolower($current_user->billing_company);
    
    // replace spaces in the billing company with hyphens
    $company = str_replace( " ", "-", $billing_company);
    
    // setup argument
    $args = array(
       'post_type' => 'product',  // first, call all products (wooproducts)
       'tax_query' => array(   // next, run a tax query on the Attributes...
          array(
    	'taxonomy' => 'pa_client',  // ... on all Client Attributes
    	'field' => 'slug',  // with a slug of...
    	'terms' => $company  // the user's billing company
          )
        )
    );
    
    $query = new WP_Query( $args );
    if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post();
    ?>

    This code is on a custom template assigned to the my-account page so when the user first logs in, they are taken to this page and on the left side they only see a list of items that have their company name as a Variation.

    I am so close! :) Thanks again for the help bheadrick!

    Thanks,
    Chris

  9. bangbangmobile
    Member
    Posted 1 year ago #

    Ok so I got it to work! The Client logs in, and in the left column of their My Account page, they see only Products that have an Attribute that matches their Company Name. Thank you for the guidance bheadrick!

    Now, can I HIDE the Client Attribute so they cannot choose the other Variations, which are other client's pricing? I assume that is done on the single product page...

    Thanks,
    Chris

  10. bheadrick
    Member
    Posted 1 year ago #

    you could use the woocommerce_attribute filter or you could just edit the product-attributes.php template to say if($attribute['name']!='pa_clients'):.... endif;

  11. bangbangmobile
    Member
    Posted 1 year ago #

    bheadrick, how would I show content based on Variation? So the Attribute is Client, and the Term for this Attribute is Company ABC, Company XYZ, etc. If I only want to show the Company ABC Variation for a logged in user whose Billing Company is equal to Company ABC, can I block all other Variations (like Company XYZ) ?

  12. bangbangmobile
    Member
    Posted 1 year ago #

    I am thinking I need to edit the variation.php file within this section:

    <td class="value"><select id="<?php echo esc_attr( sanitize_title($name) ); ?>" name="attribute_<?php echo sanitize_title($name); ?>">
    <option value=""><?php echo __('Choose an option', 'woocommerce') ?>&hellip;</option>
    <?php
    if ( is_array( $options ) ) {
    
    if ( empty( $_POST ) )
    $selected_value = ( isset( $selected_attributes[ sanitize_title( $name ) ] ) ) ? $selected_attributes[ sanitize_title( $name ) ] : '';
    else
    $selected_value = isset( $_POST[ 'attribute_' . sanitize_title( $name ) ] ) ? $_POST[ 'attribute_' . sanitize_title( $name ) ] : '';
    
    // Get terms if this is a taxonomy - ordered
    if ( taxonomy_exists( sanitize_title( $name ) ) ) {
    
    $terms = get_terms( sanitize_title($name), array('menu_order' => 'ASC') );
    
    foreach ( $terms as $term ) {
    if ( ! in_array( $term->slug, $options ) ) continue;
    echo '<option value="' . $term->slug . '" ' . selected( $selected_value, $term->slug, false ) . '>' . apply_filters( 'woocommerce_variation_option_name', $term->name ) . '</option>';
    }
    } else {
    foreach ( $options as $option )
    echo '<option value="' . $option . '" ' . selected( $selected_value, $option, false ) . '>' . apply_filters( 'woocommerce_variation_option_name', $option ) . '</option>';
    }
    }
    ?>
    </select> <?php
    if ( sizeof($attributes) == $loop )
    echo '<a class="reset_variations" href="#reset">'.__('Clear selection', 'woocommerce').'</a>';
    ?></td>

    hmmmmm....

  13. bheadrick
    Member
    Posted 1 year ago #

    doing this with variations is a bit difficult unless you write some jquery to automatically make the selection for you. The variation select boxes aren't used in the way you'd expect normal select fields to work. Basically, if javascript were turned off, you couldn't buy a variable item.

    Another option, there's an "update_price" function on the wc_product class, though I have yet to use it successfully, you could make your "client" a meta field instead of an attribute (which is something you can modify in bulk, unlike attributes).

    You could, then do a filter so the price displayed is the price the logged in customer gets, and if they're not logged in, you could display a custom message.

  14. bangbangmobile
    Member
    Posted 1 year ago #

    I feel like it is so close with the variations.php file but it looks like I will just have to create separate products for each Client, then filter the display based on Attribute = Client ABC. I was hoping I could edit the variations.php file above to display the option specifically for the logged in customer, but it's over my head :)

    Thanks for all the help.

  15. sarahhellems2
    Member
    Posted 11 months ago #

    Hey bangbangmobile, wondering if you got this all sorted out? I'm creating a site that needs the exact same functionality. Any help you can give would be much appreciated!

  16. jkbeck
    Member
    Posted 11 months ago #

    I'm also working on something similar. The target customers will be part of teams and will only be able to see the general items + their team gear. The other teams gear will be hidden.

    I've been able to add a custom team category to the registration using S2member plugin. I've also coded some functions to prevent anyone who is not logged in or not on a team from viewing another teams page.

    The final two things I need to do is figure out how to separate the store so that Team A can't browse Team B's gear or end up finding it using the Search function.

    I'll most likely be using WooCommerce plugin.

    Bang & Sara, have you guys reached a final solution?

  17. vark
    Member
    Posted 11 months ago #

    Hi Folks,
    We're a couple of weeks away from releasing a plugin which will do exactly this.

  18. jkbeck
    Member
    Posted 11 months ago #

    Will your plugin be compatible with WooCommerce?

    Is there any way to get updates on your status?

    Thanks,
    Justin

  19. vark
    Member
    Posted 11 months ago #

    Hi @jkbeck,
    If you look at the varktech.com website for the pricing deals plugin, you'll see the latest.
    Best,
    Vark

  20. homedog
    Member
    Posted 9 months ago #

    @bangbangmobile, i want to talk with u, please give me a e-mail adress? :) tnx

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic