在 Woocommerce 电子邮件通知中显示自定义订单状态的付款 link

Display a payment link for custom order statuses in Woocommerce email notifications

我一直在努力让这个工作。我需要在我的 woocommerce 电子邮件中显示此付款 link,但仅限于某些(自定义)订单状态。它是如何完成的?谢谢:)

    printf(
    wp_kses(
        /* translators: %1s item is the name of the site, %2s is a html link */
        __( '%2$s', 'woocommerce' ),
        array(
            'a' => array(
                'href' => array(),
            ),
        )
    ),
    esc_html( get_bloginfo( 'name', 'display' ) ),
    '<a href="' . esc_url( $order->get_checkout_payment_url() ) . '">' . esc_html__( 'Click here to pay for this order', 'woocommerce' ) . '</a>'
);

您将使用 WC_Order 方法 get_status(),例如:

if( in_array( $order->get_status(), array( 'custom-one', 'custom-two') ) ) {
    printf( wp_kses(
        /* translators: %1s item is the name of the site, %2s is a html link */
        __( '%2$s', 'woocommerce' ), array(
            'a' => array(
                'href' => array(),
            ),
        ) ),
        esc_html( get_bloginfo( 'name', 'display' ) 
    ), '<a href="' . esc_url( $order->get_checkout_payment_url() ) . '">' .
    esc_html__( 'Click here to pay for this order', 'woocommerce' ) . '</a>' );
}

它应该可以工作 (您可以用自定义状态块替换 custom-onecustom-two