はシンプルかつ変数製品の製品価格の後にカスタムラベルを追加するには、以下のコードを使用しましょう:可変製品セレクタ:WooCommerceに住んで選択した値
add_filter('woocommerce_variation_price_html','prices_custom_labels', 10, 2 );
add_filter('woocommerce_price_html','prices_custom_labels', 10, 2);
function prices_custom_labels($price, $product){
// Set HERE your custom labels names
$per_dozen = ' '. __('per dozen', 'woocommerce');
$per_case = ' '. __('per case (20 dozens)', 'woocommerce');
// 1) Variable products
if ($product->product_type != 'simple' && $product->variation_id) {
// Getting the array of existing attributes values for a variation
$variation_attribute_value = $product->variation_data;
// Here we keep only the last value in this array
$last_variation_attribute_slug_value = ' ' . end($variation_attribute_value);
// Finding the word 'case' in the attribute value slug
$has_case = strstr($last_variation_attribute_slug_value, 'case');
// Setting the right displayed label depending on attribute value slug
if($has_case)
$attribute_quantity_name_value = $per_case;
else
$attribute_quantity_name_value = $per_dozen;
// Here the output price + custom label
$price = '<ins class="highlight">'.woocommerce_price($product- >regular_price).$attribute_quantity_name_value.'</ins>';
}
// 2) Simple products
else
{
// Here the output price + custom default label
$price = '<ins class="highlight">'.woocommerce_price($product- >regular_price).$per_dozen.'</ins>';
}
return $price;
}
しかし、変数の製品で、私は問題を持っていますライブ表示価格で追加されたカスタムラベル。私が使用するコードは、 "ダースンごとの"ライブ価格の後にのみ表示されます。
私は価格の後に右のラベルを追加するためのカスタム「数量」セレクタで選択した値を取得する必要があります。
- 選択した値が「ダース」であるならば、私は生き価格の後に表示する必要があります」
- 選択された値が「ケース(20ダース)」の場合、「ケースごと(20ダース)」のライブ価格の後に表示する必要があります。
このスクリーンショットは、私はすべてのケースのために実際に持っているものです。
チェックこの問題を私のウェブサイト上でspecific product page
は、だから私は属性を取得する必要があります「数量ライブ値段に右のラベルを追加するために選択された値。
助けが必要ですか?それを働かせるにはどうすればいいですか?
私は多くのコードを試しましたが、私はそれを働かせることはできません。
リンクを開くことができません! – Smit
問題なしで開かれただけです...どのようなエラーが表示されますか?再試行する。 – Dora