Woocommerce Multiple Checkout Pages - php

rSo I have been banging my head against my computer trying to figure out how to get this to work and am wondering if this is possible (well anything is possible with a bit of work).
My end goal is to have more than one page that holds the Woocommerce checkout form so that I can have a page for a custom one-page subscription checkout.
This works fine when I set the checkout form to be this page via the settings panel but if not set to this page it will not load the form with the proper scripts and is unable to perform ajax requests to update shipping etc, thus being restrictive to one page per working checkout form.
Steps taken:
So far I have tried bringing the form using the following :
<?php echo do_shortcode('[woocommerce_checkout]'); ?>
Through the Page's WYSIWYG (not a solution in my case eithey way)
And Manually building the form via the provided functions
<div class="checkout">
<div class="col2-set" id="customer_details">
<div class="col-1">
<?php echo $woocommerce->checkout->checkout_form_shipping() ?>
</div>
<div class="col-2">
<?php echo $woocommerce->checkout->checkout_form_billing()?>
</div>
</div>
<h3 id="order_review_heading">Your order</h3>
<div id="order_review" style="zoom: 1; position: relative;">
<?php echo wc_get_template( "checkout/review-order.php", array( "checkout" => WC()->checkout() ) ) ?>
</div>
All of these steps brought in the form but with the script/ajax errors. Please if anyone has accomplished this in the past I would love to hear what it takes. Suggestions are always welcome too! Thanks in advanced :)

I had the same problem, I fixed it by using this at the top of my custom checkout page:
if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) {
define( 'WOOCOMMERCE_CHECKOUT', true );
}

Related

how link several pages, and adding a plugin to a new custom WordPress theme

I've created my own WordPress custom theme for a website that I'm working on. It's my first time building a theme from scratch! I'm having a difficulty 1st: to link several pages to the fron-page, or home page. For example lets say that I want to link "Who we are", page + "Contact us", page, etc.. How can I make WordPress understands that each page is different, and link to it? here is what I did so far:
in page.php I placed this code:
<?php get_header(); ?>
<div class="container">
<?php
if (have_post()) {
while(have_post()) {
the_post();
get_template_part( 'template-parts/content', 'page');
}}
?>
</div>
<?php get_footer(); ?>
I also created a content-page.php where I've placed my HTML code. (I'm building the whole thing with an HTML and CSS code that's just like building a website from scratch).
I also want to know when using a plugin, how can I connect that into the pages that I'm adding. For example, if I'm installing a form such as WpForms for a page like "Contact us" how can I link that?
Please let me know if my questions need more details
If I understand this correctly...
You want to be able to display (link) a couple of pages to your home page?
Ex:
[home page content here]
[Connect page content here] [Blurb page here]
If so, you need to pull in the page content into the home page.
Something like:
<?php
$postid = 0 /*Need to get page id, that's the key */;
//Pull in the page data
$featured_page = get_post($postid);
$thumbnail = get_the_post_thumbnail( $featured_page->ID );
//Only show the excerpt in this case
$content = apply_filters( 'the_content', $featured_page->post_excerpt );
?>
<article id="post-<?php echo $featured_page->ID ?>">
<header class="entry-header">
<h1><?php echo $featured_page->post_title ?></h1>
</header>
<div class="entry-content">
<div class="thumbnail">
<?php echo $thumbnail; ?>
</div>
<div>
<?php echo $content; ?>
</div>
</div>
Important! You'll need to get the page id from somewhere. You can hard-code it in, but that's risky if something changes. You can set up an Customizer option that lets the user select what page to use.
https://codex.wordpress.org/Theme_Customization_API
As for the contact form etc. I'd suggest putting it on a page as a shortcode, then displaying the full page, not the excerpt.
I use this code for a theme I built myself. If you need anymore help, let me know, I can show you where to find it.

$variable = get_post_meta not working as expected

