Home › Forums › Plugins › Wholesale Pricing › Support › Question About Edits to Product Templates
- This topic has 4 replies, 4 voices, and was last updated 11 years, 11 months ago by finifinito.
Welcome to our community support forums! We're here to help - but if you have an urgent request for a Pro Plugin, you will get a prioritised response through our Premium Support page.
-
AuthorPosts
-
September 29, 2011 at 11:26 am #8403bnance63Participant
Can anyone verify the instructions for updating the product templates for hiding/showing products?
The readme says:
2. Open 'wpsc-products_page.php' and paste '' on line #663. Open 'wpsc-single_product.php' and paste '' on line #30
Does the your function call come before or after the beginning of product loop? Does it replace part of the loop?My files have code on the stated line numbers, so I’m not clear where you code should go.
I have tried it everywhere I could think of and it breaks the site.
Follow up question: Do we need an
endif
anywhere?October 11, 2011 at 9:06 am #8498tracyyikesParticipantI have the same question. The directions for editing the product-template.php file are very clear, but not these. Can you please describe the surrounding code and exactly where it needs to go?
Thanks!
October 12, 2011 at 12:17 am #8506seriouslyseanParticipantNo matter what I was trying, I couldn’t get the guest visibility to work. I had to copy the wpsc_wp_is_product_visible() function, rename it, and make changes to it in my own functions.php file to get it to work.
I’m not sure if it will help anyone on here, but hopefully it will. The changes I made will request the post data for all user roles (including guest, which wasn’t happening before). In order to get this to work, do the following steps in order.
Just be advised, for any update after the 3.8 version of WP-eCommerce, this fix MAY break if they decide to make changes to the way their built in function works. When that happens, you will have to go back and change these back to the way they suggested.
1.) Copy the following to your ‘functions.php’ file in your theme directory and then save the file
function sp_wpsc_wp_is_product_visible()
{
// Check if the user is logged in
if(is_user_logged_in())
{
global $current_user;
get_currentuserinfo();
$role = $current_user->roles[0];
}
else
{
$role = ‘guest’;
}// Get the product information
switch(wpsc_get_major_version())
{
case ‘3.7’:
$checkbox = get_product_meta( wpsc_the_product_id(), ‘wpsc_wp_checkbox’, true );
break;case ‘3.8’:
global $post;
$post_id = $post->ID;
if(!$post_id)
$post_id = $product_id;
$product_data = get_post_custom($post_id);
$product_data[‘meta’] = maybe_unserialize($product_data);
if($product_data[‘meta’])
{
foreach($product_data[‘meta’] as $meta_key => $meta_value)
$product_data[‘meta’][$meta_key] = $meta_value[0];
$product_meta = maybe_unserialize($product_data[‘_wpsc_product_metadata’][0]);$checkbox = $product_meta[‘wpsc_wp_checkbox’];
}
break;
}// See if the visibility is actuall enabled
if($checkbox[$role] == ‘on’)
{
// User per-Product visibility for that User Role, including Site Visitors
switch(wpsc_get_major_version())
{
case ‘3.7’:
$visibility = get_product_meta( wpsc_the_product_id(), ‘wpsc_wp_visibility’, true );
break;default:
case ‘3.8’:
$visibility = $product_meta[‘wpsc_wp_visibility’][$role];
break;
}switch($visibility)
{
case ‘0’:
return false;
break;default:
case ‘1’:
return true;
break;
}
}
else
{
return true;
}
}2.) In your ‘wpsc-products_page.php’, search for
<?php while (wpsc_have_products()) : wpsc_the_product(); ?>
and change it to the following:
<?php while (wpsc_have_products()) : wpsc_the_product(); ?>
<?php if(sp_wpsc_wp_is_product_visible()) : ?>Then look for the closing tag of the loop
<?php endwhile; ?>
<?php /** end the product loop here */?>And change it to the following
<?php endif; ?>
<?php endwhile; ?>
<?php /** end the product loop here */?>3.) In your ‘wpsc-single_product.php’, search for
<?php
/**
* Start the product loop here.
* This is single products view, so there should be only one
*/while ( wpsc_have_products() ) : wpsc_the_product(); ?>
and change it to the following:
<?php
/**
* Start the product loop here.
* This is single products view, so there should be only one
*/while ( wpsc_have_products() ) : wpsc_the_product(); ?>
<?php if(sp_wpsc_wp_is_product_visible()) : ?>Then look for the closing tag of the loop
<?php endwhile;
do_action( 'wpsc_theme_footer' ); ?>
And change it to the following
<?php endif; endwhile;
do_action( 'wpsc_theme_footer' ); ?>
October 12, 2011 at 12:34 am #8509seriouslyseanParticipantbnance63, if you want to just use their built in function, you can just skip the first step and follow steps 2 and 3 using ‘wpsc_wp_is_product_visible()’ instead of ‘sp_wpsc_wp_is_product_visible()’.
Hope this helps!
December 20, 2011 at 6:41 am #8975finifinitoParticipantI tried this solution above and it breaks my theme. I’m just using the basic WordPress 2011 theme on the latest 3.3 install of WordPress, 3.8 WP Ecommerce plugin and the most recent Wholesale Pricing plugin. I desperately need to hid products for wholesale customers only on my client’s site. Any help would be greatly appreciated.
-
AuthorPosts
- The forum ‘Support’ is closed to new topics and replies.