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.
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 am wondering if there is a way of doing something similar to <?php get_template_part(); ?> in the functions.php file – I am specifically hoping to target Woocommerce with this code.
Most of my website's pages use the following code from my default template – page.php
<?php get_header(); ?>
<?php get_template_part('includes/side-menu'); ?>
<div class="content">
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
<?php endif; ?>
</div>
<?php get_footer(); ?>
I have set up my theme (custom built) for use with the Woocommerce plugin, but I'm having an issue with a side-menu in my theme that is in a separate folder from my header and footer. Woocommerce uses its own templates to generate its pages, i.e. the product archive and product pages etc. Each of these templates call my theme's header and footer by default, but they don't call my menu, so when I press the button to open it on one of those pages, it isn't there.
I have set up Woocommerce to be compatible with my theme using the method recommended by the plugin authors. I have added the following code to my functions.php
remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10);
remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10);
add_action('woocommerce_before_main_content', 'my_theme_wrapper_start', 10);
add_action('woocommerce_after_main_content', 'my_theme_wrapper_end', 10);
function my_theme_wrapper_start() {
echo '<div id="woocommerce-content" class="content"> <div class="container">';
}
function my_theme_wrapper_end() {
echo '</div> </div>';
}
This code allows me to add a div to the Woocommerce templates to wrap my content. I am wondering if there is a way of changing this code so I can call in my menu template side-menu.php on Woocommerce template pages.
There is another way of doing this, but I am trying to avoid using it because it involves a lot more work in the long term. It is possible to override the plugin template files by copying them into a folder within my theme, and adding the <?php get_template_part(); ?> code to call my side-menu.
The only problem with this is that it means that with every significant update to the plugin, I have to update these override files to include new code released with Woocommerce updates, because it doesn't update them automatically.
If there is any way of calling the side-menu as a blanket action throughout Woocommerce pages in the same way that the code above adds the HTML, that would be a much easier solution.
I'm interested to hear if this is possible.
As I understand by default Woocommerce shop page uses product archive template. What I am looking for, is to use a custom template for shop page.
Here is what I did:
Create template "my-shop"
Create page "My shop" -> choose template "my-shop"
Choose "My shop" as Woocommerce shop page
But none of the changes I made to "my-shop" template are present on the shop page.
What am I missing here? I would not like to change product archive itself, just the shop page.
Is there a way to disable product archive from being a default for shop page?
Thanks
I know it's too late and you may have figured it out by now. In any case, the changes that you would like to make to the WooCommerce Shop Page need to be done in the archive-product.php and it would be safer to create a child theme and do these changes. Making enhancements and customizations in a Child theme is best practice so that you can update the parent theme at any time and it won't affect your store.
I hope this helps, for more information on how you can use WooCommerce short-codes to customize your store can be found here.
To add to Silver Ringvee's answer - he used is_page but that only works on wordpress pages. For woocommerce you need to use something like is_woocommerce() . See Woocommerce conditional tags page.
My example code uses the is_shop conditional tag as that was the page you wanted to change. the code get_template_part( 'content', 'shop' ); will call the file content-shop.php in your theme root folder. This code is to be added at the top of wp-content\themes\*theme*\woocommerce\archive-product.php that you can copy from wp-content\plugins\woocommerce\templates\archive-product.php
You can add it just before get_header( 'shop' ); line 23 in my file - and the entire page will be drawn from your template. If you want to keep the header of the shop page, then put this code after the get_header code. Remember to include a footer in your file as well
if (is_shop()) {
get_template_part( 'content', 'shop' );
} else {
#normal archive-product code here
}
The solution (not perfect) that I figured to work best, until someone finds a way to actually change the template from dashboard:
Adding:
<?php
if (is_page( 'Page Title' ) ):
# Do your stuff
endif;
?>
to content-product.php in my theme's woocommerce folder.
If you prefer to go with code, you can create a redirect from the original shop page to your page via wp_redirect.
add_action('template_redirect', 'bc_010101_redirect_woo_pages');
function bc_010101_redirect_woo_pages()
{
if (is_shop())
{
wp_redirect('your_shop_url_here');
exit;
}
}
More detailed tutorial can be found here
This is not possible to create custom template for shop page , just copy and paste woocommerce Templates into you theme folder and Try to work in content-product.php template .
I'm using WordPress to build a simple personal website. I know (basic) HTML and CSS but no PHP, so I'm having a little trouble with a particular customization.
My theme inserts the title of the page at the top of the page. I would like to stop it from doing this on one page only (the home page).
Thanks for any help. The site is here: http://www.melvingauci.com/
Try going into your page.php template and remove <?php the_title(); ?>. Then add this:
<?php if ( ! is_front_page() ) { ?>
<?php the_title(); ?>
<?php } ?>
Note: This assumes your home page uses the page.php template. If another template is used, then the same approach will work.
I'm trying to make my woocommerce cart template display as a full 12 column layout.
The existing layout is using bootstrap's col-sm-8 column. I need to change it to col-sm-12.
<main class="main col-sm-8" role="main">
<div class="page-header">
<h1>Cart</h1>
</div>
<div class="woocommerce">...</div>
<div class="woocommerce-info">...</div>
<div class="cart-collaterals">
// shipping code etc.
</div>
</main>
I checked out the relevant woo-templates shown here, and copied the cart.php template into my theme to override. However, it looks like I need to modify the woocommerce_before_cart action to change the <main> layout and insert the col-sm-12 class. I found the relevant actions on this woocommerce page.
I can see from the cart.php template the action called before the <form> element as shown below:
global $woocommerce;
wc_print_notices();
do_action( 'woocommerce_before_cart' ); ?>
<form action="<?php echo esc_url( WC()->cart->get_cart_url() ); ?>" method="post">
<?php do_action( 'woocommerce_before_cart_table' ); ?>
<table class="shop_table cart" cellspacing="0">enter code here
I'm new to php, my question is how do I modify the output of this action so I can change the layout to 12 columns?
Woocommerce inserts the content in cart.php into page.php in the root of your theme. :)
Doesn't look like woocommerce creates action hooks for 'woocommerce_before_cart' or 'woocommerce_before_cart_table', you can check this with has_action(). They seem to be there as suggestions for developers to extend upon. Should be right to remove them from cart.php (although developers might have them there for future releases or popular plugins) or if you want to use them add this to your themes functions.php.
add_action('woocommerce_before_cart', 'sample', 1);
function sample() {
echo '<h1>hello</h1>';
}
EDIT:
Just read your response to the previous answer, looks like that theme you're using might be creating the hook in its functions.php file, look for
add_action('woo_commerce_before_cart', 'sample', X);
'sample' is the name of the function that is called and X is its priority. You can either modify the output of that function or add another function to the hook.
For anyone who works with child theme, please note that sometimes your parent theme already override the cart.php template, especially heavily customised like Themeforest products. So don't copy the original cart.php from Woocommerce, copy it from the parent theme template.