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

    (@josk79)

    Try checking ‘Individual use only’ to the 10+-items-coupon and set the names so that alphabetically the name of the special-coupon comes before the 10+-items-coupons’ name.

    That should work, but haven’t tried. Please try it otherwise I have to look further.

    Thread Starter BClifton

    (@omegadm)

    unfortunately not – it was already set to individual use. Renaming to “aaspecial” as well as deleting and creating the aaspecial coupon again, still has the same problem…

    Plugin Author Soft79

    (@josk79)

    Try this hack in your theme’s function.php. Please change the names of the coupon in the first two lines of the script

    add_filter( 'wp_loaded', function( ) {
    	$COUPON_10_AUTO = 'auto10';
    	$COUPON_25 = 'special';
    
    	if ( $_GET['apply_coupon'] == $COUPON_25 ) {
    		$coupon = new WC_Coupon( $COUPON_25 );
    		if ($coupon->is_valid()) {
    
    			//Remove the auto coupon
    			if ( WC()->cart->has_discount( $COUPON_10_AUTO ) ) {
    				WC()->cart->remove_coupon( $COUPON_10_AUTO );
    			}
    
    			//Invalidate the auto coupon
    			add_filter( 'wjecf_coupon_can_be_applied', function( $can_be_applied, $coupon ) {
    				if ( $coupon->code == $COUPON_10_AUTO ) return false;
    				return $coupon_can_be_applied;
    			}, 10, 2);
    		}
    	}
    });
    Thread Starter BClifton

    (@omegadm)

    Unfortunately no change… Can I ping you direct to send further info?

    Plugin Author Soft79

    (@josk79)

    You could send your site credentials to: admin at soft79 dot nl. Then I can take a peek.

    Plugin Author Soft79

    (@josk79)

    Problem solved. There was a conflict with a custom script in functions.php.

    ok so I am trying to make an auto redeem page like the one in this link: https://www.sitepoint.com/creating-a-woocommerce-redeem-coupon-page/

    and it’s going great: everything else is working perfectly.. except one thing!
    When a user inserts a not valid coupon it should say underneath the field to retry with a valid coupon but that doesn’t happen. All the following codes are in functions.php of my theme.

    This is what the guy posted on that link.
    ——————–

    // Create an instance of WC_Coupon with our code
    $coupon = new WC_Coupon( $code );
    if( ! $coupon->id && ! isset( $coupon->id ) ) {
    	// Build our response
    	$response = array(
    		'result'    => 'error',
    		'message'   => 'Invalid code entered. Please try again.'
    		);
    
    	header( 'Content-Type: application/json' );
    	echo json_encode( $response );
    
    	// Always exit when doing ajax
    	exit();

    ———————–

    it looks like the “if statement” just never happens,
    so i tried to change it like this:

    ———————–

    // Create an instance of WC_Coupon with our code
    $coupon = new WC_Coupon( $code );
    
    // Check coupon to make determine if its valid or not
    if( ! $coupon->is_valid() )  {

    exc exc
    ———————–

    and now it looks like $coupon->is_valid() is always false
    so it doesn’t even see when a coupon exist or not!
    in both cases $coupon->is_valid() will give false
    what am i missing?
    I don’t think u need the big picture of what I am doing! i just want a statement in functions.php of my theme that return true only if a coupon is actually valid. I’ll type ! in front of it and the job will be done. Please help me ??

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘over-ride Auto-coupon i.e. ignore’ is closed to new replies.