• Resolved axos1192

    (@axos1192)


    Hello,

    I ran into the issue with lower sale price as the tier prices. I understand the explanation here Tiered Pricing Table and Sales | www.ads-software.com how the logic works as of now, but I think there should be at least the option to set the tier prices to the maximum of the sale price. E.g. If the price is 10 the tier price is 9 for 10 pieces and a sale price would be 8, then if in my opinion the tier price should be 8 for 10 pieces as well. So just flat out the same price.

    Right now I have the issue that the 10 pieces would be more expensive per piece than 9.

    Any chance we could get a fix on that?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author WP Developer

    (@bycrik)

    Hello @axos1192,

    This is wholly expected behavior. We will not restrict tiers that are higher than regular/sale prices because some users actually increase their prices when the quantity goes up, so flat price tiers give you complete control over those cases.

    As mentioned in that thread, you can use percentage-based tiers to calculate the prices based on the sale or regular price (this is controlled in the settings). You can also have a CSV import file to quickly update your flat price tiers when the sale price is present.

    The plugin also provides the “tiered_pricing_table/price/pricing_rule” hook, which you can use to modify the pricing at runtime. See examples in the src/PriceManager.php file.

    Hope this helps.

    Thread Starter axos1192

    (@axos1192)

    Hello @bycrik ,

    thanks for your fast response. I still have the feeling that the use-case you described is quite an edge-case but agree to disagree ?? Maybe you will implement it optionally in the future or in the premium version of the plugin.

    I did actually use your hook but i you have to get the sale state by postmeta query because I tried to get the product object by wc_get_product() from the id but that triggers an infinite loop with the provided hook “tiered_pricing_table/price/pricing_rule”. So not optimal but it works.

    Thanks for the fast and, even if the solution is not completely perfect, great support!

    Plugin Author WP Developer

    (@bycrik)

    @axos1192,

    You can use “edit” context to not pass the property through hooks when you get it.

    Here is the code that should work for you:

    	add_filter( 'tiered_pricing_table/price/pricing_rule', function ( \TierPricingTable\PricingRule $pricingRule, $productId ) {
    if ( $pricingRule->isPercentage() ) {
    return $pricingRule;
    }

    $product = wc_get_product( $productId );

    if ( ! $product ) {
    return $pricingRule;
    }

    $pricingRules = $pricingRule->getRules();
    $salePrice = $product->get_sale_price('edit');

    if ( $salePrice ) {

    // filter prices that are less than sale price
    $pricingRules = array_filter( $pricingRules, function ( $price ) use ( $salePrice ) {
    return $price < $salePrice;
    } );

    $pricingRule->setRules( $pricingRules );
    }

    return $pricingRule;

    }, 999, 2 );
    Thread Starter axos1192

    (@axos1192)

    Thanks for your response, I definitely learnt something new. I adapted the solution to my needs, I still want to have all rules available because I do add the tables in the frontend myself with direct add to cart options. Your solution feels a little bit snappier than mine.

    add_filter('tiered_pricing_table/price/pricing_rule', 'change_pricing_rule_v2', 50, 2);

    function change_pricing_rule_v2($pricing_rule, $product_id) {
    if ( $pricing_rule->isPercentage() ) { return $pricing_rule; }
    $product = wc_get_product( $product_id );
    if ( ! $product ) { return $product_id; }

    $pricingRules = $pricing_rule->getRules();
    $salePrice = $product->get_sale_price('edit');

    if ($salePrice) {
    $pricingRules = array_map(function($rule) use ($salePrice) {
    return min($rule, $salePrice);
    }, $pricingRules);

    $pricing_rule->setRules($pricingRules);
    }

    return $pricing_rule;
    }

    Thanks! I definitely appreciate your effort!

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.