I want to show an error message in Woocommerce checkout page, and remove the order button. I can use one action and one filter:
add_action( 'woocommerce_before_checkout_form', 'add_checkout_error', 9 );
function add_checkout_error() {
wc_print_notice( __( 'An error message.', 'woocommerce' ), 'error' );
}
add_filter('woocommerce_order_button_html', 'remove_order_button_html' );
function remove_order_button_html( $button ) {
$button = '';
return $button;
}
How can I combine them? If I put the filter inside the action function, it doesn't work.
add_action( 'woocommerce_before_checkout_form', 'add_checkout_error', 9 );
function add_checkout_error() {
$error=1;
if ($error==1){
wc_print_notice( __( 'An error message.', 'woocommerce' ), 'error' );
add_filter('woocommerce_order_button_html', 'remove_order_button_html' );
}
}
function remove_order_button_html( $button ) {
$button = '';
return $button;
}
I want to show an error message in Woocommerce checkout page, and remove the order button. I can use one action and one filter:
add_action( 'woocommerce_before_checkout_form', 'add_checkout_error', 9 );
function add_checkout_error() {
wc_print_notice( __( 'An error message.', 'woocommerce' ), 'error' );
}
add_filter('woocommerce_order_button_html', 'remove_order_button_html' );
function remove_order_button_html( $button ) {
$button = '';
return $button;
}
How can I combine them? If I put the filter inside the action function, it doesn't work.
add_action( 'woocommerce_before_checkout_form', 'add_checkout_error', 9 );
function add_checkout_error() {
$error=1;
if ($error==1){
wc_print_notice( __( 'An error message.', 'woocommerce' ), 'error' );
add_filter('woocommerce_order_button_html', 'remove_order_button_html' );
}
}
function remove_order_button_html( $button ) {
$button = '';
return $button;
}
Share
Improve this question
asked Nov 29, 2020 at 18:16
franz877franz877
312 bronze badges
1 Answer
Reset to default 0the filter function must be inside the action function, because if it isnt it is not recognize. So I think. At least with variables is like this.
add_action( 'woocommerce_before_checkout_form', 'add_checkout_error', 9 );
function add_checkout_error() {
wc_print_notice( __( 'An error message.', 'woocommerce' ), 'error' );
add_filter('woocommerce_order_button_html', 'remove_order_button_html' );
function remove_order_button_html( $button ) {
$button = '';
return $button;
}
}