below is php code that another member posted which allows for a shortcode to be inserted in the short description of every woocommerce product page (code goes into the theme's function.php file). This has worked perfectly for me, but I have one more thing I need to achieve. I assume this is simple but I have primitive knowledge of php:
How do I make the inserted shortcode into a clickable link that links to a url of my choosing? Below is the code the is currently working and needs a hyperlink:
add_action( 'woocommerce_before_add_to_cart_form', 'enfold_customization_extra_product_content', 15 ); function enfold_customization_extra_product_content() {
echo do_shortcode("[wpqr-code]");}
Try:
add_action('woocommerce_before_add_to_cart_form','enfold_customization_extra_product_content', 15);
function enfold_customization_extra_product_content() {
echo ''. do_shortcode("[wpqr-code]") . '';
}
Related
When navigating to the next page of search results in Woocommerce, the title shows as
Search results: “example” – Page 2
I would like to know how I can customise this so the page number is not shown. Ideally, it would be nice to be displayed as
Search results for Example
I have looked in the files and this title seems to be called using
<?php woocommerce_page_title(); ?>
So there's not much there for me to work on.
There are lots of posts on removing the title all together, nothing on how to customise it.
You can use woocommerce_page_title hook to alter the title
according to your need.
Here is a working code:
// define the woocommerce_page_title callback
function filter_woocommerce_page_title($page_title)
{
if (is_search())
{
$page_title = 'Search results for ' . ucfirst(get_search_query());
}
return $page_title;
}
// add the filter
add_filter('woocommerce_page_title', 'filter_woocommerce_page_title', 10, 1);
Code goes in functions.php file of your active child theme (or theme). Or also in any plugin php files.
Hope this helps!
So I have attached an image of my issue.
Basically I followed the instructions on this Stack Overflow question thread right here:
Text under Add to cart (woocommerce)
I posted my question there 5 times and someone kept removing it, so I'm posting it again here. Please advise.
Update: I have already tried the paragraph tag, the break tag, and the pre tag.
You could try this (as you will see this is a CSS styling issue with the margin-top):
add_action( 'woocommerce_after_add_to_cart_button', 'custom_content_after_addtocart_button', 100 );
function custom_content_after_addtocart_button() {
// custom content.
echo '<br/><div><p style="font-size:10px; font-style=italic; margin-top:20px;">(*Contact us for bulk purchase enquiry)</p></div>';
}
Code goes in function.php file of your active child theme (active theme or in any plugin file).
Tested and works. You will get that:
This code will place it nicely below the Add to Cart button :
add_action( 'woocommerce_after_add_to_cart_form','content_after_addtocart', 100 );
function content_after_addtocart() {
// place your content below.
echo 'Hello There !!';
}
I've added the Like Button plugin to my wordpress page and it adds a like/dislike button at the bottom of my wordpress post.
I'd like to change the position where the buttons are shown (to below my post's title), but I can't find where the function that draws the buttons is being called.
Any way I can change that by editing one of the php files?
Thank you.
You'll need to search plugin's source code for the the_content hook and remove it like this:
remove_filter('the_content', 'same_function_name', 10)
Be sure that the last number is the same as the add_filter function, otherwise it won't work.
Then you can create your own function like this:
<?php
function my_new_button_position( $title ) {
$button_html = call_plugin_function_that_was_in_the_content_hook();
$title .= $button_html;
return $title;
}
add_filter( 'the_title', 'new_button_position' );
?>
The call_plugin_function_that_was_in_the_content_hook() is the function that was called in the content hook.
I'm all tied up in knots trying to echo shortcodes within shortcodes and I really need your help please!
Here's the code:
function custom_listify_single_job_listing_actions_after() {
global $post;
$url = get_post_meta( $post->ID, 'your_custom_meta_key', true );
echo 'Contact me';
echo '<div id="my-popup" class="popup"><?php echo do_shortcode('[groups_member group="Active Employer"]<?php echo do_shortcode('[widget id="jmfe_widget-7"]');?>[/groups_member]');?></div>';
}
add_filter( 'listify_single_job_listing_actions_after', 'custom_listify_single_job_listing_actions_after' );
The function adds a button to my site which opens a modal popup when clicked. I'm tying to display content within that popup that is restricted based on membership. That part uses the groups_member shortcode. Then, I'm trying to display content within the groups_member shortcode that belongs to a widget.
Each of the shortcodes works individually - the button, the popup, the restricted content and the widget shortcode - problem is that it doesn't work when I try to put it all together. I've wondered about creating a shortcode that contains the other shortcodes and then somehow inserting that into the popup function, but I'm rubbish at this stuff as it turns out! Can you help please?
I'm not to sure what you are after but echo with php, using string operators would give something like this, which is untested and may be missing a dot or a ' somewhere
echo '<div id="my-popup" class="popup">'.do_shortcode('[groups_member group="Active Employer"]'.do_shortcode('[widget id="jmfe_widget-7"]').'[/groups_member]').'</div>';
I am trying to use php echo shortcode into Wordpress but I can't figure out how.
I want to use this shortcode:
php echo $pack['download_link'];
To add a shortcode in worpress:
add_shortcode('tag','myfunction' ); this add the shortcode in wordpress
function myfunction {
//your code to run
}
In pages or post use [myfunction]:
in templates echo do_shortcode('[myfunction]');
Your question has already been answered in a previous post
In short, PHP code cannot run within a WP post without an associated plugin that will process the PHP shortcode.