猿问

带有条件的订单明细表下的文本

我想在我的帐户页面的订单详细信息表下添加一个文本,如下面的屏幕截图所示,但如果订单状态更改为完成,我希望将此文本更改为另一个文本。


这是我用来显示文本的内容,但如果状态从任何状态更改为完成,我不能有条件地将文本更改为另一个文本。


add_action('woocommerce_order_details_after_order_table', 'action_order_details_after_order_table', 10, 4 );

function action_order_details_after_order_table( $order, $sent_to_admin = '', $plain_text = '', $email = '' ) {

    // Only on "My Account" > "Order View"

    if ( is_wc_endpoint_url( 'view-order' ) ) {

        printf( '<p class="custom-text">' .

        __("To cancel your license within the 30 day trial period click on %s" ,"woocommerce"),

        '<strong>"' .__("Refund my entire order", "woocommerce") . '"</strong>.</p>' );

    }

}

我只需要在订单状态完成后将此消息更改为另一条消息。


神不在的星期二
浏览 123回答 1
1回答

幕布斯7119047

使用以下代码更改您的上述代码 -add_action('woocommerce_order_details_after_order_table', 'action_order_details_after_order_table', 10, 4 );function action_order_details_after_order_table( $order, $sent_to_admin = '', $plain_text = '', $email = '' ) {&nbsp; &nbsp; // Only on "My Account" > "Order View"&nbsp; &nbsp; if ( is_wc_endpoint_url( 'view-order' ) ) {&nbsp; &nbsp; &nbsp; &nbsp; if( $order->get_status() == 'completed' ){ // for completed status&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf( '<p class="custom-text">' .&nbsp; &nbsp; &nbsp; &nbsp; __("Your order completed message goes here %s" ,"woocommerce"),&nbsp; &nbsp; &nbsp; &nbsp; '<strong>"' .__("Refund my entire order", "woocommerce") . '"</strong>.</p>' );&nbsp; &nbsp; &nbsp; &nbsp; }elseif($order->get_status() == 'cancelled'){ // for cancelled status&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;printf( '<p class="custom-text">' .&nbsp; &nbsp; &nbsp; &nbsp; __("Your order cancelled message goes here %s" ,"woocommerce"),&nbsp; &nbsp; &nbsp; &nbsp; '<strong>"' .__("Refund my entire order", "woocommerce") . '"</strong>.</p>' );&nbsp; &nbsp; &nbsp; &nbsp; }else{ // for rest statuses&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf( '<p class="custom-text">' .&nbsp; &nbsp; &nbsp; &nbsp; __("To cancel your license within the 30 day trial period click on %s" ,"woocommerce"),&nbsp; &nbsp; &nbsp; &nbsp; '<strong>"' .__("Refund my entire order", "woocommerce") . '"</strong>.</p>' );&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }}
随时随地看视频慕课网APP
我要回答