Automattic\WooCommerce\Blocks\Shipping
ShippingController::show_local_pickup_details │ public │ WC 1.0
Inject collection details onto the order received page.
Метод класса: ShippingController{}
Возвращает
Строку.
Использование
$ShippingController = new ShippingController();
$ShippingController->show_local_pickup_details( $return_value, $order );
- $return_value(строка) (обязательный)
- Return value.
- $order(WC_Order) (обязательный)
- Order object.
Код ShippingController::show_local_pickup_details() ShippingController::show local pickup details
WC 10.3.4
public function show_local_pickup_details( $return_value, $order ) {
// Confirm order is valid before proceeding further.
if ( ! $order instanceof \WC_Order ) {
return $return_value;
}
$shipping_method_ids = ArrayUtil::select( $order->get_shipping_methods(), 'get_method_id', ArrayUtil::SELECT_BY_OBJECT_METHOD );
$shipping_method_id = current( $shipping_method_ids );
// Ensure order used pickup location method, otherwise bail.
if ( 'pickup_location' !== $shipping_method_id ) {
return $return_value;
}
$shipping_method = current( $order->get_shipping_methods() );
$details = $shipping_method->get_meta( 'pickup_details' );
$location = $shipping_method->get_meta( 'pickup_location' );
$address = $shipping_method->get_meta( 'pickup_address' );
$cost = $shipping_method->get_total();
$lines = array();
if ( $location ) {
$lines[] = sprintf(
// Translators: %s location name.
__( 'Collection from <strong>%s</strong>:', 'woocommerce' ),
$location
);
}
if ( $address ) {
$lines[] = nl2br( esc_html( str_replace( ',', ', ', $address ) ) );
}
if ( $details ) {
$lines[] = wp_kses_post( $details );
}
if ( $cost > 0 ) {
$tax_display = get_option( 'woocommerce_tax_display_cart' );
$tax = $shipping_method->get_total_tax();
// Format cost with tax handling.
if ( 'excl' === $tax_display ) {
// Show pickup cost excluding tax.
$formatted_cost = wc_price( $cost, array( 'currency' => $order->get_currency() ) );
if ( (float) $tax > 0 && $order->get_prices_include_tax() ) {
/**
* Hook to add tax label to pickup cost.
*
* @since 6.0.0
* @param string $tax_label Tax label.
* @param \WC_Order $order Order object.
* @param string $tax_display Tax display.
* @return string
*/
$formatted_cost .= apply_filters(
'woocommerce_order_shipping_to_display_tax_label',
' <small class="tax_label">' . WC()->countries->ex_tax_or_vat() . '</small>',
$order,
$tax_display
);
}
} else {
// Show pickup cost including tax.
$formatted_cost = wc_price(
(float) $cost + (float) $tax,
array( 'currency' => $order->get_currency() )
);
if ( (float) $tax > 0 && ! $order->get_prices_include_tax() ) {
/**
* Hook to add tax label to pickup cost.
*
* @since 6.0.0
* @param string $tax_label Tax label.
* @param \WC_Order $order Order object.
* @param string $tax_display Tax display.
* @return string
*/
$formatted_cost .= apply_filters(
'woocommerce_order_shipping_to_display_tax_label',
' <small class="tax_label">' . WC()->countries->inc_tax_or_vat() . '</small>',
$order,
$tax_display
);
}
}
$lines[] = '<br>' . sprintf(
// Translators: %s is the formatted price.
__( 'Pickup cost: %s', 'woocommerce' ),
$formatted_cost
);
}
// If nothing is available, return original.
if ( empty( $lines ) ) {
return $return_value;
}
// Join all the lines with a <br> separator.
return implode( '<br>', $lines );
}