WPEC Bulk Category Pricing
[resolved] Your plugin breaks if more than one category (3 posts)

  1. jn0101
    Posted 4 years ago #

    Please, code like

    if( ! in_array( $item->category_id_list[0], $bulk_categories ) )
                $eligible_products[$item->category_id_list[0]]['quantity'][$item->product_id] = $item->quantity;

    just screams to break. Initially users are happy... then they work on their products, add categories and boom.... your plugin doesent work anymore, or actually worse, sometimes break, sometimes doesent, depending on whether you are lucky that the bulk category ID is in $item->category_id_list[0] and not in $item->category_id_list[1].

    You need to use inner loops:

    foreach( $item->category_id_list as $cid ) {
    error_log('i2  id_list '. $cid);
                if( in_array( $cid, $bulk_categories ) ) {
                  $eligible_products[$cid]['quantity'][$item->product_id] = $item->quantity;

    Also here:

    //Check which category the product is in.
            $cat_id = $object_terms[0]->term_id;

    needs to be something like:

    foreach( $object_terms as $term ) {
              $cat_id = $term->term_id;
              $price = $price - $eligible_products[$cat_id]['discount'];


  2. jn0101
    Posted 4 years ago #

    You can download the code, fixed so multiple categories work, here:



  3. Justin Sainton
    Plugin Author

    Posted 4 years ago #

    Thanks for the tip! Your use case wasn't something we had in mind with the initial release, but it makes enough sense. I'll check out your changes, run some tests and release a new version soon.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WPEC Bulk Category Pricing
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic