I am trying to fire a custom function when a credit card error occurs in the WooCommerce checkout flow.
I seem to be able to get standard woo errors by using but it seems that the stripe plugin does not us woocommerce_add_error
add_filter( 'woocommerce_add_error', 'my_woocommerce_add_error' );
I found the following hook in the WooCommerce Stripe documentation, but I can't seem to get it to work with add_action
wc_gateway_stripe_process_payment_error ($error, $order) – Called when
an error occurs during the process payment event.
add_action( 'wc_gateway_stripe_process_payment_error', 'test_this' );
What am I missing? Is there another filter or hook that I should be using?
As per documentation https://docs.woocommerce.com/document/stripe/ this hook take 2 params $error, $order so you have to tell it to WordPress:
add_action( 'wc_gateway_stripe_process_payment_error', 'test_this', 10, 2 );
function test_this($error, $order) {
// something
}
It's working fine on my side
The only way I could figure out how to do this is by watching for dod inserts on the dom. This is the code I used below.
Note: You should probably use mutated events these days but for some reason, I couldn't figure it out.
$(document).on('DOMNodeInserted', function(e) {
if ( $(e.target).hasClass('woocommerce-error') ) {
console.log('stripe input error');
}
});
Related
Note: In looking for an answer to my question I came across this post but it is NOT duplicate: Remove add to cart notice and change "add to cart" button in Woocommerce the answer there gives the option to remove the notice from the entire site. I want to remove it only from the cart page and I don't want to do it with CSS.
I use external links to my site to send people directly to the shopping cart with the item already added to the cart. When doing so, the "added-to-cart notification" shows up on the cart page which I do not want.
I found this code which removes the added-to-cart notification: add_filter( 'wc_add_to_cart_message_html', '__return_false' ); but it removes the notification from all pages of my site which is not what I want.
To be more specific, I want the added-to-cart notification to show on every product archive page and nowhere else.
I tried to add a filter but it doesn't work the way I would expect it to, I tried the following two ways (and tested it with various pages to see if I could make anything work but it seems my general syntax is off because I Can't get it to do anything...
function hide_cart_notes() {
if ( ! is_archive() ) {
add_filter( 'wc_add_to_cart_message_html', '__return_false' );
}
}
add_action( 'woocommerce', 'hide_cart_notes' );
function hide_cart_notes() {
if ( is_archive() ) {
return;
}
add_filter( 'wc_add_to_cart_message_html', '__return_false' );
}
add_action( 'woocommerce', 'hide_cart_notes' );
when woocommerce hook starts? where it's docs? does it run at all?
these question should be answered before.
i know that WordPress parses query at parse_query hook, so i would try this
add_action('parse_query', function() {
if (!is_archive()) {
add_filter( 'wc_add_to_cart_message_html', '__return_false' );
}
});
because is_shop(), is_archive(), is_* need query to be parsed first.
I have used below action hook to hide fields but it is not working.
remove_action( 'give_cc_form', 'give_get_cc_form' );
can anyone help me to figure out this issue
I am using GiveWP plugin for donation in WordPress site.
GiveWP has a pretty expansive snippet library, and one example shows how you can remove and rearrange fields. This is probably the best place to start from:
https://github.com/impress-org/givewp-snippet-library/blob/master/form-customizations/customize-fieldset-order.php
function give_remove_fieldsets() {
remove_action( 'give_cc_form', 'give_get_cc_form' );
}
add_action( 'init', 'give_remove_fieldsets' );
this actually worked for me
Make sure to run it at init, and you need to add the same priority used in the add_action, if none it uses 10 and the priority can be left blank
add_action('init','remove_actions');
function remove_actions() {
remove_action( 'give_cc_form', 'give_get_cc_form', 1 ); // Replace the priority with the correct one
}
i'm trying to solve this issue for weeks, have tried everything.
I have a Custom Order Action in my order admin panel like this:
function manage_actions( $actions ) {
$actions['wc_my_custom_action'] = 'My Custom Action';
return $actions;
}
add_action( 'woocommerce_order_actions', 'manage_actions');
function custom_action_function( $order ) {
update_post_meta( $order->id, 'Custom_Meta', 'Value' );
}
add_action( 'woocommerce_order_action_my_custom_action', 'custom_action_function' );
This works fine, if i open an order and then click on the 'My Custom Action' in the actions menu the 'Custom_Meta' key value pair is added to the order.
Now i have an Order Update WebHook (using API v3) set up and unfortunately it triggers before the 'custom_action_function' function runs so i always get the payload of the order without the new meta tag. I have tried everything i can to add the meta data prior to the webhook being fired, does anyone have an idea on how to accomplish this? Thanks
I have been trying to figure out a filter or action to modify Resume custom fields.
There is a documentation here about how to do it for resume core fields but not for custom fields.
If I use submit_resume_form_fields filter like
add_filter( 'submit_resume_form_fields', 'remove_submit_resume_form_fields' );
function remove_submit_resume_form_fields( $fields ) {
$fields only returns resume core fields but not the custom fields.
Can anyone help me?
Finally I got it worked. So instead of using submit_resume_form_fields filter, I used submit_resume_form_fields_get_resume_data and it gave me all the fields (with custom fields as well). Unfortunately I could not find a documentation of this, I had to search the code. So the code goes like
add_filter( 'submit_resume_form_fields_get_resume_data', 'remove_submit_resume_form_fields' );
function remove_submit_resume_form_fields( $fields ) {
unset( $fields['resume_fields']['custom_field_name'] );
}
I thought it might help someone!
I'm new to WordPress plugin development. I have a doubt about below 3
filter hooks.
content_edit_pre
content_filtered_edit_pre
excerpt_edit_pre
Please tell me the what the difference between these hooks.
content_edit_pre filter hook
The content_edit_pre filter hook is used to hook into the content of a post just before it is loaded to be edited. For example, if you included the following at the end of your functions file:
function test_of_content_edit_pre( $content, $post_id ) {
return "Insert this before the content about to be edited ".$content;
}
add_filter( 'content_edit_pre', 'test_of_content_edit_pre', 10, 2 );
Then open a post to edit it, you would see that the text has been inserted before the post:
excerpt_edit_pre filter hook
The excerpt_edit_pre filter hook is very similar to content_edit_pre, except it is used to hook into excerpts (instead of posts) just before they are loaded to be edited. For example:
function test_of_excerpt_edit_pre( $content, $post_id ) {
return "Add this to excerpt".$content;
}
add_filter( 'excerpt_edit_pre', 'test_of_excerpt_edit_pre', 11, 2 );
Would result in this being shown in the excerpt:
content_filtered_edit_pre filter hook
This one I am not sure about. I tested it out and it didn't seem to do anything. I will update my answer if I can find more information on this.