На странице оформления заказа моего сайта WooCommerce пользователи будут иметь список способов доставки на выбор в зависимости от того, что они покупают
Это список, который я хочу захватить:
Things like
- “Free Shipping” for orders over a certain price
- “Freight Shipping” for certain items, and so on.
My goal, is to display ALL available methods for each specific order, and display it on the “Edit Order / Order Details” page in the Admin view.
A small feature that would help us be able to quickly identify what option people are choosing more often, depending on the choices that they have available.
This is what I have so far:
add_action( 'woocommerce_checkout_update_order_meta', 'save_available_shipping_methods' );
function save_available_shipping_methods( $order_id ) {
$shippingmethods = WC()->cart->get_shipping_methods();
update_post_meta( $order_id, '_shipping_methods', $shippingmethods );
}
add_action( 'woocommerce_admin_order_data_after_shipping_address', 'get_available_shipping_methods', 10, 1 );
function get_available_shipping_methods($order){
$order = wc_get_order( $order_id );
if ( $order ) {
echo '<p><strong>'.__('Available Shipping Methods: ').'</strong> ' . get_post_meta($order->get_shipping_methods(), '_shipping_field_value', true ) . '</p>';
}
}
Я также прикреплю картинку, чтобы, может быть, было немного легче следить.
Вот где я бы хотел ее поместить. Текущая ловушка помещает поле под адресом доставки
Вот где я хотел бы это поставить. Текущая ловушка помещает поле под адресом доставки