I am trying to auto-add some shortcode at the end of every woo product description. (not after short description). The code with which I am trying is:
add_filter('product_descr','ce_add_text_short_descr');
function ce_add_text_short_descr($description){
$text="[my-shortcode-goes-here]";
return $description.$text;
}
That one is not working for me. can someone help me?
add_filter('the_content', 'mujuonly_alter_product_description');
function mujuonly_alter_product_description($description) {
if (is_product()) {
$text = do_shortcode('[products limit="4" columns="4" orderby="popularity" class="quick-sale" on_sale="true" ]');
return $description . $text;
}
return $description;
}
This way using the hook the_content you can update the product description using the shortcode
add_filter('woocommerce_short_description','ts_add_text_short_descr');
function ts_add_text_short_descr($description){
$text = do_shortcode('[my-custom-text]');
return $description.$text;
}
You are making mistake with woocommerce hook and if we neeed to print a shortcode in a php file it works with do_shortcode(); Hope it will work on your side I have already tested it.
Don't forget to replace my-custom-text with your shortcode.
Related
I would like to place my own content (in my case a shortcode) on the thank you page at WooCommerce after completing the order, which depends on the shipping method.
So for example:
Shipping Method 1: Content 1
Shipping Method 2: Content 2
Shipping Method 3: No content
I have already found something for text here, but i dont get the shortcode inserted. Alternatively I have tested what works with the shortcode here, where the dependency on the shipping method is missing.
Maybe someone can help me to implement this.
Ideally the content should be above the table with the order information.
Thanks a lot!
May be the way you added the shortcode to the thank you text can be the issue.
See the following shortcode function called avengers which i created for demo.
function call_avangers( $atts ){
return "<p>Avengers . . . . Assemble !!!</p>";
}
add_shortcode( 'avengers', 'call_avangers' );
You can display this shortcode in thank you page using the below function
add_filter( 'woocommerce_thankyou_order_received_text', 'woo_change_order_received_text', 20, 2 );
function woo_change_order_received_text( $text, $order ) {
if( $order->get_shipping_method() == 'your_shipping_method_here' ) {
$text .= do_shortcode('[avengers]');
}
return $text;
}
The basic thing is you have to call do_shortcode('your_shortcode_name')
I am really quite new to programming and I need help with something that I think is not difficult. What I want is to delete the title of the attachment page, I have searched and in this forum I have found a code that has worked partially. That is, the code removes the title but also removes the menu from the attachment page. I have searched everywhere, and I have seen that conditional tags are required to generate that function, however, I am a beginner in the world of websites and I need your help. The code is the following:
add_filter( 'the_title', 'remove_page_title', 10, 2 );
function remove_page_title( $title, $id ) {
if (is_attachment())
return '';
return $title;
}
Thanks in advance for your help.
In your child theme you would add this into the functions.php file:
function remove_page_title( $title, $id ) {
if (is_attachment()):
return '';
return $title;
endif;
}
remove_action('virtue_page_title_container', 'remove_page_title', 20);
I hope it would help you out.
I am trying to place an image next to the product description in the tabs of woocommerce. The code I am trying to use is this:
add_action('woocommerce_template_product_description', 'badge', 25);
function badge() {
echo '<div class="badge"><img src="URL" style="width:175px;height:175px;"></div>';
}
I have not had any luck in getting it to display, and am thinking that the 'woocommerce_template_product_description' maybe the problem - I'm sure if I am targeting the product description correctly. I think tabs are increasing the complexity of the solution.
Using the code below the image displays next to the product summary.
add_action('woocommerce_single_product_summary', 'badge', 25);
function badge() {
echo '<div class="badge"><img src="URL" style="width:175px;height:175px;"></div>';
}
I would appreciate some help is solving this problem.
After much head scratching I think I might have figured it out. This code seems to work:
add_filter( 'woocommerce_product_tabs', 'magva_badge', 98 );
function magva_badge( $tabs ) {
$tabs['description']['callback'] = 'woo_custom_description_tab_content'; // Custom description callback
return $tabs;
}
function woo_custom_description_tab_content() {
woocommerce_product_description_tab(); echo '<div class="magva_badge"><img src="https://www.magva.com/wp-content/uploads/2015/10/made_in_ireland.png" style="width:175px;height:175px;"></div>';
}
I have problems with add_filter functions in WordPress.
Code:
function ftp_content_filter($content) {
$content = preg_replace("#\[form_to_pdf\]#si", ''.ftp_content().'',$content);
return $content;
}
add_filter('the_content', 'ftp_content_filter');
It's working , but i have ftp_content(); on every page.
Code [form_to_pdf] is only in page_id=3 and I want to have this function only on this page.
I thnik that 'the_content' is content from every page, so how can i filter only single (current open) page?
Thanks for help.
This way, you shortcode should work anywhere shortcodes do:
function form_to_pdf_func() {
return ftp_content();
}
add_shortcode('form_to_pdf', 'form_to_pdf_func');
I am just working on filter titles in pages and posts and everything works as expected but when I view the single.php whereas it shows the actual post as should be, the function hook filter i am working on inside functions.php of my plugin is filtering every title of each post of my blog, I was expecting to filter just the title of the current post:
add_filter( 'the_title', 'ta_modified_post_title');
function ta_modified_post_title ($title) {
if((in_the_loop())){
/**/
}
}
any help is grateful.
Thanks ;)
add_filter( 'the_title', 'ta_modified_post_title');
function ta_modified_post_title ($title) {
if((some condition true)){
$add_this = 'some string';
$new_title = $title.' '.$add_this;
return $new_title;
}
return $title;
}
when you view any post it is shown through single.php so every post becomes current post when you view it
I understand now that for the filter title hook it is the same viewing a single post from single.php than viewing the whole blog. would there be a way of filtering with a condition to only retrieve the title of the current post in single.php?, I did try "get_the_title(get_the_ID())" like this but obviously I cant nest it.
add_filter( 'the_title', 'ta_modified_post_title');
function ta_modified_post_title ($title) {
if((in_the_loop())){
if(is_single()){
$title=get_the_title(get_the_ID());
}
}
}