php - WooCommerce - 配信方法の前にアイコンを挿入する方法

okwaves2024-01-25  6

こんにちは。

配信方法の前にアイコンを挿入する方法を誰か教えてください。

このフィルターを使用します

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; 
}

これはローカルピックアップとザシルコヴナでは通常通り機能しますが、最後の 2 つは機能しません。

私が持っている ID が値「value」で見つかりました。入力で。誰か私を助ける方法を知っていますか?

または、CSS のみを使用してこれを行うにはどうすればよいですか?

ご質問に回答しました。正しいメソッド ID を見つけてコードに適用するのに役立ちます。

– 7uc1f3r

2020 年 9 月 3 日 12:21



------------------------

使用できる正しい $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 ); 

1

1

代わりに、常に一意である $method->instance_id を使用できます。

– ビームキラー

2022 年 6 月 7 日 9:47

総合生活情報サイト - OKWAVES
総合生活情報サイト - OKWAVES
生活総合情報サイトokwaves(オールアバウト)。その道のプロ(専門家)が、日常生活をより豊かに快適にするノウハウから業界の最新動向、読み物コラムまで、多彩なコンテンツを発信。