I need a function to add a HTML code before checkout header title on WooCommerce. I would like to add a process bar.
Thanks
The Checkout title is located in the header.php of your theme. So there is no any WooCommerce hooks for that.
So you can accomplish that editing the header.php file of your active child theme (or active theme) using the dedicated WooCommerce conditional tag is_checkout():
<?php if( is_checkout() ): ?>
<!-- HERE GOES YOUR HTML CODE DISPLAYED ONLY IN CHECKOUT HEADER -->
<?php endif; ?>
ADDITIONAL UPDATE:
For checkout only and not order recieved (thank you):
<?php if( is_checkout() && ! WC()->cart->is_empty() ): ?>
<!-- HERE GOES YOUR HTML CODE DISPLAYED ONLY IN CHECKOUT HEADER -->
<?php endif; ?>
Related
the code below is part of main php code for Dokan Vendor Shop Page.
in Full Site Editing i have added my custom header / footer (name in template part: My Custom Header) and using replace optioni was able to show them instead of default header/footer in all other template but i am unble to replace/show them in this custom php code.
i have tried get_header( 'my_custom_header' ); and php get_footer( 'my_custom_footer' ); and no luck.
please help me how to achieve that?
<?php
/**
* The Template for displaying all single posts.
* #package dokan - 2014 1.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
get_header( 'shop' );
?>
<?php do_action( 'woocommerce_before_main_content' ); ?>
<div class="dokan-store-wrap
....
....
</div><!-- .dokan-store-wrap -->
<?php do_action( 'woocommerce_after_main_content' ); ?>
<?php get_footer( 'shop' ); ?>
The problem is that you are mixing two meanings of template. get_header() is function (and the same get_footer()) which will "paste" the code of a php file. So your theme has a *.php template (in your case it will be named header-shop.php) and by calling get_header() it will add header in process of rendering the website.
On the other hand, you created your header/footer templates in Gutenberg editor. They are handled by a Gutenberg plugin. You should just try call get_header(); without any parameters. It should be handled in the standard way and then you can modify it using Full Site Editing.
Before that, you should check if on your specific page there isn't a function get_header() override. It can be done by some plugin.
I have a child theme from Storefront and have custom page templates running for the homepage and other pages without issues.
I am building a custom layout for Woocommerce pages and use content-single-product.php for the single product page with custom code in the file for example:
<div class="wc-product-images">
<?php do_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_images'); ?>
</div>
<div class="wc-product-description">
<?php the_content(); ?>
</div>
Question 1: Do I call the Woocommerce Content correct with do_action() in the template file? I have a specific layout and cannot follow the hook layouts as per the default file
Question 2: When I call:
<?php
do_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products' );
?>
I get the product description with the related products and actually need to build a div with only related products.
How can I call this properly without the description included?
Any help is appreciated.
You are making confusions, original do_action( 'woocommerce_before_single_product_summary' ) enables an entry point in woocommerce content-single-product.php template, where add_action() is used to hook other templates using the functions:
woocommerce_show_product_sale_flash() (with a hook priority of 10)
woocommerce_show_product_images() (with a hook priority 20)
So if you want to enable only the product image in your custom template you will have to create your own hook:
<div class="wc-product-images">
<?php do_action( 'woocommerce_before_single_product_summary_custom' ); ?>
</div>
<div class="wc-product-description">
<?php the_content(); ?>
</div>
Then you will add this in function.php file of your active child theme (or active theme):
add_action( 'woocommerce_before_single_product_summary_custom', 'woocommerce_show_product_images', 20 );
It should work as intended.
But you can use in your custom template the original hook, if you don't need any different hook customizations… In that case you will only have that:
<div class="wc-product-images">
<?php do_action( 'woocommerce_before_single_product_summary' ); ?>
</div>
<div class="wc-product-description">
<?php the_content(); ?>
</div>
Additon: Related to your comment (regarding related products).
To enable related products in your custom template, add this block in it (with a custom hook):
<div class="wc-product-related">
<?php do_action( 'custom_after_single_product_summary' ); ?>
</div>
Then you will add this in function.php file of your active child theme (or active theme):
add_action( 'custom_after_single_product_summary', 'woocommerce_output_related_products', 20 );
It should work.
So I am working on WooCommerce with a Child-theme. I have created my structure,
/themes/child/woocommerce/checkout/review-order.php
My goal is just to add some 'static text' to the page.
So for example, <h2>Purchase Disclaimer</h2>
Inside review-order.php
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?>
<h2>Purchase Disclaimer</h2>
My problem is, when I view the page, it then goes,
<h2>Purchase Disclaimer</h2>
<h2>Purchase Disclaimer</h2>
I don't know why it seems to load it 2 times. Is this a glitch, or am I loading it weird? Perhaps someone could help clarify this issue for me.
Thanks in advance
Checkout review-order table load first one time and then ajax is making a 2nd loading (for update purposes is suppose), so you have to use a little condition to avoid that:
<?php if(!defined( 'DOING_AJAX' )): ?>
<h2>Purchase Disclaimer</h2>
<?php endif; ?>
You should avoid <h2> tag as it's already use for <h3 id="order_review_heading">Your order</h3>
Alternatively you can use instead a hooked function in woocommerce_checkout_before_order_review hook this way:
add_action('woocommerce_checkout_before_order_review', 'my_custom_funtion');
function my_custom_funtion(){
?>
<h2>Purchase Disclaimer2</h2>
<?php
}
This code goes in function.php file of your active child theme (or theme) or also in any plugin php files.
I'm developing a wordpress theme where I have a set of custom pages and each page has it's own content! For an example, say there is a custom page where the content is already done using HTML but I need to be able to change the content of a single paragraph using the wordpress admin panel.
How do i do this using the wordpress framework? is there any special way of adding custom editable fields to specific content locations in a page?
Just add meta box and get the values from post meta to show in your html
you can generate metabox from this site without any programing skills
https://jeremyhixon.com/tool/wordpress-meta-box-generator/
and get meta field value with the below code
get_post_meta(get_the_ID(), 'meta_key', true);
Use Wordpress loop to do this:
<div class="content">
<p>Your static content goes here</p>
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
<?php endif; ?>
<p>Or here</p>
</div>
This part between if(have_posts()) and endif; will be generated from Wordpress admin panel so you can easily change it with page WYSIWYG editor without any additional plugins.
Don't forget to create your custom pages as page templates and assign to page in admin panel otherwise it won't work as expected.
Use the following code:
<?php
$id=2;
$post = get_post($id);
$content = apply_filters('the_content', $post->post_content);
echo $content;
?>
Here, $id=2 is your page id which is you get from WordPress Admin panel.
On Azure hosted Wordpress site I have to use a Universal Header/Footer (UHF) which when activated overrides the sites header/footer.
I require the sites original Navigation and added Footer code to run.
These are the README.md instructions:
Theme integration
Once UHF has been configured, minor changes need to be made within your site's theme(s):
Begin by wrapping the theme's current header in a Microsoft\UHF\is_active() conditional statement. This helper method will determine if UHF is configured and active for the current site. Meanwhile, your existing code will be in the else portion of the conditional, enabling your site's current functionality to persist should UHF ever be deactivated.
Example:
<?php if ( function_exists( '\Microsoft\UHF\is_active' ) && \Microsoft\UHF\is_active() ) : ?>
<?php \Microsoft\UHF\get_header(); ?>
<?php else : ?>
<!-- Your original header -->
<?php endif; ?>
Please note that the UHF header should be the first thing under the <body> element, but it does not replace your existing <head> element!
The footer replacement will be similar:
<?php if ( function_exists( '\Microsoft\UHF\is_active' ) && \Microsoft\UHF\is_active() ) : ?>
<?php \Microsoft\UHF\get_footer(); ?>
<?php else : ?>
<!-- Your original footer -->
<?php endif; ?>
The provided code samples show how to replace the header and footer with UHF's (when the feature is activated), but if you need the UHF header and/or footer and your original header/footer, you can adjust the conditional statement, e.g.:
<?php if ( function_exists( '\Microsoft\UHF\is_active' ) && \Microsoft\UHF\is_active() ) : ?>
<?php \Microsoft\UHF\get_header(); ?>
<?php endif; ?>
<!-- put your header here, outside the conditional -->
Source: I wrote the plugin.