Could you show me how you modified the template?
Do you remember to write do_shortcode( ‘[broadcasted_from]’ ); ?
Thread Starter
sjanej
(@sjanej)
Hi thanks for the reply.
I have placed the following code into my main stores child theme content-product.php do_action( ‘woocommerce_shop_loop_item_title’ );
do_shortcode( ‘broadcasted_from’ );
If I add do_shortcode( ‘[broadcasted_from]’ ); then the shop page returns a blank page
I have placed the following code into my main stores child theme functions.php
/* Using the Broadcast plugin but wanted to add the name of the parent store on the product on WaiStore */
function broadcasted_from()
{
// Check that Broadcast is enabled.
if ( ! function_exists( 'ThreeWP_Broadcast' ) )
return;
// Load the broadcast data for this post.
global $product;
$broadcast_data = ThreeWP_Broadcast()->get_product_broadcast_data( get_current_blog_id(), $product->ID );
// This post must be a child. Check for a parent.
$parent = $broadcast_data->get_linked_parent();
if ( ! $parent )
return;
// Fetch the permalink
switch_to_blog( $parent[ 'blog_id' ] );
$blog_name = get_bloginfo( 'name' );
$permalink = get_product_permalink( $parent[ 'product_id' ] );
restore_current_blog();
// And now assemble a text.
$r = sprintf( 'Store: <a href="%s">%s</a>.', $permalink, $blog_name );
return $r;
}
add_shortcode( 'broadcasted_from', 'broadcasted_from' );
[Moderator note: code fixed. Please wrap code in the backtick character or use the code button.]
Its doesnt seem to matter what i change in the code either nothing changes or I get a blank page
-
This reply was modified 7 years ago by bdbrown.
Blank page = error somewhere.
Enable WP_DEBUG and try again.
Thread Starter
sjanej
(@sjanej)
Ok so Ive put the shortcode back to do_shortcode( ‘[broadcasted_from]’ );
Have enabled wp-debug and obviously Ive changed the code wrong somehow so I need to figure out what changes do I make in the function to grab the products originating blog name as the code doesnt work as is for products only posts
Notice: Undefined variable: post in /home/waibizni/waistore.nz/wp-content/themes/customizr-child-theme-01/functions.php on line 56
Notice: Trying to get property of non-object in /home/waibizni/waistore.nz/wp-content/themes/customizr-child-theme-01/functions.php on line 56
And what is line 56 on that file?
Are you sure you’re supposed to change $post to $product?
Thread Starter
sjanej
(@sjanej)
$broadcast_data = ThreeWP_Broadcast()->get_post_broadcast_data( get_current_blog_id(), $product->ID );
I have no idea what Im supposed to change thats the problem. I have put back the original function and it doesnt display the originating blog name with the product that its broadcasting. If I put the shortcode into one of my posts then that works as expected and the originating blog name appears so its a matter of trying to figure out how to make that function work with a product rather than a post.
-
This reply was modified 7 years ago by bdbrown.
I don’t suppose you have the product ID by the time you’re using the shortcode? Because then you could pass it as a function parameter.