> */ public function data() { return array_merge( parent::data(), array( Cleanup::record( 'notes', __( 'Order notes about sent links', 'admin-powerups-for-woocommerce' ), __( 'Order notes are part of your order history, so they stay.', 'admin-powerups-for-woocommerce' ) ) ) ); } /** * {@inheritDoc} * * @return array> */ public function fields() { return array( array( 'id' => 'add_note', 'type' => 'toggle', 'label' => __( 'Add an order note when the link is emailed', 'admin-powerups-for-woocommerce' ), 'description' => __( 'Records who sent it and when.', 'admin-powerups-for-woocommerce' ), 'default' => true, ), ); } /** * {@inheritDoc} */ public function boot() { if ( is_admin() ) { CustomerPagesBox::add_section( 'payment', __( 'Payment link', 'admin-powerups-for-woocommerce' ), array( $this, 'render' ), 10 ); } add_action( 'rest_api_init', array( $this, 'register_routes' ) ); } /** * Section markup. * * @since 1.0.0 * @param WC_Order $order Order. * @return void */ public function render( WC_Order $order ) { if ( ! $order->needs_payment() ) { printf( '

%s

', esc_html( sprintf( /* translators: %s: order status, e.g. "Completed". */ __( 'Nothing to pay. This order is %s.', 'admin-powerups-for-woocommerce' ), strtolower( wc_get_order_status_name( $order->get_status() ) ) ) ) ); return; } $url = $order->get_checkout_payment_url(); $email = $order->get_billing_email(); $id = 'apwc-pay-url-' . $order->get_id(); ?>

get_customer_id() ) : ?>

WP_REST_Server::CREATABLE, 'callback' => array( $this, 'rest_email' ), 'permission_callback' => static fn() => current_user_can( 'edit_shop_orders' ), 'args' => array( 'order' => array( 'type' => 'integer', 'required' => true, ), ), ) ); } /** * POST email: send WooCommerce's "Order details" (customer invoice) email, which carries the pay link. * * @since 1.0.0 * @param WP_REST_Request $request Request. * @return \WP_REST_Response|\WP_Error */ public function rest_email( WP_REST_Request $request ) { $order = wc_get_order( (int) $request['order'] ); if ( ! $order instanceof WC_Order ) { return new \WP_Error( 'apwc_no_order', __( 'Order not found.', 'admin-powerups-for-woocommerce' ), array( 'status' => 404 ) ); } if ( ! $order->needs_payment() ) { return new \WP_Error( 'apwc_paid', __( 'This order has nothing to pay.', 'admin-powerups-for-woocommerce' ), array( 'status' => 409 ) ); } if ( ! is_email( $order->get_billing_email() ) ) { return new \WP_Error( 'apwc_no_email', __( 'This order has no billing email.', 'admin-powerups-for-woocommerce' ), array( 'status' => 409 ) ); } $email = WooEmails::get( 'customer_invoice' ); if ( ! $email instanceof WC_Email_Customer_Invoice ) { return new \WP_Error( 'apwc_no_template', __( 'The WooCommerce “Order details” email is not available.', 'admin-powerups-for-woocommerce' ), array( 'status' => 500 ) ); } $email->trigger( $order->get_id(), $order ); if ( $this->setting( 'add_note' ) ) { $user = wp_get_current_user(); $order->add_order_note( sprintf( /* translators: 1: email address, 2: staff display name. */ __( 'Payment link emailed to %1$s by %2$s.', 'admin-powerups-for-woocommerce' ), $order->get_billing_email(), $user->display_name ) ); } /** * Fires after a payment link was emailed from the order screen. * * @since 1.0.0 * @param WC_Order $order Order. */ do_action( 'apwc_payment_link_emailed', $order ); return rest_ensure_response( array( 'sent' => true, 'to' => $order->get_billing_email(), ) ); } }