Estoy tratando de agregar tiempos de llegada estimados a las etiquetas de mis métodos de envío. Sin embargo, me gustaría que los tiempos de llegada tuvieran algo de HTML extra dentro de la etiqueta. (Hágalos más pequeños y con un peso de fuente diferente).
Aquí hay un ejemplo simple:
function add_estimated_arrival_times($rates, $package){
$groundStuff = $timeReturnedFromAPI; //collect a bunch of cart information, post to the UPS API, return estimated arrival time to $timeReturnedFromAPI
$ground_rate_id = 'ups:6:09'; //UPS ground rate ID
// Loop through available shipping rates, add arrival time if rate is UPS ground
foreach ( $rates as $rate_key => $rate ) {
if( $ground_rate_id === $rate_key ) {
$rates[$rate_key]->label .= ' <span style="font-size: 12px; font-weight: normal;">(' . $groundStuff . ')</span>'; //<---- problem: HTML is not added
break;
}
}
return $rates;
}
add_filter( 'woocommerce_package_rates','add_estimated_arrival_times', 50, 2 );
El código anterior agrega con éxito el texto sin formato a la etiqueta del método de envío, pero el HTML desaparece.
¿Cuál sería una buena solución para esto?
El gancho que estás usando solo te permite editar el texto de la etiqueta:
function filter_woocommerce_package_rates( $rates, $package ){
// Loop through available shipping rates
foreach ( $rates as $rate_key => $rate ) {
$rates[$rate_key]->label = __( 'My label', 'woocommerce' );
}
return $rates;
}
add_filter( 'woocommerce_package_rates','filter_woocommerce_package_rates', 10, 2 );
Que también es ajustable mediante el woocommerce_cart_shipping_method_full_label
gancho:
function filter_woocommerce_cart_shipping_method_full_label( $label, $method ) {
// Target a specific method ID
if ( $method->id == 'local_pickup:1' ) {
// Overwrite
$label = __( 'My new label', 'woocommerce' );
} elseif ( $method->id == 'free_shipping:2' ) {
// Append
$label .= __( ' - Extra text label', 'woocommerce' );
}
return $label;
}
add_filter( 'woocommerce_cart_shipping_method_full_label', 'filter_woocommerce_cart_shipping_method_full_label', 10, 2 );
Pero tu pregunta era agregar algo después de la etiqueta. y esto se puede hacer a través de la woocommerce_after_shipping_rate
gancho:
function action_woocommerce_after_shipping_rate( $method, $index ) {
// Target a specific method ID
if ( $method->id == 'local_pickup:1' ) {
echo '<p>test</p>';
} else {
$groundStuff="some value";
echo '<span style="font-size: 12px; font-weight: normal;">(' . $groundStuff . ')</span>';
}
}
add_action( 'woocommerce_after_shipping_rate', 'action_woocommerce_after_shipping_rate', 10, 2 );
O
sobreescribiendo /carrito/carro-envio.php en la línea 40 @ versión 3.6.0: esta plantilla se puede anular copiándola en yourtheme/woocommerce/cart/cart-shipping.php