• Resolved VinzClortho

    (@vinzclortho)


    Hello,
    in my shop I have many products with a price already discounted in wc. When I apply a discount rule I would like it to be possible for the customer to understand in the product page if the discounted price is due to the discount rule. Is there a way to show a text on the product sheet or in the checkout only when the rule is applied? For example, “Amount saved” display text indicates the cumulative saved price of all the discounts, both those set in wc and through this plugin.
    I appreciate it if you can provide me with a php snippet that checks in the product or in the checkout if a rule is applied.

    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author algol.plus

    (@algolplus)

    hello

    please, tweak this code, I have to use “tag” , as forum removes html tags from my code.

    add_action( 'woocommerce_after_cart_item_name', function($cart_item, $cart_item_key){
    if(empty($cart_item["adp"]["discount"])) return;
    $value = 0;
    foreach($cart_item["adp"]["discount"] as $rule_id=>$amounts)
    $value += array_sum($amounts);
    if($value>0)
    echo "tag Discount by rule = " . wc_price($value) . "tag";
    },10,2);

    • This reply was modified 5 months, 1 week ago by algol.plus.
    • This reply was modified 5 months, 1 week ago by algol.plus.
    Thread Starter VinzClortho

    (@vinzclortho)

    Hi, thanks for your reply!

    The snippet works fine, but it only applies to the cart, I would like to be able to show it in the product page.

    I saw that you query the $cart_item object to check if an adp discount rule is applied. Is there a way to get this information also in the product page, querying for example $product?

    Thank you

    • This reply was modified 5 months, 1 week ago by VinzClortho.
    Plugin Author algol.plus

    (@algolplus)

    Useful link https://www.businessbloomer.com/woocommerce-visual-hook-guide-single-product-page/

    please, modify this code

    add_action( 'woocommerce_before_add_to_cart_button', function(){
    global $product;
    $processedProduct = adp_functions()->calculateProduct($product, $qty = 1, $useEmptyCart = true);
    if($processedProduct instanceof ADP\BaseVersion\Includes\PriceDisplay\ProcessedProductSimple) {
    $discount = $product->get_price() - $processedProduct->getCalculatedPrice();
    }
    elseif($processedProduct instanceof ADP\BaseVersion\Includes\PriceDisplay\ProcessedVariableProduct) {
    $discount = $product->get_variation_price('min') - $processedProduct->getLowestPrice();
    }
    if($discount>0)
    echo "Discount by rule = " . wc_price($discount) . "";
    });

    Thread Starter VinzClortho

    (@vinzclortho)

    Perfect! Thank you very much, you were very kind!

    Plugin Author algol.plus

    (@algolplus)

    You’re very welcome ??

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