1 回答

TA貢獻1816條經(jīng)驗 獲得超6個贊
使用掛鉤在過濾器掛鉤中的自定義函數(shù)woocommerce_package_rates
,您將能夠?qū)①徫镘嚿唐菲放泼Q添加到運輸方式標簽名稱之前。
由于在 WooCommerce 中啟用品牌的方法有多種,您需要定義在 WooCommerce 中啟用的品牌插件所使用的分類法...
add_filter( 'woocommerce_package_rates', 'prepend_brand_to_shipping_methods', 10, 2 );
function prepend_brand_to_shipping_methods( $rates, $package ){
? ? // HERE define the taxonomy for product brand (depend of used plugin)
? ? $taxonomy ='product_brand';
? ? // Get the first cart item
? ? $cart_item = reset($package['contents']);
? ? // Get the product brand term name
? ? $brand_name = wp_get_post_terms( $cart_item['product_id'], $taxonomy, ['fields' =>'names']);
? ? $brand_name = reset($brand_name);
? ? // Loop through shipping rates
? ? foreach ( $rates as $rate_key => $rate ){
? ? ? ? // Changing shipping method label name
? ? ? ? $rates[$rate_key]->label = $brand_name . ' ' . $rate->label;
? ? }
? ? return $rates;
}
代碼位于活動子主題(或活動主題)的functions.php 文件中。經(jīng)過測試并有效。
刷新運輸緩存:
1). 此代碼已保存在您的 function.php 文件中。
2)。在運輸區(qū)域設(shè)置中,禁用/保存任何運輸方式,然后啟用返回/保存。
你已經(jīng)完成了,你可以測試它。
- 1 回答
- 0 關(guān)注
- 177 瀏覽
添加回答
舉報