Thank you ashwani_multi.
I created the original post. I tried to post back immediately, but my new OpenCart forum account would not let me reply to posts. Therefore, I raised a ticket and waited for support to get back to me. They said this is a known issue and suggested I opened a new account. Here I am.
Regarding your kind help, the code you provided adds the text before the price on the line above, not in front of the price on the same line, I presume because the price is wrapped in a <h2> tag and you used (add position="before").
Therefore, I wrapped the additional text in <h2> tag and reduced the ‘margin-bottom’ to bring the two closer together.
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<modification>
<name>Add From Price</name>
<code>add-from-price</code>
<version>1.0</version>
<author>me</author>
<link>http://ocuk.co.uk/</link>
<file path="catalog/view/theme/*/template/product/product.tpl">
<operation>
<search><![CDATA[<?php echo $price; ?>]]></search>
<add position="before"><![CDATA[<h2 style="margin-bottom: -10px;">From</h2>]]></add>
</operation>
</file>
</modification>
This looked better, but it was not what I wanted.
I looked at your code again and I noted that you had just used <?php echo $price; ?> in <search>, without the header tags.
So, I tried again using add position="replace", without the header tags. This time the text was added just where I wanted it. Below is the code to modify the price with the additional text ‘From’ on the same line as the price.
I needed your help to get there. Thanks again; I am grateful.
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<modification>
<name>Add From Price</name>
<code>add-from-price</code>
<version>1.0</version>
<author>me</author>
<link>http://ocuk.co.uk/</link>
<file path="catalog/view/theme/*/template/product/product.tpl">
<operation>
<search><![CDATA[
<?php echo $price; ?>
]]></search>
<add position="replace"><![CDATA[From <?php echo $price; ?>]]></add>
</operation>
</file>
</modification>
Update:
My client then asked for the price with tax and without tax to be swapped positions.
The best method I found for achieving this was to add another product.tpl file in system\storage\modification\catalog\view\theme\default\template\product\product.tpl, which causes the file to overwrite the original like the Wordpress child theme system.
Then, I swapped the price with tax and without tax around. But this stopped the above ocmod to add the text ‘From’, from working - I presume because the duplicate product.tpl is called after the ocmod.
So, to get the words ‘from’ and ‘incl tax’ and ‘excl tax’ in the correct positions I added the 'from' 'incl' and 'excl' text and style directly onto the duplicate template (see below) and disabled the ocmod to add 'from' in front of price.
The below final code swapped the prices for with and without tax around and added the text ‘From’ in front of the top price. The code swapped n the duplicate of product.tpl was on line 137 down (OpenCart 2.3.0.2).
Code: Select all
<?php if ($price) { ?>
<ul class="list-unstyled">
<?php } ?>
<?php if ($tax) { ?>
<li><h2>From: <?php echo $tax; ?><span style="font-weight: 500; font-size: 14px;"> (excl. tax)</span></h2></li>
<?php if (!$special) { ?>
<li>
<h4><?php echo $price; ?> (incl. tax)</h4>
</li>
<?php } else { ?>
<li><span style="text-decoration: line-through;"><?php echo $price; ?></span></li>
<li>
<h2><?php echo $special; ?></h2>
</li>
<?php } ?>
<?php if ($points) { ?>
<li><?php echo $text_points; ?> <?php echo $points; ?></li>
<?php } ?>
<?php if ($discounts) { ?>
<li>
<hr>
</li>
<?php foreach ($discounts as $discount) { ?>
<li><?php echo $discount['quantity']; ?><?php echo $text_discount; ?><?php echo $discount['price']; ?></li>
<?php } ?>
<?php } ?>
</ul>
I hope this helps somebody else.