Mariol
Mariol

Reputation: 33

Adding custom text with a link via PHP function in Woocommerce

I'm trying to add additional text woocommerce_before_checkout_form in functions.php via Editor but I see following error:

"Your PHP code changes were rolled back due to an error on line 0 of file Unknown. Please fix and try saving again. Exception thrown without a stack frame"

function bonus() {
    echo "<div id='bonus'>Don't you have a coupon?<a href="https://mywebsite.com/checkout/?apply_coupon=promo5?apply_coupon=promo5">Click here to get 5% OFF</a></div>";
}

add_action( 'woocommerce_before_checkout_form', 'bonus' );

When I add only text without ahref everything works.

I want to add to this ahref redirect to: https://mywebsite.com/checkout/?apply_coupon=promo5

Upvotes: 0

Views: 1036

Answers (2)

dipmala
dipmala

Reputation: 2011

You have used double quote within double quote that is the reason error is coming.

Try below code it will work.

function bonus() {
  echo "<div id='bonus'>Don't you have a coupon?<a href='https://mywebsite.com/checkout/?apply_coupon=promo5?apply_coupon=promo5'>Click here to get 5% OFF</a></div>";
    }

  add_action( 'woocommerce_before_checkout_form', 'bonus' );

Upvotes: 1

Vel
Vel

Reputation: 9257

Try this.

You need to change <a href="https://mywebsite.com/checkout/?apply_coupon=promo5?apply_coupon=promo5"> to <a href='https://mywebsite.com/checkout/?apply_coupon=promo5?apply_coupon=promo5'>

function bonus() {
    echo "<div id='bonus'>Don\'t you have a coupon?<a href='https://mywebsite.com/checkout/?apply_coupon=promo5?apply_coupon=promo5'>Click here to get 5% OFF</a></div>";
}

add_action( 'woocommerce_before_checkout_form', 'bonus' );

Upvotes: 2

Related Questions