api = $api; add_action( 'woocommerce_order_status_completed', [ $this, 'on_order_completed' ] ); add_action( 'woocommerce_order_status_cancelled', [ $this, 'on_order_cancelled' ] ); add_action( 'user_register', [ $this, 'on_user_register' ] ); } /** * Sync billing email to phpList when an order is marked completed. * * @param int $order_id WooCommerce order ID. */ public function on_order_completed( int $order_id ): void { if ( get_option( 'woolist_sync_completed' ) !== 'yes' ) { return; } $list_id = (int) get_option( 'woolist_completed_list_id', 0 ); if ( $list_id < 1 ) { error_log( '[WooList] Completed order sync enabled but no list ID configured.' ); return; } $order = wc_get_order( $order_id ); if ( ! $order ) { return; } $email = $order->get_billing_email(); if ( ! is_email( $email ) ) { return; } $this->api->subscribe_email_to_list( $email, $list_id ); } /** * Sync billing email to phpList when an order is cancelled. * * @param int $order_id WooCommerce order ID. */ public function on_order_cancelled( int $order_id ): void { if ( get_option( 'woolist_sync_cancelled' ) !== 'yes' ) { return; } $list_id = (int) get_option( 'woolist_cancelled_list_id', 0 ); if ( $list_id < 1 ) { error_log( '[WooList] Cancelled order sync enabled but no list ID configured.' ); return; } $order = wc_get_order( $order_id ); if ( ! $order ) { return; } $email = $order->get_billing_email(); if ( ! is_email( $email ) ) { return; } $this->api->subscribe_email_to_list( $email, $list_id ); } /** * Sync new user email to phpList when a WordPress account is created. * * @param int $user_id Newly registered user ID. */ public function on_user_register( int $user_id ): void { if ( get_option( 'woolist_sync_signup' ) !== 'yes' ) { return; } $list_id = (int) get_option( 'woolist_signup_list_id', 0 ); if ( $list_id < 1 ) { error_log( '[WooList] Account signup sync enabled but no list ID configured.' ); return; } $user = get_userdata( $user_id ); if ( ! $user || ! is_email( $user->user_email ) ) { return; } $this->api->subscribe_email_to_list( $user->user_email, $list_id ); } }