How To Use do_shortcode with WooCommerce One Page Checkout - php

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 like
add_filter( 'is_wcopc_checkout', '__return_true' );
There is no filter named is_wcopc_checkout in the code of WooCommerce one page checkout version 1.0.2
From 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 $templates array passed to your function.
For example, to register a custom pricing table template, the code would be similar to:
function eg_add_opc_template( $templates ) {
$templates['my-custom-pricing-table'] = array(
'label' => __( 'My Pricing Table', 'eg' ),
'description' => __( "Display a sophisticated and colourful pricing table with each product's attributes, but not weight or dimensions.", 'eg' ),
);
return $templates;
}
add_filter( 'wcopc_templates', 'eg_add_opc_template' ) );
The key used in the $templates array should be the template's file name (excluding the extension). The label element of the array is the name displayed on the One Page Checkout dialog. The description element is used for the tooltip next to the template's name.

Related

Wordpress Filtering Woocommerce Structured Data

I'm figuring out a filter but can't be figured :)
Just want to change PrimaryImageOfPage value with an og:image value in CollectionPage for Taxonomies.
It may be that I have to use woocommerce_structured_data_product to filter here and look for the image $markup['image'] = $image;
I have created some filters, but it isn't woocommerce_structured_data_product I guess.
One of them was like that but it... nah.
add_filter( 'woocommerce_structured_data_product', function( $markup ) {
$markup['image'] = ('rank_math/opengraph/{$network}/image');
return $markup;
});
What am I doing wrong? I have been doing this whole day -_-
If You inspect the code of the class WC_Structured_Data, You would see that woocommerce_structured_data_product filter is executed inside function generate_product_data
WC Complete Source of the class WC_Structured_Data : https://github.com/woocommerce/woocommerce/blob/b88b868ab8919b7c854173098b7d6d4ab227f9ee/includes/class-wc-structured-data.php
$this->set_data( apply_filters( 'woocommerce_structured_data_product', $markup, $product ) );
And generate_product_data function is executed on action woocommerce_single_product_summary
add_action( 'woocommerce_single_product_summary', array( $this, 'generate_product_data' ), 60 );
So, your code would work on product single page only and not archive/list pages, such as the taxonomy page.
The feature you want to achieve is not feasible out of the box in WC, You will need to customize yourself.
Logically, structured data on a single product page is feasible due to the fact there is only one product and product information is available, on the other hand, product list has more than one product (you might need to consider like you want to show details of first product) so it is ambiguous and not feasible out of the box for WC.

How can I add a custom button the messenger page in BuddyBoss?

There is a hook in buddyboss-platform/bp-templates/bp-nouveau/buddypress/common/js-templates/messages/parts/bp-message-form.php:33 called bp_nouveau_messages_hook( 'after', 'compose_content' ); which I want to access from my child theme in order to add some html. However, this hook doesn't behave like normal WordPress hooks and I cannot figure out how to access it.
The BP Nouveau template pack uses dynamic hooks.
bp_nouveau_messages_hook( 'after', 'compose_content' );
To use this hook you must include the component name ( messages ) between the stated pieces:
function test_nouveau_hook() {
echo '<br>additional content here';
}
add_action( 'bp_after_messages_compose_content', 'test_nouveau_hook' );

Turn custom Woocommerce shortcodes into php code for archive-product.php

Tl;dr: I want to use similar functionality in WC shortcodes but within the WC shop page.
I have many custom Woocommerce shortcodes I have created. I use them throughout non-shop pages.
E.g:
function displayProductIngredients($item) {
$product = wc_get_product($item['id']);
return $product->get_attribute( 'ingredients' );
}
add_shortcode('product_ingredients', 'displayProductIngredients');
I would like to use them in the archive-product.php page too.
E.g. in the example this shortcode adds the content of the "ingredients" attribute. How can the same be added for each new product added?
Is this just a case of moving around some of the php? If so, how might it look?
Thank you very much.

Add hidden meta data to product Woocommerce

I've added a custom field to my product for admin only meta data, I have hidden it using CSS.
However it still shows up in emails. Is there any way I can create a custom field where the meta data only shows up in the admin orders page?
You could try to use woocommerce_email_order_meta_fields filter hook to remove this custom field from order metadata, using unset() php function this way:
add_filter( 'woocommerce_email_order_meta_fields', 'wc_email_order_meta_remove_custom_field', 10, 3 );
function wc_email_order_meta_remove_custom_field( $fields, $sent_to_admin, $order ) {
// Replace HERE 'meta_key' by your custom field meta key or slug.
unset($fields['meta_key']);
return $fields;
}
This code goes in function.php file of your active child theme (or theme) or also in any plugin file.
This should work, but not sure as you don't provide any information and code related to the way you have set this custom field.

Wordpress - saving custom fields data of custom taxonomy

Forgive me if this answer is easily found in the Codex function reference. I have looked at the reference page for add_action( $hook, $function_to_add, $priority, $accepted_args ); but I have not been able to find the information I need.
What I have already:
I've created a custom field for my custom taxonomy of a custom post type. This custom field is added both to the "add new" and "edit" contexts (see image links):
http://screencast.com/t/CBmkyxrK
http://screencast.com/t/BQacL9AL3G
Yay, the creation part works!
What doesn't work:
Unfortunately, I'm only able to save media links that added using the "edit" context. Media links added using the "add new" quick create tool are not being saved.
Why it doesn't work
If I take a look at the example I followed to create my custom meta field (https://pippinsplugins.com/adding-custom-meta-fields-to-taxonomies/) you'll see that Pippin does not include a save action for the "add new" part, he only adds the field using add_action( 'category_add_form_fields', 'pippin_taxonomy_add_new_meta_field', 10, 2 );
I know that what I am missing is the WordPress specific syntax for saving actions in the "add new" context, and I know that it will be similar to the save action which is used for the "edit" context:
// add custom field to 'edit' and 'add new' contexts
add_action( 'affiche_edit_form_fields', 'affiche_taxonomy_custom_fields', 10, 2 );
add_action( 'affiche_add_form_fields', 'affiche_taxonomy_custom_fields', 10, 2 );
// save field input
add_action( 'edited_affiche', 'save_affiche_taxonomy_custom_fields', 10, 2 );
Reviewing the last line of the above code block, what is the equivalent string to 'edited_[taxonomy_name]' for adding new (not editing existing) custom taxonomy entries?
For adding new you need to use the create_{$taxonomy} hook
add_action( 'create_affiche', 'save_affiche_taxonomy_custom_fields', 10, 2 );

Categories