php - WooCommerce - 如何在交付方法之前插入图标
问题描述
再会,
谁能帮助我如何在交付方法之前插入图标?
我用这个过滤器
add_filter( 'woocommerce_cart_shipping_method_full_label', 'filter_woocommerce_cart_shipping_method_full_label', 10, 2 );
function filter_woocommerce_cart_shipping_method_full_label( $label, $method ) {
// Use the condition here with $method to apply the image to a specific method.
if( $method->method_id === "napobocce" ) {
$label = "<img src='https://image.flaticon.com/icons/svg/2922/2922830.svg' style='height: 30px; border-radius: 20px; margin-left: 5px; margin-right: 5px;' />".$label;
}
if( $method->method_id == "zasilkovna" ) {
$label = "<img src='https://image.flaticon.com/icons/svg/2922/2922830.svg' style='height: 30px; border-radius: 20px; margin-left: 5px; margin-right: 5px;' />".$label;
}
if( $method->method_id == "doprava>ceska-posta>16" ) {
$label = "<img src='https://image.flaticon.com/icons/svg/2922/2922830.svg' style='height: 30px; border-radius: 20px; margin-left: 5px; margin-right: 5px;' />".$label;
}
if( $method->method_id == "doprava>geis>16" ) {
$label = "<img src='https://image.flaticon.com/icons/svg/2922/2922830.svg' style='height: 30px; border-radius: 20px; margin-left: 5px; margin-right: 5px;' />".$label;
}
return $label;
}
这通常适用于本地取货和 Zásilkovna,但不适用于最后两个。
我在输入中的值“值”中找到了我与他们一起拥有的 id。有人知道如何帮助我吗?
或者如何仅使用 CSS 来做到这一点?
解决方案
要找出正确的$method->method_id
你可以使用
echo 'DEBUG: method id = '. $method->method_id;
所以你得到
function filter_woocommerce_cart_shipping_method_full_label( $label, $method ) {
// Remove afterwards
echo 'DEBUG: method id = '. $method->method_id;
// Use the condition here with $method to apply the image to a specific method.
if( $method->method_id === "local_pickup" ) {
$label = "<img src='https://image.flaticon.com/icons/svg/2922/2922830.svg' style='height: 30px; border-radius: 20px; margin-left: 5px; margin-right: 5px;' />" . $label;
} elseif( $method->method_id == "zasilkovna" ) {
$label = "<img src='https://image.flaticon.com/icons/svg/2922/2922830.svg' style='height: 30px; border-radius: 20px; margin-left: 5px; margin-right: 5px;' />" . $label;
}
return $label;
}
add_filter( 'woocommerce_cart_shipping_method_full_label', 'filter_woocommerce_cart_shipping_method_full_label', 10, 2 );
推荐阅读
- react-native - 找不到 lint-gradle-api.jar (com.android.tools.lint:lint-gradle-api:26.1.2)
- python - requests.get 在大文件上,下载不完整但找不到错误指示
- javascript - 使用 bcrypt 重置密码功能不起作用,发送到客户端后无法设置标头?
- ios - xcodebuild 默认构建路径
- python - 如何在列表列表中找到具有最大值的列表(其中嵌套列表包含字符串和数字)?
- python - scipy.integrate.odeint 每个时间步更新初始条件
- java - 我可以使用 Solr DocumentObjectBinder 和 Field 注释来创建递归嵌套文档吗?
- c# - c# Xamarin Forms 实现 ASMX 服务
- javascript - 不允许时间更改 React-DatePicker
- r - DT tables not shown in shiny