• Resolved prasada_pujari

    (@prasadaeightnine)


    After clicking on the paypal button on checkout page , the checkout fields are validated but there is one functionality missing in which the woocommerce coupon code usage also needs to be validated.

    The logged out users can apply coupon code on cart page and when they browse to checkout page after filling the checkout user fields and clicking on paypal button there should be a validation for woocommerce coupon code as well for that particular user, this kind of functionality is present in woocommerce checkout page default “place order” button but is missing out in paypal button on checkout page.

    Please guide me if there is any hook which I can use to validate the woocommerce coupon on clicking the “paypal” button but before the pop up for paypal is shown.

    Regards,

    Prasada

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Payment Plugins

    (@mrclayton)

    Hi @prasadaeightnine

    this kind of functionality is present in woocommerce checkout page default “place order” button but is missing out in paypal button on checkout page.

    That functionality within WooCommerce doesn’t change when using our plugin. If you click the blue Pay button in the PayPal popup, all of the WooCommerce validations related to processing an order will take place once the popup closes.

    You will see that WooCommerce will not allow the order to process since your custom coupon validation will run at that time.

    Kind Regards

    Plugin Author Payment Plugins

    (@mrclayton)

    Setting to resolved. We added a new action wc_ppcp_validate_checkout_fields so custom validations can be added when the PayPal button is clicked on the checkout page.

    Can you please specify how to use this action hook in functions.php to check for validation after the button is clicked and before the popup appears for adding payment details.
    Also, if the user is logged out and when they fill in the billing deatils in which they will have to specify the email id , how can we run a valiadtion for the coupon code restriction on email id when clicked on the paypal button , just like the way it happens with default woocommerce paypal option.

    I tried something like this in my functions.php for valiadting the coupon code restriction on the user email.
    add_action('wc_ppcp_validate_checkout_fields', 'custom_coupon_validation'); function custom_coupon_validation() { // Get the coupon code entered by the user $coupon_code = isset($_POST['coupon_code']) ? sanitize_text_field($_POST['coupon_code']) : ''; // Perform your coupon code validation checks here if (!empty($coupon_code)) { $user_id = get_current_user_id(); // Check if the coupon code is valid for the user $is_valid = WC_Discounts::is_coupon_valid($coupon_code, $user_id); if (!$is_valid) { wc_add_notice('Coupon code is not valid for this user.', 'error'); } } }
    Plugin Author Payment Plugins

    (@mrclayton)

    Hi @vaibhavshukla31

    just like the way it happens with default woocommerce paypal option.

    You can’t really compare how that other plugin works to ours because it doesn’t render a PayPal button. It works off submitting the checkout page form by clicking the Place Order button which results in a redirect to the PayPal payment page.

    This plugin works off the PayPal smartbuttons which means the PayPal popup appears early in the order execution flow.

    The same validations that WooCommerce performs during checkout apply to this plugin as well. They just happen after the user closes the PayPal popup, since that’s when the checkout form is submitted.

    Here is an example of how to use the wc_ppcp_validate_checkout_fields filter which you can modify to fit your needs:

    add_action('wc_ppcp_validate_checkout_fields', function($request){
    	$coupon_code = isset($_POST['coupon_code']) ? sanitize_text_field($_POST['coupon_code']) : '';
    	if(empty($coupon_code)){
    		throw new \Exception('Invalid coupon code');
    	}
    });

    You want to throw an Exception when the validation fails as that’s the message that will appear on the checkout page.

    Kind Regards

    This feature which is already present on “place order” button in woocommerce is the ideal way in which the checkout flow should happen , if we make a coupon code which is restricted for some users but somehow they get hold of the same coupon and apply it, they will then move to checkout and after placing order using paypal the ideal flow should be to remove the coupon code and throw the error.
    But with your plugin this kind of feature is not present and affects the user interactions, since the pop for paypal first pops up and then after processing the paypal form the coupon is removed if the user is restricted for that particular coupon. This makes the customer hopefull that the coupon is going to work whenever firts paypal pop up opens.

    Please consider adding this functionality as feature if possible which will improve the customer interaction.

    Hi , can you please update me regarding this matter?
    It is quite an urgent requirement.

    Plugin Author Payment Plugins

    (@mrclayton)

    Hi @vaibhavshukla31

    The functionality you’re asking for would result in a less than ideal integration that would have performance impacts. The plugin would have to allow the WooCommerce order to be created, return control back to the checkout page, create the PayPal order, then launch the PayPal popup.

    I recommend you try out different PayPal plugins to see if there is one that more closely aligns with your desired functionality.

    Kind Regards

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Regarding coupon code message on checkout page’ is closed to new replies.