Reply 320670 to: Need help: plugin Smart Coupon seems to not be compatible with the theme

Avatar: Jemo
Jemo
Participant
March 27, 2022 at 14:50

Hi,

thanks for reply.

In fact, a “dedicated product” should display all templates from “gift card” of the “smart coupon plugin”.

The product that should display all the template is: https://www.jetentemachance.com/boutique/bons-dachats-recompenses/

The setting for this product is here: https://www.jetentemachance.com/wp-admin/post.php?post=84793&action=edit

And the setting from the plugin for this is here: https://www.jetentemachance.com/wp-admin/admin.php?page=wt-smart-coupon-for-woo_store_credit#wt-sc-gift-card-template

I have try to take your code and update it for the “smart coupon plugin” (pro version) as this:

 // Make Smart Coupon compatible with XStore
add_action('init', function() {
	if (function_exists('wt-smart-coupons-for-woocommerce-pro')) {
		add_action( 'etheme_woocommerce_template_single_excerpt', 'wt-smart-coupons-for-woocommerce-pro', 25 );
	}
});

but this make critical error (in fact i don’t understand how make this update and not if it is the good way…

*********************AND*********************** (another thing)
(code source from here: https://www.sitepoint.com/creating-a-woocommerce-redeem-coupon-page/)

perhaps you can help me for the other problem i see (another problem):

The fact: i want to display a “have a coupon” form on the front (homepage header) of my website.

so i have use this code:


//******************** RECLAMATION COUPON DU CLIENT BENEFICIAIRE BH ********************//

add_action( 'wp_ajax_bh_coupon_redeem_handler', 'bh_coupon_redeem_handler' );
add_action( 'wp_ajax_nopriv_bh_coupon_redeem_handler', 'bh_coupon_redeem_handler' );

function bh_coupon_redeem_handler() {

// Get the value of the coupon code
$codebh = $_REQUEST['coupon_code'];
// Check coupon code to make sure is not empty

if( empty( $codebh ) || !isset( $codebh ) ) {
// Build our response
$reponsebh = array(
	'result'    => 'error',
	'message'   => 'Le champ CODE COUPON ne doit pas être vide.'
	);
header( 'Content-Type: application/json' );
echo json_encode( $reponsebh );
// Always exit when doing ajax
exit();
	}

// Create an instance of WC_Coupon with our code
$couponbh = new WC_Coupon( $codebh );
// Check coupon to make determine if its valid or not
if( ! $couponbh->id && ! isset( $couponbh->id ) ) {
// Build our response
$reponsebh = array(
	'result'    => 'error',
	'message'   => 'Le COUPON CODE n\'est pas valide ou a déjà été utilisé. Merci de ré-éssayer.'
		);

header( 'Content-Type: application/json' );
echo json_encode( $reponsebh );
// Always exit when doing ajax
exit();

} else {
// Coupon must be valid so we must
// populate the cart with the attached products
foreach( $couponbh->product_ids as $prod_id ) {
			WC()->cart->add_to_cart( $prod_id );
		}

// Build our response
$reponsebh = array(
	'result'    => 'success',
	'href'      => WC()->cart->get_cart_url()
	);

header( 'Content-Type: application/json' );
echo json_encode( $reponsebh );

// Always exit when doing ajax
exit();

	}
}
//******************** AJAX validation reponse coupon ********************//
jQuery( document ).ready( function() 
{
jQuery( '#ajax-coupon-redeem input[type="submit"]').click( function( ev ) 
{
 // Get the coupon code
 var code = jQuery( 'input#coupon').val();
// We are going to send this for processing
        data = {
            action: 'bh_coupon_redeem_handler',
            coupon_code: code;
        }
 // Send it over to WordPress.
jQuery.post( woocommerce_params.ajax_url, data, function( returned_data ) 
{
if( returned_data.result == 'error' ) 
{
jQuery( 'p.result' ).html( returned_data.message );
} else {
// Hijack the browser and redirect user to cart page
window.location.href = returned_data.href;
}
})
// Prevent the form from submitting
        ev.preventDefault();
    }); 
});

into my functions child theme.. but the “ajax validation code” make critical error (because i’d like to see the answer “valide coupon” for example disply just above the form…

the ajax funtion for validation is:


//******************** AJAX validation answer coupon ********************//
jQuery( document ).ready( function() 
{
jQuery( '#ajax-coupon-redeem input[type="submit"]').click( function( ev ) 
{
 // Get the coupon code
 var code = jQuery( 'input#coupon').val();
// We are going to send this for processing
        data = {
            action: 'bh_coupon_redeem_handler',
            coupon_code: code
        }
 // Send it over to WordPress.
jQuery.post( woocommerce_params.ajax_url, data, function( returned_data ) 
{
if( returned_data.result == 'error' ) 
{
jQuery( 'p.result' ).html( returned_data.message );
} else {
// Hijack the browser and redirect user to cart page
window.location.href = returned_data.href;
}
})
// Prevent the form from submitting
        ev.preventDefault();
    }); 
});

i don’t want abuse for help but i am blocked with this too…

i ‘ll appreciate you can tell me where is the problem with it?

I have create a “static block” for display the form as this:


<div class="cadre-coupon">
<div class="redeem-coupon" style="text-align: center;">
<h2><span style="color: #ff00ff;">Echangez vos COUPONS CODES</span></h2>
<form id="ajax-coupon-redeem"><input id="coupon" name="coupon" type="text" /><input name="redeem-coupon" type="submit" value="Validez votre COUPON CODE" />
</form><!-- #ajax-coupon-redeem -->
</div>
</div>

perhaps the “Ajax code” must go with this code and not on the functions.php file? but i don’t know if i can add this AJAC code into the “static block” ? yes ? no? if yes how i must do for not have critical error? must i add a plugin for can adding code into the “post” of the “static block”?
and must the “ajax code” go into PHP balise or not?

lol

i know, i am not a developer so excuse for stupid question

hope you can answer / help me with this

Go To The Whole Conversation In Topic
We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.