This is my first post on stackoverflow, as I am quite new to PHP. I am learning the language to help me customize my online portfolio in Wordpress, and I usually manage to make the changes I need - but not this time, apparently.
I am trying to use get_post_meta to read a meta tag in my portfolio pages, and avoid displaying the page thumbnail. This is the code I am using:
<?php $disable_thumb = get_post_meta( get_the_ID(), 'minimal_portfolio_page_thumb', true );
if( $disable_thumb !== 'on' ): ?>
<?php if ( has_post_thumbnail() ) : ?>
<div class="post-thumbnail">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<?php the_post_thumbnail(); ?>
</a>
</div>
<?php endif; ?>
<?php endif; ?>
Using a meta tag management plugin, I added the following tag to all my "portfolio"-type pages:
<meta name="minimal_portfolio_page_thumb" content="on">
I am currently checking if this works in this page of my web: egozalor.com/portfolio/hansel-gretel/
Long story short, the trick does not work as expected. I guess there is something I am doing wrong or not realizing, due to my little knowledge of PHP. Any indications, tips or recommendations are very welcome!
Also please let me know if further or more specific information is necessary to assess my issue.
Thanks in advance!
The function get_post_meta has nothing to do with the <meta> elements of your site. With this function you can only get metadata of the post itself. You can set the metadata on each post at the end (custom fields) as key / value pairs.
These custom fields are not visible on the site itself. You can create a custom field on every post with key minimal_portfolio_page_thumb and value on (or another value like 0/1).
Looks like the custom fields are disabled by default on WordPress. But you can enable the custom fields without an additional plugin. On the top right of your post you can find three dots to open a menu. At the end of the menu there is the entry "Options". On the options you can enable the custom fields.
You can enable the custom fields for posts and pages.

Woocommerce archive-product.php overwrite issues.

I'm trying to customize the archive-product page, and it works perfectly while I'm on my local server, but when I move it online, it's switches back to the default template. I'm trying to fix this for a week now, I've read all the other answers regarding this issue, but most of them are for an older version of woocommerce or the solution just doesn't work.
As a last refugee from madness, I've deleted all the archive-product.php file I can find, even the one in the woocommerce source folder, but nothing changed, I don't know where the site is getting the template from. The page have become self aware and I am going crazy because I have no idea what to do next.
Here is the difference between the page on local and online server
Please check if you have this in your functions.php, if not add:
add_theme_support( 'woocommerce' );
In theme root folder, add the file woocommerce.php and in that file set your own layout. For example:
<div class="wrapper">
<div class="sidebar">
// sidebar
</div>
<div class="inner">
<?php if ( have_posts() ) :
while(have_posts()) : the_post();
<?php woocommerce_content(); ?>
<?php
endwhile;
endif;?>
</div>
</div>
For more details: go through https://docs.woothemes.com/document/third-party-custom-theme-compatibility/

<?php woocommerce_cart_totals(); ?> is somehow displaying twice

