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

    (@josk79)

    You’d have to do some PHP scripting in functions.php. Take a look at the woocommerce_get_price_html filter.

    Thread Starter es_ther

    (@es_ther)

    My coupon has an amount and products for the coupon. No rules for shipping, qty, etc. The coupon amount will be applied for some products. I tried to find code examples without a luck.

    add_filter( ‘woocommerce_get_price_html’, ‘show_coupon_amount_shop’, 10, 2 );
    function omniwp_credit_dollars_price( $price, $product ) {
    …find if coupon exist…
    …change price format…
    }
    I just need to know there is a coupon for a product. Any help?

    Plugin Author Soft79

    (@josk79)

    Are you talking about bulk pricing? I’m working on a plugin that does just that, but without the use of coupons. If you are interested please post this question on https://www.soft79.nl/support and I can send you the current development version.

    If not, the WC_Coupon class has a is_valid_for_product() function that seems to be what you’re looking for.

    Thread Starter es_ther

    (@es_ther)

    It’s not perfect but I figured out somehow.
    First, add meta in product post, say ‘nam_coupon_code’ and put value, ‘100off’ etc.
    Then change the function as below.

    add_filter( ‘woocommerce_get_price_html’, ‘show_coupon_amount_shop’, 10, 2 );
    function show_coupon_amount_shop( $price, $product ) {
    /*…. whatever for price format reg price or saleprice….*/
    /* Show Coupon – use product meta: nam_coupon_code – still not perfect */
    $coupon_exist = get_post_meta( $product->post->ID, ‘nam_coupon_code’, true );
    if ($coupon_exist && $price == $saleprice) {
    $price = ‘<del>’ . $saleprice . ‘</del>’;
    }
    else if($coupon_exist && $price != $saleprice) {
    $price = ‘<del>’ . $price . ‘</del>’;
    }
    return $price;
    }

    There is a glitch showing before coupon price at the buy button, but it’s OK for now. I hope it helps anyone looking for a similar job.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Show coupon on shop page’ is closed to new replies.