Tag Archives: WordPress

Shopp: Custom Discount Price for Products

I’m not sure if anyone will ever have a need for this, but we had a random request from a client regarding price discounts in Shopp. Shopp has a built in discount function that you can set on a product by product basis, but we needed to show a 20% discount automatically based on the list price for each product.

How to:

So the first thing we did was open the product.php template (wp-content > plugins > shopp > core > model > product.php) and create a new case for the product table called “pricediscounted”. This will check the list price of a product and deduct 20%.

1
2
3
4
5
case "pricediscounted":
     if (empty($this->prices)) $this->load_data(array('prices'));
     $list_price = $this-> min['price'] + ($this-> min['price']*$taxrate);
     return money($list_price - ($list_price*0.20));
     break;

Next we wanted to show the exact amount the user would be saving. So we created another case that would calculate what 20% would amount to.

1
2
3
4
5
case "pricepercent":
     if (empty($this->prices)) $this->load_data(array('prices'));
     $list_price = $this->min['price'] + ($this->min['price']*$taxrate);
     return money($list_price - ($list_price*0.80));
     break;

Finally, here is an example of how you can display this information on your site. Simply place the following anywhere you are using the product loop.

1
2
3
List Price: <?php shopp('product','price'); ?>
Online Price: <span><?php shopp('product','pricediscounted'); ?>
A savings of: <?php shopp('product','pricepercent'); ?>

WordPress: Query Posts by Taxonomy Term Value

Here’s a simple way to create a custom query for posts by term value. It’s pretty straight forward but if you see a way to improve it, feel free to let me know.

The Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php
// Define the arguments for the query here.
$args=array(
  'taxonomy' => 'taxonomy_slug_here',
  'term' => 'term_slug_here',
  'post_type' => 'custom_post_type_slug_here',
  'posts_per_page' => -1,
  'caller_get_posts'=> 1,
  'orderby'=> 'post_date',
  'order'=> 'ASC',
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
   while ($my_query->have_posts()) : $my_query->the_post(); ?>
    Call the post content here
   <?php endwhile;
} wp_reset_query(); ?>

Wishlist Member: Check Membership Level

Have you ever wanted to display different content based on Wishlist Member levels in WordPress? I did. After starting development on a recent project using WLM, I had a hard time finding documentation for specific hooks or functions. I even tried contacting the dev team, but never received a reply… and their documentation is pretty much non-existent. Basically if you are wanting anything other than out-the-box functionality it’s like pulling teeth as you won’t find much out there.

Anyway, if you are running a membership site via WLM and are looking to offer your content in a drip feed on the same page, and not just on a page by page basis, here’s what you can do:

The Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
// Get the current user level from WP
$user = wp_get_current_user();
 
// Get user levels from WishlistMembers
$levels = WLMAPI::GetUserLevels($user->ID);
 
// Then run the check for the level you want like this:
if(in_array('silver', $levels)){
  //  Display silver level content here
}
elseif (in_array('gold', $levels)){
   // Display gold level content here
}
?>

WordPress Taxonomies: Displaying Terms as Text

While using custom post types on a recent site, I ran into a situation where I wanted to list the terms(taxonomies) associated to a post. The function get_the_terms worked great, but I wanted to list the terms as text and not URLs. The first thing that came to mind was to use “strip_tags”, but that just felt dirty… so here’s a simple solution to display a post’s terms as text and not URLs.

The Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php function get_language_terms($args) {
            // Get terms for post
            $terms = get_the_terms( $post->ID , $args );
 
            if ( !empty( $terms ) ):
                // Loop over each item since it's an array
                foreach( $terms as $term ) {
                    // Print the name method from $term which is an OBJECT
                    echo $term->name;
                    // Get rid of the other data stored in the object, since it's not needed
                    unset($term);
           } endif;
 
} ?>

Then place this inside the loop and specify the argument for which taxonomy you are wanting to list terms for.

1
<?php get_language_terms('taxonomy_slug_goes_here'); ?>

I hope this can help someone else as well!

Older Posts