Woocommerce shopping cart page is acting very strange.
I just updated my theme ( X | Theme v3.2.5 ) and woocommerce ( v2.3.8 )
So I am running the most current versions.
For some reason, since the update my cart totals are now displaying twice on my cart page.
I have two subtotal columns, two proceed to checkout buttons, two empty cart buttons, etc.
When I look at the HTML, it's literally duplicated.
<div class="cart-collaterals">
<div class="cart_totals ">
<div class="cart_totals ">
</div>
Obviously cart_totals has more HTML underneath, but you get the idea.
On the actual cart.php page I can locate this php:
<?php woocommerce_cart_totals(); ?>
only one time. Here is all the markup from the cart.php page:
<div class="cart-collaterals">
<?php do_action( 'woocommerce_cart_collaterals' ); ?>
<?php woocommerce_cart_totals(); ?>
</div>
<?php do_action( 'woocommerce_after_cart' ); ?>
Is there any way to ensure that this php is only being ran one time?
I might try to just limit the height of the CSS container, but that's not the right fix...
In their latest update, they must have moved the cart total to the woocommerce_cart_collaterals, which means it is now printed once in this action, and once in your code.
I had the same problem with TM Extra Options plugin on Themeforest. In the plugin remove <?php woocommerce_cart_totals(); ?> in the templates/cart/cart.php file (it's at the bottom) and you will remove duplicate "Cart Totals". Hope this helps someone.

wordpress custom theme search has quantity but displays no results

Trying my best to wrap my head around wordpress search process and results.
Been reading and researching online for about 8 hours straight at this stage and have gotten almost nowhere.
I have a completely custom theme, designed by a friend for a client. I have a search box in a nav bar at the top of the page, inside the header. I'd like the user to be able to search the site's content from that search box in the nav bar at any time. I've found plenty of examples of this being accomplished on other pages, though they often seem to be using a ready-made theme.
Eventually I'd like to be able to understand what's going in the search.php file well enough to edit it along with the searchform.php file so that the search box and results appear unified with the rest of the theme.
At the moment the closest I've gotten to having anything functioning at all is the inclusion of a quantity of search results showing the appropriate number of hits expected, but I still can not figure out how to display a result.
I've been combing through others' page sources and every hit I can google about customising or just explaining the search.php file, and yet all I keep finding is "read the Creating a Search Page" and "it must be a theme issue." This is not gainful information.
My understanding of what's being taught in the "Creating a Search Page" info is that it describes the steps for creating a custom search page that one can hyperlink / permalink to, but which is unrelated to the default search function within the wordpress kit. Indeed, I've successfully created a custom search page, but it behaves simply as a stand-alone page, and is not related to a customised search results page. To customise the look of default search function results, I understand the search.php file must be edited. So far the "what to edit" within that file escapes me, but for now I'd just like to understand why I am seeing the correct number of results, but no actual results.
My search.php file looks like this:
<?php get_header(); ?>
THIS IS THE TOP OF SEARCH.PHP
<section id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<?php if ( have_posts() ) : ?>
<header class="page-header">
<h1 class="search-title">
<?php echo $wp_query->found_posts; ?> <?php _e( 'Search Results Found For', 'locale' ); ?>: "<?php the_search_query(); ?>"
</h1>
</header><!-- .page-header -->
<?php
// Start the Loop.
while ( have_posts() ) : the_post();
/*
* Include the post format-specific template for the content. If you want to
* use this in a child theme, then include a file called called content-___.php
* (where ___ is the post format) and that will be used instead.
*/
get_template_part( 'content', get_post_format() );
endwhile;
/*
// Previous/next post navigation.
twentyfourteen_paging_nav();*/
else :
// If no content, include the "No posts found" template.
get_template_part( 'content', 'none' );
endif;
?>
</div><!-- #content -->
</section><!-- #primary -->
THIS IS AFTER THE SECTION OF SEARCH.PHP
<?php
// get_sidebar( 'content' );
// get_sidebar();
get_footer();
*Note: The notes in CAPS are to help me understand what content is coming from where as I try to figure out what each phpiece of the puzzle is doing.
Also, the twentyfourteen_paging_nav line is commented out as it kept spitting back an error. The original search.php was from a (default theme?) folder called "twentyfourteen". My current folder is called "ewgi2014" however, replacing twentyfourteen_paging_nav with ewgi2014_paging_nav spat back the same error, and I can't find any more useful information on the topic. Also, when looking at other sample search.php files I didn't see the paging_nav call, so I tried commenting it out, and was able to at least avoid the error, though I still don't understand it.
Sample output on the page after searching for the term, say, "program" is:
8 Search Results Found For: "program"
...with nothing else written beyond that.
Not entirely relevant, I believe, but my searchform.php looks like this:
<form role="search" method="get" class="search-form" action="<?php echo home_url( '/' ); ?>">
<label>
<input type="search" class="search-field" placeholder="search …" value="" name="s" title="Search for:" />
</label>
<input type="submit" class="search-submit" value="Search" />
</form>
I've read and re-read the "Creating a Search Page" page from the Codex so many times I could probably recite it by heart, but haven't found any solutions within.
I've read the stackoverflow hit about "How to display Wordpress search results?" and have tried the code from ThemeShaper, but that throws an error on the shape_content_nav line(s).
I've read this and ... and apparently I can't link to all the other things I've read as this is my first post, but I have been reading a lot, and fiddling, and making very little headway.
Apologies for the long-winded post. Just trying to be thorough and show my research and current point of understanding.
What happens if you put
the_title();
Directly after your while statement?
Each time you loop within the while loop, you are processing each post. Currently, on each loop, you are entering a content-*.php file, where * depends on the post format. Does that file exist?

Categories