ClintonLee83
Forum Replies Created
-
Forum: Themes and Templates
In reply to: Apply function to specific page templateI can add:
add_filter ('add_to_cart_redirect', 'redirect_to_checkout'); function redirect_to_checkout() { global $woocommerce; $checkout_url = $woocommerce->cart->get_checkout_url(); return $checkout_url; }
directly into the landing-page.php template, correct? Wouldn’t this solve the problem? I’m just not sure how to add the code into the template, I’ve tried adding it and I’m getting errors.
Here’s the template, how can I add the filter directly into this?
<?php /* Template Name: Landing Page */ ?> <?php get_header ( "landing" ); ?> <div id="primary" class="content-area"> <main id="main" class="site-main" role="main"> <?php while ( have_posts() ) : the_post(); do_action( 'storefront_page_before' ); get_template_part( 'content', 'page' ); /** * Functions hooked in to storefront_page_after action * * @hooked storefront_display_comments - 10 */ do_action( 'storefront_page_after' ); endwhile; // End of the loop. ?> </main><!-- #main --> </div><!-- #primary --> <?php get_footer();
Forum: Hacks
In reply to: Apply add:filter to a specific page templateHi there bcworkz,
Thanks for the reply! I appreciate your help.
Yes, I opened up a brand new thread about this problem a few days before I posted here:
https://www.ads-software.com/support/topic/apply-function-to-specific-page-template?replies=2#post-8449648I wasn’t getting anywhere there so I wanted to try my luck here, then update that thread once solved.
I think your solution sounds like a much better way of doing it and is an alternative solution to the subject of this thread.
When I put the code at the top of the template, I’m getting errors. I’m not so great with php.
Can you show me how to add this code
<?php add_filter ('woocommerce_add_to_cart_redirect', 'redirect_to_checkout'); function redirect_to_checkout() { global $woocommerce; $checkout_url = $woocommerce->cart->get_checkout_url(); return $checkout_url; } ?>
to this template?
<?php /* Template Name: Landing Page */ ?> <?php get_header ( "landing" ); ?> <div id="primary" class="content-area"> <main id="main" class="site-main" role="main"> <?php while ( have_posts() ) : the_post(); do_action( 'storefront_page_before' ); get_template_part( 'content', 'page' ); /** * Functions hooked in to storefront_page_after action * * @hooked storefront_display_comments - 10 */ do_action( 'storefront_page_after' ); endwhile; // End of the loop. ?> </main><!-- #main --> </div><!-- #primary --> <?php get_footer();
Forum: Hacks
In reply to: Apply add:filter to a specific page templateI’m using the code that Craig posted above but tried to modify it for the template and filter I’m using, but it’s not working for me, see the code below.
(the function will take the woocommerce user straight to the checkout page after clicking “add to cart” , this should only work on the landing-page.php template)
function checkPageTemplate(){ $currentPost = get_post(); $pageTemplate = get_post_meta( $currentPost->ID, '_wp_page_template', true ); if ( $pageTemplate == "landing-page.php") { add_filter ('woocommerce_add_to_cart_redirect', 'redirect_to_checkout'); } } add_action( 'the_post', 'checkPageTemplate' ); function redirect_to_checkout() { global $woocommerce; $checkout_url = $woocommerce->cart->get_checkout_url(); return $checkout_url; }
Is there something wrong with this code?
Forum: Themes and Templates
In reply to: Apply function to specific page templateI’ve just replaced my code with yours in the child theme’s functions, it’s still not working…
Your ‘f’ got cut off from ‘function’ at the top of your code, I fixed it when I added it.
function checkPageTemplate(){ $currentPost = get_post(); $pageTemplate = get_post_meta( $currentPost->ID, '_wp_page_template', true ); if ( $pageTemplate == "landing-page.php") { add_filter ('woocommerce_add_to_cart_redirect', 'redirect_to_checkout'); } } add_action( 'the_post', 'checkPageTemplate' ); function redirect_to_checkout() { global $woocommerce; $checkout_url = $woocommerce->cart->get_checkout_url(); return $checkout_url; }
Here’s the original sources I’m using to figure this out:
https://www.remicorson.com/woocommerce-skip-product-cart-pages/
https://www.ads-software.com/support/topic/apply-addfilter-to-a-specific-page-template?replies=7Forum: Themes and Templates
In reply to: Apply function to specific page templateThanks Creativepaddy,
I’m terrible with this stuff, can you show me how to make a filter hook?
I’ve been searching for an answer to this and came across a post that provided this solution:
function checkPageTemplate(){ $currentPost = get_post(); $pageTemplate = get_post_meta( $currentPost->ID, '_wp_page_template', true ); if ( $pageTemplate == "landing-page.php") { add_filter ('add_to_cart_redirect', 'redirect_to_checkout'); } } add_action( 'the_post', 'checkPageTemplate' ); function redirect_to_checkout() { global $woocommerce; $checkout_url = $woocommerce->cart->get_checkout_url(); return $checkout_url; }
But it’s still not working
other solution is that get the page slug for the page you using this Template and then check for condition and apply filter
I need this to work on all of the pages I use the template on, not just one. Would I have to add a page slug to this function for each page I create and want to use this on? If that’s the case, I’d rather find a solution that doesn’t require me to mess with the code because this is for someone who knows nothing about code.
Forum: Themes and Templates
In reply to: Apply function to specific page templateHi there,
Yes, as I mentioned above, the landing-page.php is directly inside the child theme folder.
Do I need to make a subdirectory? I’m able to select this template from the page editor inside wordpress and it shows up fine.
The only problem is that I’m unable to apply the function (redirect straight to checkout using an add to cart button) on this template only.
Forum: Plugins
In reply to: [WooCommerce] Reverse Menu OrderThat worked
Thank you so much Mike!
Forum: Plugins
In reply to: [WooCommerce] Reverse Menu OrderUpdate:
On the product page, the menu order is ascending, but when I add the shortcode to the homepage:
[featured_products per_page=”12″ columns=”4″ orderby=”menu_order”]
the menu order is descending… Why would this happen?
Forum: Plugins
In reply to: [WooCommerce] Sku not showing on some productsAh ha, I got it.
I’ve removed:
if ( ! $post->post_excerpt ) {
return;
}I’ve got these in the short-description.php template.
I was using a csv to edit these and I had the pn in the post_exerpt column in the csv. I moved them over into a custom column which left the post_exerpt blank.
I appreciate the help guys!
I’ve managed to figure out the problem. The .csv format that open office saved the sheet wasn’t working with the plugin. Simply saving as .xls then uploading the .xls worked.
Forum: Plugins
In reply to: [WooCommerce] Change Cart Layout With Cross SellsI’m also trying to adjust the layout of cross sells relative to the cart totals. Right now, the totals are on the left and the cross sells are directly below the totals.
I want to display the cross sells next to the totals box. Totals on the left and cross sells on the right.
I added:
// remove cross-sells from their normal place remove_action( 'woocommerce_cart_collaterals', 'woocommerce_cross_sell_display' ); // add them back in further up the page add_action ('woocommerce_after_cart_totals', 'woocommerce_cross_sell_display' );
To the functions but it’s only adding the cross sells to the same spot as where they were previously.
How can I get the cross sells to show up next to the totals?
Forum: Plugins
In reply to: [WP Responsive header image slider] Images stacked, slider not workingI’ve created a test page so we can troubleshoot this while I keep my home page looking clean. Here is the new link:
Forum: Plugins
In reply to: [WooCommerce] Some images cropped largeGood deal that’s all it took. It’s working now after unchecking “hard crop” for Catalog and single product images.
Simple stuff, thank you Joh… Mike! ??
Forum: Plugins
In reply to: [WooCommerce] Some images cropped largeWhoops, I meant Mike!
I’m sorry, I was probably talking to John when I wrote that.
That’s probably going to do it, I’m regenerating the thumbnails now. I’ll let you know when they’re done. I appreciate your help Mike!
Forum: Plugins
In reply to: [WooCommerce] Some images cropped largeHi there John!
The theme we’re using, Flatsome comes with the zoom script. I don’t think it’s the zoom, if you inspect the images that are too big and follow the image source, you can see the images are actually huge and cropped. That’s how they were saved.
When you use the zoom feature to inspect the image, the real zoomed image is not cropped.
I’m wondering if this is an error from the Regenerate Thumbnails Plugin. I can’t find any references of anyone else having this problem in this plugins forums.