Hello,
Under Wordpress, I have a form with 1 single field intended to check the validity of a discount coupon.
Verification is done correctly.
My problem is that if the coupon is valid, I try to include it in a url.
Despite my various attempts, I am unable to generate in php the link including the valid variable ($coupon = XXXX in this example).
The Link I am looking to obtain is of the type: https://www.monsite.com/XXXX
Here is the code used:
add_shortcode( 'coupon_field', 'display_coupon_field' );
function display_coupon_field() {
if( isset($_GET['coupon']) && isset($_GET['redeem-coupon']) ){
$coupon_code = wc_format_coupon_code($_GET['coupon']);
$coupon = new WC_Coupon( $coupon_code );
if ( $coupon->is_valid() ) {
$makeredirection = header("Location: https://www.xxx.com/". $coupon); (<<<<<< don't work)
} else {}
$success = __('The coupon "%s" is valid! ');
$error = __("Error: coupon not valid");
$message = isset($makeredirection) && $makeredirection ? $success : $error;
}
$output = '<div class="cadre-coupon">
<div class="redeem-coupon">
<form id="coupon-redeem">
<h2 style="text-align: center; color: #ff00ff;">Redeem coupon</h2>
<input type="text" name="coupon" id="coupon" placeholder="Put coupon code here..."/>
<input type="submit" class="bouton-coupon" name="redeem-coupon" value="' .__('Redeem Coupon!'). '"/>';
return $output . '</form><p>'. $message .'</p></div></div>';
}
Who would be kind enough to give me a hand on this problem? I can't solve it...
if I try to modify like this:
$makerredirection = header("Location: https://www.xxx.com/". $coupon);
I get an incomprehensible link of a length URL who's make error (forbidden nginx) as this : https://www.xxx.com/%7B%22id%22:91731,%22code%22:%22adlr-mmmp-z4hh%22,%22amount%22:%22100%22,%22status%22:%22publish%22,%22date_created%22:%7B%22date%22:%222022-04-26%2009:20:47.000000%22,%22timezone_type%22:1,%22timezone%22:%22+00:00%22%7D,%22date_modified%22:%7B%22date%22:%222022-09- etc etc etc
I use Wordops and use the php 7.4.
Perhaps this is a probleme of activated module in the php.ini of the 7.4 ? or a urlencode / urldecode of php?
Perhaps a missing config into the nginx.conf ?
I am new in WordOps so i don't know if this is a bad setting by me ? I search a solution but i'am not able to find the correct answer...
In my thinking, i am tell myself that developper of WordOps can see why i have this error? Or somebody who have this already the same problem ?
The form is placed on my header and is showing anywhere by a shortcode (code included into my functions.php child theme).
I need use this code for linking correctly if the coupon code is valid and add automaticly the "free product" linked with the good code for the customer only have to validate his basket (for the better simplified solution)...
I hope that i have good describe the problem i have and hope too that somebody can help me to fix this...
Thanks in advance
Jemo