I'm trying to use the WordPress do_shortcode function for the WooCommerce One Page Checkout Plugin which uses shortcode like this: [woocommerce_one_page_checkout template="product-table" product_ids="product, ids, here"]. It seems like I can only use this shortcode IF it's in the content editor and won't allow me to add this to a page template using the do_shortcode function.
Their documentation here says:
If you wish to display the One Page Checkout Shortcode using WordPress’ do_shortcode() function instead of including the shortcode in a post or page’s content, you will also need to attach custom code to the 'is_wcopc_checkout' filter and make sure a boolean true value is returned.
So I tried adding the following to the functions.php file:
add_filter( 'is_wcopc_checkout', function(){ return true; } );
and it didn't seem to do the trick.
I also tried:
add_filter( 'is_wcopc_checkout', 'my_one_page_checkout' );
function my_one_page_checkout(){
return true;
}
add_filter( 'is_wcopc_checkout', 'true' );
That didn't seem to do it either.
Am I adding this code to the functions.php wrong? Any help on how I can get the One Page Checkout Plugin to work using do_shortcode?
Here's my full code in the page template for reference:
<?php
echo do_shortcode('[woocommerce_one_page_checkout template="product-table" product_ids="62, 122, 438, 52, 433, 435, 512, 514"]');
?>
Thanks for your help.
(I tried contacting WooCommerce support and they were no help saying that this is custom code and they can't do anything to help.)
The simplest way to return a true to a filter is like sitting the call back to WP default
__return_true. So the function will be likeThere is no filter named
is_wcopc_checkoutin the code of WooCommerce one page checkout version 1.0.2From their doc- You can also manually add a shortcode
[woocommerce_one_page_checkout]to any page or post and use the shortcode's attributes.Usage:
[woocommerce_one_page_checkout product_ids="30,45,12"]Some context from One page checkout readme.
To register your template, attach a callback to the
'wcopc_templates'filter and add a new array of your template's details to the$templatesarray passed to your function.For example, to register a custom pricing table template, the code would be similar to:
The key used in the
$templatesarray should be the template's file name (excluding the extension). Thelabelelement of the array is the name displayed on the One Page Checkout dialog. Thedescriptionelement is used for the tooltip next to the template's name.