再次订购WooCommerce Inside查看订单

时间:2019-11-05 作者:Salah Eddine Khadim

Im使用此功能在操作中添加按钮“再次订购”

function cs_add_order_again_to_my_orders_actions( $actions, $order ) {
    $payment_method = method_exists($order, \'get_payment_method\') ? $order->get_payment_method() : $order->payment_method;
    if ($payment_method === \'cod\') {
        $actions[\'order-again\'] = array(
            \'url\'  => wp_nonce_url( add_query_arg( \'order_again\', $order->id ) , \'woocommerce-order_again\' ),
            \'name\' => __( \'Transformer en commande\', \'woocommerce\' )
        );
    }

    return $actions;
}
add_filter( \'woocommerce_my_account_my_orders_actions\', \'cs_add_order_again_to_my_orders_actions\', 50, 2 );
它工作正常,但我想在查看订单页面中也显示它

如何提取短代码以显示“查看订单页”内的按钮

2 个回复
SO网友:Siddhesh Shirodkar

你试过这个吗?添加操作(“woocommerce\\u view\\u order”、“cs\\u add\\u order\\u Reagain\\u to\\u my\\u orders\\u actions”,50,2);

SO网友:Salah Eddine Khadim

其工作方式是在所有订单状态下添加过滤器显示选项。

Wooocommerce默认情况下仅在完成的订单中显示该按钮

此功能将以所有顺序显示选项按钮:

add_filter( \'woocommerce_valid_order_statuses_for_order_again\', \'add_order_again_status\', 10, 1);

function add_order_again_status($array){
    $array = array_merge($array, array(\'on-hold\', \'processing\', \'pending-payment\', \'cancelled\', \'refunded\', \'completed\'));
    return $array;
}

相关推荐