Woocommerce move notices on account login page - wordpress

Woocommerce outpuits a number of error/info notices on multiple pages. Normally this is handles by <? wc_print_notices() ?>, and so is nice and easy to reposition within a custom template. However, on the woocommerce account login page (form-login.php), there is no reference to <? wc_print_notices() ?> and therefore I cannot reposition. How are they automatically being output, and is there a way to overide them?

error, success and notice html file exist in templates/notices and include by some function, filter and action. for example woocommerce_before_customer_login_form action for login form.

Related

WordPress: adding or enabling user/customer registration? And making content only visible when logged in?

I currently have a very basic WordPress site with a few pages.
There are no user accounts, only my own admin account.
What I'm looking for:
A possibility for visitors to sign up i.e. register their own customer account. I don't need detailed account information, just an email address and perhaps a name and/or company name.
Restrict certain content to logged in visitors only. Preferably when someone is not logged in I would want the page to show 'this information is only accessible for customers - log in or sign up here'. And if someone is logged in, show the actual content.
Caveat: I'm dealing with a Woocommerce site and one of the things I'd like to restrict to logged in users only is the Shop page. But as I understood this is not a normal page with regular content in Wordpress. I guess its content is generated or controlled through the Woocommerce plugin. So is there a way to pull this off?
I'd assume this is a very common pattern in WordPress and this is probably very simple. But being a total WordPress newbie with zero experience, I wouldn't know how/where to start.
User Registration
Those are default WordPress behaviors. Enabling registration can be done via the admin control panel.
Settings → General → Membership, ✓ Anyone can register
Once this is done, users can registered # http://localhost/www/wordpress/wp-login.php?action=register
Conditional Tags
Conditional Tags can be used in your Template Files to alter the display of content depending on the conditions that the current page matches. They tell WordPress what code to display under specific conditions. Conditional Tags usually work with PHP if/else Conditional Statements.
Source # https://developer.wordpress.org/themes/basics/conditional-tags/
Restricting content to logged in user can be done via the is_user_logged_in() function.
Determines whether the current visitor is a logged in user.
For more information on this and similar theme functions, check out the Conditional Tags article in the Theme Developer Handbook.
Source # https://developer.wordpress.org/reference/functions/is_user_logged_in/
Use Case Scenario
<?php
if ( is_user_logged_in() ) {
// ... logged-in user content
} else {
// ... non-logged-in user content
};
WooCommerce Conditional Tags
You can use is_shop() to determine if the current page is a shop page.
Returns true when on the product archive page (shop).
Source # https://docs.woocommerce.com/document/conditional-tags/#section-4
Usually the shop page is built around the archive-product.php page template. the following should englobe the content from the archive-product.php page template. You don't have to specify is_shop as we're building the conditional statement on the archive-product.php page template.
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
};
/**
* Basic logged-in restricted `archive-product.php` page template example.
*/
get_header();
if ( is_user_logged_in() ) {
// ... logged-in user content
} else {
// ... non-logged-in user content
};
get_footer();
Template hierarchy
As you're new to WordPress you should try to understand the basics in term of template hierarchy. You should refer to https://developer.wordpress.org/themes/basics/template-hierarchy/. WooCommerce works the same.

how to display single product do_action in shop Page in Woocommerce

