how to (line) break output at specific keyword? - php

Situation: PHP-based CMS (OpenCart 2.0.3.1) -> category page -> outputs the product names via:
<?php echo $product['name']; ?>
Problem: need to wrap a portion of the product name, to the next line. For example, what currently displays as 20-inch Blue Widget For Golfers should display as
20-inch Blue
Widget for Golfers
So every product that has the word "Widget" (or "AnotherKeyword" in it), should have a <br> before it.
How can this be done?
P.S. Changing the product name itself to include a <br> or <br> doesn't work, since OpenCart displays whatever is in the Product Name field literally, ignoring HTML. (Unless someone can point me in the direction of "how to echo the $product[name] but actually process the HTML in it").

As suggested, you can first replace in php "Widget" with a br in front and then via jquery wrap all this way:
<script>
$(".name a").text(function () {
$(this).wrap('<pre />');
})
</script>

Related

How to modify widget's innerHTML in Woocommerce

I'm trying to show that one of the categories is on sale by displaying "ON SALE! -50%" text in category list widget.
I obviously can't and won't modify category name to include this text.
Here's the website: https://demo.wpdesk.org/michalkleszko23gmailcom/
Maybe the fastest way how to do it is to write a short javascript, which will edit text. So, if yours widget has id="block-5" (according to the demo), you just add replacing script into the next custom HTML widget under the yours category widget.
<script>
document.getElementById('block-5').innerHTML = document.getElementById('block-5').innerHTML.replace("Albums", "Albums <div style=\"color:red\">ON SALE! -50%</div>");
</script>

Adding html inside function

I need to add a symbol (→) inside a function. The function is supposed to display a product tag on the woocommerce single product page and link back to the specific tag archive. the last part of the function is
echo '<h2>'.$text.'</h2>';
and I need the arrow to be displayed righ after the term slug. How do I insert it?
You can add it as a html entity →
echo '<h2><a href="'.esc_url($link).'" title="'.$text.'" class="" '.$term->slug.'>→'.$text.'</a></h2>';
Hope I understand it correctly "displayed righ after the term slug" that you want it displayed before the text.
Here's the entity table for future references: https://www.w3schools.com/charsets/ref_utf_arrows.asp

How to add "final sale" next to special price in cart page magento

I would like to add "final sale" for sale items next to special price in cart page.
i added
<span class="price-label"><?php echo $this->__('Final Sale') ?></span>
in
template/checkout/cart/item/default.phtml
but I am getting final sale for all the items in cart page.
i want to add final sale for only sales items.
How can i do that?
You can actually do this with an observer. The event to use is core_block_abstract_to_html_after and then you you can get that block's html with:
$transport = $observer->getTransport();
$html = $transport->getHtml();
// do some stuff here to determine which items you need to edit the label for.
// after editing the label, maybe with DomDocument and xpath, set the new html at the end
// of your observer like so:
$transport->setHtml($html);
I use this method all the time because i hate modifying template files when the change is something small like you want to do.
Use the Transate Inline.
Turn it on via System -> Configuration -> Developer -> Translate Inline.
You can change what it says by clicking it and changing the words to "Final Sale".

Wordpress custom field - show image

I am creating a menu for an Indian restaurant, The Curry Lounge. I want to show the vegetarian symbol next to the title (as shown) if it is actually a vegetarian dish.
I have tried to look for a way to do this in custom fields but have had no luck in doing so. I have created a custom field within one of my posts and called it "hass_veg" and in the menu_page_template of my theme I have the following code where I want it to be placed:
<?php if ( $hass_veg <> 'Y' ) { ?>
<img src="http://www.tesco.com/wine/UIAssets/I/Sites/Retail/Wine/Online/Product/IsVegetarian.gif" alt="Vegetarian" height="30" width="30">
<?php } ?>
I have deduced that when I put the "Y" in, the image appears on the page.
Can anyone help me at all?
In your stylesheet:
.cufon-canvas{
background: url('path_to_your_image_goes_here');
}
Or whatever class name you choose to give the div next to the vegetarian items. I'd add the image in the stylesheet so you (and others) don't have to dig through the php to change it.

How to display text in my wordpress post except if it's in a certain category?

I want to display certain text in all my posts except if it's in this one category. How do I do that? Oh yea I almost forgot I want to include the title of the post in the text. So I think I need to use echo, cat='-5', and or something?? I don't know how to form it though. Thanks!
You could use the Wordpress function in_category(). When you use it inside the loop, it returns true if the current post is a member of the category you passed it.
<?php
if ( in_category('my-category'))
{
// don't output text
} else {
// do output text
}
?>
Do you require the text to be completely locked away, or just hidden from view? If you only need it hidden from view (but accessible to anyone who chooses to pry) then you may be able to do it very quickly using css.
If you have coded your theme - or are using someone else's - that adds helpful styles into the header, you may have a lot to work with already. For example, this is a body declaration generated by the Thematic theme:
<body class="wordpress y2011 m01 d31 h12 archive category category-orthopaedics">
Say you have a chunk of content to hide:
<div class="text_to_hide">This is what gets hidden.</div>
Then you declare the CSS as:
.category-orthopaedics .text_to_hide { display: none; }

Categories