WooCommerce Webhooks Custom/Action not saving
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.phppublic 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;}