Woocommerce Custom Logged-in Price not transferring to Checkout
-
Hi
In a WooCommerce store I want to offer a 20% discount to logged in users for a particular brand.
The following code is successful in displaying the correct pricing on the product and archive templates, however the discounted price is not appearing in the cart or checkout
Any ideas? TIA ????
// Utility function to change the prices with a multiplier (number) function get_price_multiplier() { $prod_id = get_the_ID(); $terms = get_the_terms($prod_id,'product_brand'); $brands = array(); $brand = ''; $count = 0; if(is_array($terms)) { foreach ($terms as $term) { $count ++; if($count == 1) { $brand = $term->slug; } } } if ( (is_user_logged_in()) && ($brand == 'acme') ) { return 0.8; // 20% off } else { return 1; } } // Simple, grouped and external products add_filter('woocommerce_product_get_price', 'custom_price', 99, 2 ); add_filter('woocommerce_product_get_regular_price', 'custom_price', 99, 2 ); // Variations add_filter('woocommerce_product_variation_get_regular_price', 'custom_price', 99, 2 ); add_filter('woocommerce_product_variation_get_price', 'custom_price', 99, 2 ); function custom_price( $price, $product ) { return (float) $price * get_price_multiplier(); } // Variable (price range) add_filter('woocommerce_variation_prices_price', 'custom_variable_price', 99, 3 ); add_filter('woocommerce_variation_prices_regular_price', 'custom_variable_price', 99, 3 ); function custom_variable_price( $price, $variation, $product ) { // Delete product cached price (if needed) wc_delete_product_transients($variation->get_id()); return (float) $price * get_price_multiplier(); } // Handling price caching (see explanations at the end) add_filter( 'woocommerce_get_variation_prices_hash', 'add_price_multiplier_to_variation_prices_hash', 99, 3 ); function add_price_multiplier_to_variation_prices_hash( $price_hash, $product, $for_display ) { $price_hash[] = get_price_multiplier(); return $price_hash; }
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Woocommerce Custom Logged-in Price not transferring to Checkout’ is closed to new replies.