/>
/>

/> />


get_col( $wpdb->prepare( "SELECT object_id FROM `".WPSC_TABLE_META."` WHERE `meta_key` = 'use_bulk_pricing' AND meta_value = 1" ) ); $category_ids = array_unique( $wpsc_cart->get_item_category_ids() ); $bulk = false; foreach( $category_ids as $id ) { if( in_array( $id, $bulk_categories ) ) $bulk = true; } if( ! $bulk ) return $bulk; //At this point, we know we have categories in the cart that are potentially eligible for bulk pricing. $eligible_products = array(); foreach( $wpsc_cart->cart_items as $item ) { foreach( $item->category_id_list as $cid ) { if( in_array( $cid, $bulk_categories ) ) { $eligible_products[$cid]['quantity'][$item->product_id] = $item->quantity; } } } //Loop de doop foreach( $eligible_products as $cat => &$product ) { $bulk_price_threshold = wpsc_get_categorymeta( $cat, 'bulk_pricing_threshold' ); if( array_sum( $product['quantity'] ) < $bulk_price_threshold ) unset( $eligible_products[$cat] ); else $product['discount'] = wpsc_get_categorymeta( $cat, 'bulk_pricing_discount' ); } return $eligible_products; } public function modify_price($price, $product_id) { $object_terms = wp_get_object_terms( $product_id, 'wpsc_product_category' ); //If is_item_bulk method is populated, it's populated with an array of the categories $eligible_products = $this->is_item_bulk( $product_id ); //If no items in cart are in bulk categories, just return the price if( ! $eligible_products ) return $price; //error_log('modify_price ' . print_r( $eligible_products, 1)); //error_log('modify_price2 ' . print_r( $object_terms, 1)); //Check which category the product is in. //$cat_id = $object_terms[1]->term_id; //$price = $price - $eligible_products[$cat_id]['discount']; foreach( $object_terms as $term ) { $cat_id = $term->term_id; $price = $price - $eligible_products[$cat_id]['discount']; //error_log('modify_price3 ' . $cat_id); } //echo '
' . print_r( $eligible_products, 1 ) . '
'; unset( $eligible_products ); return $price; } public function refresh_cart() { global $wpsc_cart; if( is_admin() ) return; foreach( $wpsc_cart->cart_items as $key => &$value ) { $wpsc_cart->cart_items[$key]->refresh_item(); $wpsc_cart->clear_cache(); } } } new WPEC_Bulk_Category_Pricing; ?>