I have an php code which I want to put in my product page.
but I want to place this PHP below the price. when I add this snippet to my "single-product-style3.php" file which represent my layout for product page, the code adds below my add to cart button but I want it to be under the price.
I have another code which I use for my "view cart" page.
Just to clarify everything here is two screenshot, I want the paybright text to be in the red spot.
https://imgur.com/wbXBlF0
https://imgur.com/li4Duzd
Can someone help me please?
this is my website address: https://mayagallery.ca/
I wanted to know where should I upload and add this snippet:
<?php
function pb_modal() {
$pb_product_price = get_post_meta( get_the_ID(), '_price', true);
$pb_product_format = number_format((float)$pb_product_price, 2, '.', '');
echo "<script id='pb_prequalify' type='text/javascript' src='https://app.paybright.com/dist/sdk.js?public_key=*******'></script>
<script>
pb_prequalify_init();
</script>
<div id='paybright-widget-container'></div>";}
add_action( 'woocommerce_after_add_to_cart_form', 'pb_modal', 1);
?>
You should try this:
add_filter( 'woocommerce_get_price_html', 'woo_add_text_after_price_single_product', 20, 1 );
function woo_add_text_after_price_single_product($price){
// Your custom text
$custom_text = '<span style="color: #ff0000;">My Custom Text Here...</span>';
return $price.'<br>'.$custom_text;
}
Reference URL: https://stackoverflow.com/a/68936308/16560548
If you want to show test on shop page also you should try such type - https://stackoverflow.com/a/69025097/16560548
Related
I want to be able to add an "li" tag within my product title. To achieve this in a user friendly way I wrote a code which changes the character "-" to an "li" tag. But currently the html does not have an effect on the "order-details-table" (which for example appears when you finished ordering). Is there another filter to add the html globaly so it changes "-" to "li" every time the title occures? --> I updated my code and the html now appeares everywhere, only the following problem is remaining:
In the backend however the html gets added, but gets shown as plain text, so it does not have an effect. Is there also a solution to this problem?
What the product title looks like at the moment --> the html gets interpreted as normal text
add_filter( 'the_title', 'custom_the_title', 10, 2 );
add_filter( 'woocommerce_cart_item_name', 'custom_the_title', 20, 3);
add_filter( 'woocommerce_order_item_name', 'custom_the_title' );
function custom_the_title( $title){
$title = str_replace( '-', '<li>', $title );
$title = str_replace( '.', '</li>', $title );
return $title;
}
Thanks a lot for your help, and greetings from Austria!
Samuel
Are you trying to get something like this? If not, please give more information, what do you expect to see? Any visual example? Where do you want to see those changes?
add_filter( 'the_title', 'custom_the_title', 10, 2 );
add_filter( 'woocommerce_cart_item_name', 'custom_the_title', 20, 3);
function custom_the_title( $title){
$title = '<li>'.$title.'</li>';
return $title;
}
The problem is still presisting even on Wordpress version 5.2.4 and not only on Wordpress 5.5; I have tried the suggested function but it won't work as the html code will always be shown as part of the title text. For instance if I want to add a line break of change a word in the title to red the html tags will just show and the html is not rendered by the browser.
Even with php function html_entity_decode() applied to the title no luck!
So here is the fix:
After checking the code on Woocommerce latest update I found the culprit on the titile.php woocommerce plugin code:
echo esc_html( get_the_title() );
you will need to edit that and remove the esc_html(). But this is temporary as any update on the woocommrce plugin will perhaps return the issue. So I will leave it to experts here to suggest a better solution.
I found the same issue where I'd added some spans to my titles that were suddenly being rendered as text instead of HTML. It was indeed thanks to the addition of an esc_html() around the title in woocommerce/templates/single-product/title.php.
I've fixed it by copying the file to my theme folder under woocommerce/single-product/title.php and simply removing the esc_html(). This is the 'update-proof' solution as it will not be overwritten when WooCommerce next updates.
<h1 class="product_title entry-title">
<?php echo get_the_title(); ?>
</h1>
is there a way ON MOBILE to move the 3 dropdowns section to the above the product name and gallery image?
I am using the woocommerce plugin and for the dropdowns im using the PRODUCT DATA - VAriable product section.
check the link:
Website
I would need more about your actual code (or a demo version) to achieve what you exactly want. You could use a bit of jQuery in your function.php, the following code as not been tested but the logic is there:
/*Move the variation div to another created one
======================================================================= */
add_action( 'wp_footer', 'move_variations_product_tab' );
function move_variations_product_tab() {
if (is_product()) :
$product = wc_get_product( get_the_ID() );
if($product->is_type( 'composite' )){
?>
<script>
jQuery(document).ready(function($) {
$(window).load(function() {
$( ".variations_form" ).wrap( "<div id='variations-content'></div>" );
$( ".woocommerce-product-gallery" ).before( "<div class='container product-before-gallery'></div>" );
document.getElementsByClassName("product-before-gallery")[0].appendChild(
document.getElementById("variations-content")
);
});
});
</script>
<?php
}
endif;
}
Replace "product-short" by the container of your description.
Wrapping around the div you want to move.
Creating a new class before the desired location
Move the wrapped div (#variations-content) under the newly created one
(.product-before-gallery).
Hope that helps! Let me know how it goes and give more info if you needs help.
Cheers
I am new in woo commerce. I have tried with this code But it is not working
function contact_concierge() {
return '<a class="fsfb" href="'.site_url().'">CONTACT CONCIERGE</a>';
}
add_action('woocommerce_after_cart', 'contact_concierge');
I want to add the button after the singple page add to cart table. PLease help me.
The closest place you can get it to is underneath the product title, using:
function contact_concierge() {
echo '<a class="fsfb" href="'.site_url().'">CONTACT CONCIERGE</a>';
}
add_action('woocommerce_single_product_summary', 'contact_concierge');
Screenshot:
Reference:
http://docs.woothemes.com/document/hooks/
<?php do_action( 'woocommerce_after_add_to_cart_button' ); ?>
and
<?php do_action( 'woocommerce_after_add_to_cart_form' ); ?>
Are actually much closer to what the OP was looking for... assuming I understood correctly. The former is directly after the add to cart button and is therefore inside the <form> element. The latter is after the </form> closing tag.
You can see them in the WooCommerce templates /single-product/add-to-cart/single.php as well as variable.php and grouped.php.
function contact_concierge() {
echo'<a class="fsfb" href="'.site_url().'">CONTACT CONCIERGE</a>';
}
add_action('woocommerce_after_add_to_cart_button', 'contact_concierge');
I'm trying to find out what action hook/filter I can use to insert content on the admin "edit.php" page (i want to place a few links above the 'posts' table)? I've found "edit_form_after_title" and "edit_form_after_editor" (these do exactly what I want to do, but they are for posts.php, not edit.php).
With the help of this answer: How do you create a custom edit.php / edit pages page
I came up with this:
<?php
# Called only in /wp-admin/edit.php pages
add_action( 'load-edit.php', function() {
add_filter( 'views_edit-talk', 'talk_tabs' ); // talk is my custom post type
});
# echo the tabs
function talk_tabs() {
echo '
<h2 class="nav-tab-wrapper">
<a class="nav-tab" href="admin.php?page=guests">Profiles</a>
<a class="nav-tab nav-tab-active" href="edit.php?post_type=talk">Talks</a>
<a class="nav-tab" href="edit.php?post_type=offer">Offers</a>
</h2>
';
}
?>
And it looks like this:
If you just wanted to add to the post title link you could do something like this
if (is_admin()) {
add_filter('the_title', function($title) {
return $before_title . $title . $after_title;
});
}
however, it doesn't sound like you want to add text to the title link.
To add html after the title and before the actions links, you could do like this
if (is_admin()) {
add_filter('post_row_actions', function($args) {
// echo your custom content here
return $args; // and dont forget to return the actions
});
}
There is also page_row_actions for the page edit screen (post_row_actions is only for posts)
As far as adding stuff before the title, I don't see a hook/filter to do that. See wp-admin/class-wp-posts-list-table.php line 463 function single_row if you want to look for yourself.
I am editing a Custom Post Type template, and am using custom fields to enter info into a meta box to be included on the page, as well as include some static default text on all the pages.
I basically need to "chunk" together the post info in the_content along with the static text and some meta box info. Here's what I want:
the_content
static text
meta box 1
more static text
meta box 2
end of the _content
I have plugins that add social buttons before the_content and a signature after the_content so I am trying to figure out how to get all my custom stuff sandwiched in between those.
If I just add the meta boxes i nthe template, they display outside of the_content and the plugins display in unwanted places.
I ended up figuring this out on my own. The solution: using functions.php and add_filter, I had to create a new function to create the default content, and it works great.
here's the general code for anyone interested:
function custom_post_type_default_content($content) {
global $post;
if ($post->post_type == 'your-custom-post-type') {
$content .= '<p> '. get_post_meta( $post->ID, "metabox-1-slug", true ).'
<br />
<p> '. get_post_meta( $post->ID, "metabox-2-slug", true ).'</p>
<p>YOUR TEXT HERE.</p>';
}
add_filter('the_content', 'custom_post_type_default_content', 0);
Note that the zero just near the end controls placement. I have a social media plugin that has a priority of "1", and to get the default content to appear above that I have to make this a priority of "0".
Also note the single apostrophes that open and close the code following $content .=
You basically add whatever you want between those apostrophes, and in this case I am pulling metabox info which have their own apostrophes containing code. It gets confusing!
In other words, your code should be $content .='YOUR CUSTOM CONTENT' and within those apostrophes, add your text, code, etc. The standalone metabox code is '. get_post_meta( $post->ID, "metabox-1-slug", true ).' which is nested inside where the YOUR CUSTOM CONTENT text is.
I am basically explaining this to myself, as these were the things that tripped me up so figured would explain them in detail to help someone else like me. Or me when I have to go look this up again!
Post your single.php here or on pastebin along with the custom field names you're using (& where you want them) and I'll try to help you figure out what you want.
Copy this code to your function.php file.
function content_function_update($content) {
global $wp_query, $post;
if ($post->post_type == 'your-custom-post-type') {
$postid = $wp_query->post->ID;
$value1 = "your value 1";
if($value1 !== '') {
$content = $content . "<br>" . $value1
}
else {
$content = $content;
}
}
return $content;
}
add_filter('the_content', 'content_function_update');
Add any custom content in variables and append it to $content variable.