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

旧街凉风 提交于 2021-02-19 07:30:26

问题


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

回答1:


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)



来源:https://stackoverflow.com/questions/54948024/display-a-payment-link-for-custom-order-statuses-in-woocommerce-email-notificati

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!