In need to control the order notes checkout field if a coupon is applied in Woocommerce: I have tried this will no success.
add_action('woocommerce_applied_coupon', 'apply_product_on_coupon');
function apply_product_on_coupon( ) {
if (WC()->cart->has_discount('test')) {
$fields['billing']['billing_customer_note']['placeholder'] = 'You can have up to three initials';
$fields['billing']['billing_customer_note']['label'] = 'Personalise your Tote bag';
$fields['billing']['billing_customer_note']['required'] = true;
$fields['billing']['billing_customer_note']['input_class'] = array('tote-bag');
}
return $fields;
}
I know the $fields bit works as I have used this in a different scenario. If we assume that the coupon code is ‘test’ I need the order notes to be mandatory, the label and placeholder changed and some additional CSS classes applied.
Any suggestions?
2
Answers
Please try with this code. Add this code in your active theme functions.php file.
summer is coupon code name. replace with your coupon code name
Hope is useful for you. Thanks
UPDATE
If you remove coupon from checkout then refresh the page.
As customer can add or remove a coupon in Checkout page, jQuery and Php are required.
Only if a coupon code is applied to the order, the following code will make checkout order notes field required, changing its label and placeholder, and adding tote-bag as selector class to textarea input field. It will handle validation when the field is required.
Use the following code instead:
Code goes in functions.php file of the active child theme (or active theme). Tested and works.