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
Related
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>
I use a product category description in every products category in woocommerce, but i don't know how to show the full description. After a few words it just stops and shows "..."
https://i.stack.imgur.com/BaOx5.jpg
There are 2 general ways I'm aware the text would show ... at the end. Either via code or by CSS text-overflow: ellipsis; If it's using the CSS method, then you got to inspect the element (try right-click on element and choose Inspect, or something similar to that), see which html tag has the style set and then remove it or override it in the stylesheet.
(BTW: If you notice that the full description is there when inspecting the element, then text-overflow CSS is most likely involved.)
Read more here: https://developer.mozilla.org/en-US/docs/Web/CSS/text-overflow
If it's not CSS but done by code, then it's necessary to get more details on the code used for this to know how to change it. It can be done either by JavaScript or PHP and might be dependent on the WordPress Theme in use.
A quick solution is to observer the source code for the page. See if the full text is in use anywhere else on the page, and then use JavaScript to rewrite the text in the Description area based on it. Read more http://api.jquery.com/html/
Otherwise, you will have to find out if there are any API Hooks that can intercept the Description area to change the text. (Maybe https://codex.wordpress.org/Function_Reference/category_description or http://hookr.io/actions/woocommerce_archive_description/)
Again it might be dependent on the theme. If you are not getting through, add the Theme name to your question, to try get more help.
Here's an example of how to use woocommerce_archive_description
add_action( 'woocommerce_archive_description', 'woo_category_description' );
function woo_category_description() {
if ( is_product_category() ) {
global $wp_query;
$cat_id = $wp_query->get_queried_object_id();
$cat_desc = term_description( $cat_id, 'product_cat' );
$description = '<div class="description">'.$cat_desc.'</div>';
echo $description;
}
}
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>
I would need to reach a custom section by page id (or PageModel Object), but I don't find a way to get the FrontendTemplate. I would like to use it in a dropdown navigation to echo a custom section of the hovered (parent) page.
If somebody will search for, the answer is:
<?php
$articles = \ArticleModel::findPublishedByPidAndColumn($id, $column_name);
echo static::getArticle($articles[0]); // for ex. the first article
?>
I've made a template for specific pages of our website that display similar content, yet are different form the rest of the pages of the website - here's an example. I have several custom fields that I use to include all of the items you see in the boxes that float to the left and right.
My problem is, I also have pricing that's included from a custom field - and because I want it at the bottom of the page, it actually appears outside the content to work (see the bottom of my example given above). Is there a way I can call the content and tell it to display these custom fields at after the content is displayed?
Obviously the following doesn't work, but just to give you an idea:
<?php the_content(get_post_meta($post->ID, "Pricing_Mexico", true); ?>
Additionally, there are actually a lot of custom fields that need to be displayed, so if it were possible to include them in bulk (including the markup which includes divs and what-not) that would be preferred. Thanks!
You could filter the_content() so in your functions file:
function contentFilter($content){
// Output the current content
echo $content;
// Output the meta field
echo get_post_meta($post->ID, "Pricing_Mexico", true);
}
add_filter('the_content', 'contentFilter');
You could echo as many meta fields as you need inside the function.