我有一个可配置产品的商店。 在包含我所有产品的类别页面中,我想在价格之前添加文字。 我怎样才能做到这一点?我使用现代主题。
答案 0 :(得分:1)
在getPriceHtml之前添加你的文字($ _ product,true)?>在catalog / product / list.phtm
中如下所示:
<?php echo "YOUR TEXT" ?>
<?php echo $this->getPriceHtml($_product, true) ?>
答案 1 :(得分:0)
你可以查看
app/design/frontend/default/yourtheme/template/catalog/product/price.phtml
如果您的主题没有文件使用 你可以看看
\app\design\frontend\base\default\template\catalog\product\price.phtml
Around line 189 you will find the following:
<span id=”product-price-<?php echo $_id ?>
<?php echo $this->getIdSuffix() ?>”>
Just add the following above the line:
<?php echo $this->__(‘Your Text Goes Here:’) ?>
so that you have something like this:
<?php echo $this->__(‘Your Text Goes Here:’) ?>
<span class=”regular-price” id=”product-price-<?php echo $_id ?>
<?php echo $this->getIdSuffix() ?>”>
Your text will be reflected before the price in both
the catalog and the product page.
答案 2 :(得分:0)
在magento 2 中,您需要在use strict;
use warnings;
print "Please type in your first name here :";
my $name = <STDIN>;
chomp($name);
my $reversed_name = reverse($name); #at this point Name becomes emaN
my $lower_cased = lc($reversed_name); #emaN becomes "eman"
my $final_string = ucfirst($lower_cased); #then upper-case the first character which is "E" so that the string becomes "Eman" here
print "$final_string" . "\n";
进行更改
/vendor/magento/module-catalog/view/base/web/js/price-box.js
确保将此js放在自定义主题文件夹中,并在附近的第22行进行更改
price-box.js
在priceTemplate: '<span class="price"><%- data.formatted %></span>'
有点像这样,
<span class="price">
完成。
答案 3 :(得分:0)
要在价格前添加标签,您需要覆盖自定义主题中的final_price.phtml文件-
核心文件路径-
vendor/magento/module-catalog/view/base/templates/product/price/final_price.phtml
覆盖您的自定义主题-
app/design/frontend/VendorName/ThemeName/Magento_Catalog/templates/product/price/final_price.phtml
更改代码如下-
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
// @codingStandardsIgnoreFile
?>
<?php
/** @var \Magento\Catalog\Pricing\Render\FinalPriceBox $block */
/** ex: \Magento\Catalog\Pricing\Price\RegularPrice */
/** @var \Magento\Framework\Pricing\Price\PriceInterface $priceModel */
$priceModel = $block->getPriceType('regular_price');
/** ex: \Magento\Catalog\Pricing\Price\FinalPrice */
/** @var \Magento\Framework\Pricing\Price\PriceInterface $finalPriceModel */
$finalPriceModel = $block->getPriceType('final_price');
$idSuffix = $block->getIdSuffix() ? $block->getIdSuffix() : '';
$schema = ($block->getZone() == 'item_view') ? true : false;
?>
<?php if ($block->hasSpecialPrice()): ?>
<span class="special-price">
<?php /* @escapeNotVerified */ echo $block->renderAmount($finalPriceModel->getAmount(), [
'display_label' => __('Custom Label 1 : '),
'price_id' => $block->getPriceId('product-price-' . $idSuffix),
'price_type' => 'finalPrice',
'include_container' => true,
'schema' => $schema
]); ?>
</span>
<span class="old-price">
<?php /* @escapeNotVerified */ echo $block->renderAmount($priceModel->getAmount(), [
'display_label' => __('Custom Label 2 : '),
'price_id' => $block->getPriceId('old-price-' . $idSuffix),
'price_type' => 'oldPrice',
'include_container' => true,
'skip_adjustments' => true
]); ?>
</span>
<?php else: ?>
<?php /* @escapeNotVerified */ echo $block->renderAmount($finalPriceModel->getAmount(), [
'display_label' => __('Custom Label 3 : '),
'price_id' => $block->getPriceId('product-price-' . $idSuffix),
'price_type' => 'finalPrice',
'include_container' => true,
'schema' => $schema
]); ?>
<?php endif; ?>
<?php if ($block->showMinimalPrice()): ?>
<?php if ($block->getUseLinkForAsLowAs()):?>
<a href="<?= /* @escapeNotVerified */ $block->getSaleableItem()->getProductUrl() ?>" class="minimal-price-link">
<?= /* @escapeNotVerified */ $block->renderAmountMinimal() ?>
</a>
<?php else:?>
<span class="minimal-price-link">
<?= /* @escapeNotVerified */ $block->renderAmountMinimal() ?>
</span>
<?php endif?>
<?php endif; ?>
在这里,我在下面的代码中更改了文本,并且在其他情况下也将该代码添加到了该代码中,因为在其他情况下它不存在。
'display_label'=> __('Custom Label 3:'),
谢谢