Is there any method available to display single product woocommerce_before_single_product_summary action woocommerce shop page
Yes. There are a couple ways to do this, depending on what you're actually trying to achieve:
You can override the WooCommerce shop page template (archive-product.php) in your theme (or hopefully child theme) to do the woocommerce_before_single_product_summary action
You can add the functionality you're looking for that's currently hooked into the woocommerce_before_single_product_summary action to an action that fires on the Shop page
You can create a function that will do the woocommerce_before_single_product_summary action, and hook that into an action on the Shop page (similar to option 1, but doesn't override the Shop template - in theory, preventing more work in future if/when WooCommerce updates their templates)
How to do it
Create a folder in your theme/child theme called woocommerce and copy plugins/woocommerce/templates/content-product.php to it and figure out where you want to put the woocommerce_before_single_product_summary action. Making sure you're within the <?php ?> tags, pop this is where you want: do_action( 'woocommerce_before_single_product_summary' );
Find the specific function that does what you're looking for, and add it to an action that's already firing on the Shop page. In the functions.php file of your theme/child theme, (please use a child theme), add this within the <?php ?> tags:
add_action( 'woocommerce_before_shop_loop_item', 'specific_function_you_want' );
where 'woocommerce_before_shop_loop_item' is the first action that fires on the Shop page (you can swap out for another action in content-product.php depending on where you want to put the functionality, and 'specific_function_you_want' is the name of the function currently hooked into the woocommerce_before_single_product_summary action that you're looking to replicate.
Again, within the <?php ?> tags in your functions.php file add the following:
add_action( 'woocommerce_before_shop_loop_item', 'do_before_product_summary');
function do_before_product_summary() {
do_action('woocommerce_before_single_product_summary');
}
Pros/Cons
Easiest and fastest way to do what the question asks; however: note that by default, woocommerce_before_single_product_summary only does two things: display the product image & say if the item is on sale. Both of these are already being shown on the Shop page. Since this method just does the woocommerce_before_single_product_summary action, you'll most likely have duplicated content on the Shop page. Probably not the best way to go about this.
Gives you the most granularity. I'm making the assumption that you're probably looking to get some specific functionality that is currently hooked to the woocommerce_before_single_product_summary action, and do that on the Shop page. If that is the case, this method will allow you do that, without having to worry about any other functionality that's attached to the woocommerce_before_single_product_summary action (like duplicated product image as mentioned in method 1). However, you will need to find out where that specific functionality is coming from, which will require a bit of digging.
Doesn't require the digging required in method 2, but as with method 1, will do everything that's hooked into the woocommerce_before_single_product_summary action. The big benefit to using this over method 1 is that when/if WooCommerce updates their templates in the future (as they do from time to time), you won't need to worry about keeping your template override up to date with theirs. This isn't always a big deal, but it is something to keep in mind.

Can Shortcodes be used in a Static WordPress Homepage?

I have a Static page set as the home page of my wordpress website. It has a custom shortcode to show a woocommerce catalog based on my own meta query.
When I add valid products, it does not show up immediately or even after a while. However, if I publish the static page, then it shows up magically, thus leading to my question.
What are my alternatives, if I want to show my shortcode on a static home page?
I think this is my problem and nothing else, because I tried disabling all plugins and clearing the cache, but still it did not show the latest added products.
You can edit the template of your theme adding the do_shortcode() function where you want the shortcode to be displayed, for example:
<?php echo do_shortcode( '[contact-form-7 id="91" title="quote"]' ); ?>

Wordpress Form Submit button GETS (or POSTS) form data to external page

We have a wordpress website that does marketing display, but now we want to allow a customer to submit an email and selection to a separate website with a landing page that will handle the backend DB work and finish them in the other website.
Something like,
www.ourmarket.com/getdata (on Submit button click GETS to...)
www.ouradminsite/landingpage.aspx (which processes the data that the use will not see then...)
www.ouradminsite/login.aspx (where the user can now login)
I am not familiar with WP at all, but I was able to create a page with a form that has the textbox/combobox I need.
I thought it would be something simple, but somehow it seems not. I read about AJAX and doing something in functions.php and creating a custom .js file, but when working on the marketing site I find no way to add this type of function in.
My fall back is to have the WP page just have a link to a generic landing page where they enter data, but it would be visually jarring to the customer unless I duplicate the WP site for one page.
Is there an easy way to just tell WP to redirect to an external page with a GET?
UPDATE--------------
I like to think I'm making progress. I found a link that may have given me a good start. I added a function to the functions.php file located in my WP theme. It starts like this:
add_action("gform_post_submission_4", "set_post_content", 10, 2);
function set_post_content($entry, $form){
//Gravity Forms has validated the data
//Our Custom Form Submitted via PHP will go here
// Lets get the IDs of the relevant fields and prepare an email message
$message = print_r($entry, true);
// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70);
// Send
mail('myuser#mycompany.com', 'Getting the Gravity Form Field IDs', $message);
**wp_redirect("http://my.hearbuilder.com/hellomoto.aspx",301);**
}
From there I tried to edit the function to do that wp_redirect, just a simple one to start. This is added under the mail statement:
wp_redirect("http://my.hearbuilder.com/hellomoto.aspx",301);
From this link, when I fill out the form I can get the email, but the new page did not display. I added the exit; line and still got the same result, the page seems like it hangs.
The end result is that I need to have the new website landing page display (after it processes the data from the Wordpress form.
What am I still missing?
yes use wp_redirect()
if($_POST):
$textbox=$_POST['textboxname'];
$url= 'url'.'?custom=hello&textbox='.$textbox.'&anothervalue='.$anothervalue;
wp_redirect($url);
exit;
endif;
you can easily add the variables to the string as needed. The easiest way to control the url properly is to post the information to the same page , catch the post and redirect (place before get_header call or any output has started)
The other way is php Curl which is more difficult esp when dealing with .asp pages, but if you have access to the other server it makes figuring it out easier!

Load a page through ajax with Wordpress using different template

After the user clicks a link, I want to load the corresponding page within the currentpage. This ajaxpage should be themed differently than it's non-ajax page.
The pages would be added by the client in different languages. So there is no fixed id's and the client shouldnt add the same article twice (1 for normal and 1 for ajax). This rules manually overwriting templates out.
The first part, ajax loading of content is easy to do, but I don't know how to display content in different ways.
So
domain.com/product/car direct visit shows a product (car) using single-product.php as template which includes a header and footer.
ajax loading domain.com/product/car would show a product (car) but without a header and footer and perhaps some small layout changes.
My initial thought would be setting some template dynamicly (template-product-ajax.php) but Im not sure if this is possible or how.
In short, how can I create a different template/layout/view when loading a page with ajax in wordpress
You would have to pass in a series of variables, including the page/post ID you want to load, what kind of object you're trying to load (either 'page' or 'post') and a boolean to ensure that the standard get_header() function isn't loaded (as you only want the content of the page, not the headers).
Somewhere within the template, you can use that boolean to determine the template's behavior. For example:
<?php
/*Template Name: AJAX Content*/
if(!isset($_POST['bool']))
get_header();
?>
<div id="body">
<div class="page_content">
<?php
if(isset($_POST['bool']))
{
$object = $_POST['ob_type'] == 'page' ? get_page($_POST['PID']) : get_post($_POST['PID']);
echo $object->post_content;
/*echo '<pre>';var_dump($object);echo '</pre>';//Uncomment this section if you want to know what you can access with variable $object*/
{
else
{
//STANDARD LOOP
}
?>
</div>
</div>
This is untested, but it should help get you started if you're already familiar with AJAX calls and sending POST data to a separate page.

Resources