简体   繁体   中英

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

I've been struggling for a while to get this to work. I need to show this payment link in my woocommerce emails, but only on certain (custom) order statuses. How is it done? Thanks :)

    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>'
);

You will use the WC_Order method get_status() in something like:

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>' );
}

It should works (where you will replace custom-one and custom-two by your custom statuses slugs)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM