WooCommerce Webhooks Custom/Action not saving

Every time you try and set a custom/action topic within webhooks (from WooCommerce > Settings > Webhooks) it would unset it as soon as you update your changes to the webhook. In other words, it will undo your custom topic and return it back to ‘Select an option’ for the topic dropdown.

Any help at all is appreciated. Thank you very much!

Read More

edit: In addition to my comment below, I’ve also attempted to create my own custom topic via the following filter woocommerce_webhook_topic_hooks, however, it doesn’t show within the dropdown list as an option.

The below code runs from functions.php as with any WordPress hook..

Code

function custom_woocommerce_webhook_topics( $topic ) {
    $topic['order.refunded'] = array(
        'woocommerce_process_shop_order_meta',
        'woocommerce_api_edit_order',
        'woocommerce_order_edit_status',
        'woocommerce_order_status_changed'
    );

    return $topic;
}

add_filter( 'woocommerce_webhook_topic_hooks', 'custom_woocommerce_webhook_topics', 10, 1 );

edit 2: Added more context

Related posts

1 comment

  1. I was having the same issue. Selecting any of the built-in topics worked fine. But selection Action and entering any WooCommerce Subscription actions kept reverting. I had also tried creating a new custom topic in the same file (wp-content/plugins/woocommerce-subscriptions/includes/class-wcs-webhooks.php) that the built-in topics are created, mirroring 1:1 the code of one of the topics that ‘stick’ (e.g subscription.created) for a new ‘subscription.paymentcomplete’ topic. It appears in the drop down, but after saving the drop-down reverts to the default ‘Selection an option…’.

    //wp-content/plugins/woocommerce-subscriptions/includes/class-wcs-webhooks.php
    
    
    public static function init() {
    
        ...
        add_action( 'woocommerce_subscription_created_for_order', __CLASS__ . '::add_subscription_created_callback', 10, 2 );
        add_action( 'woocommerce_subscription_payment_complete', __CLASS__ . '::add_subscription_payment_complete_callback', 10,  );
        ...
    }
    
    public static function add_topics( $topic_hooks, $webhook ) {
    
        if ( 'subscription' == $webhook->get_resource() ) {
            $topic_hooks = apply_filters( 'woocommerce_subscriptions_webhook_topics', array(
                'subscription.created' => array(
                    'wcs_api_subscription_created',
                    'wcs_webhook_subscription_created',
                    'woocommerce_process_shop_subscription_meta',
                ),
                'subscription.paymentcomplete' => array(
                    'wcs_webhook_subscription_payment_complete'
                    'woocommerce_process_shop_subscription_meta',
                ),
                ...
            ), $webhook );
        }
    
        return $topic_hooks;
    }
    
    public static function add_topics_admin_menu( $topics ) {
    
        $front_end_topics = array(
            'subscription.created' => __( ' Subscription Created', 'woocommerce-subscriptions' ),
            'subscription.paymentcomplete' => __( ' Subscription Payment Complete', 'woocommerce-subscriptions' ),
            ...
        );
    
        return array_merge( $topics, $front_end_topics );
    }
    
    public static function add_subscription_created_callback( $order, $subscription ) {
        do_action( 'wcs_webhook_subscription_created', $subscription->id );
    }
    
    public static function add_subscription_payment_complete_callback( $order, $subscription ) {
        do_action( 'wcs_webhook_subscription_payment_complete', $subscription->id );
    }
    

    The solution was:

    add_filter( 'woocommerce_valid_webhook_events', __CLASS__ . '::add_event', 10, 1 );
    
    public static function add_event( $events) {
    
            $events[] = 'paymentcomplete';
    
            return $events;
    }
    

Comments are closed.