Viewing 5 replies - 1 through 5 (of 5 total)
  • Shahin

    (@skalanter)

    Hello @syntve,

    Thank you for reaching out,
    You can update that action to this one:

    add_action( 'woocommerce_after_shop_loop_item_title', 'custom_after_title' );
    function custom_after_title() {
    	global $product;
    	if ( $product->get_sku() ) {
    		echo '<strong>SKU: </strong>'; // Add your desired text here
    		echo $product->get_sku();
    	}
    }

    Screenshot: https://postimg.cc/H8gF3yP0.

    I hope it helps.
    Best Regards

    Thread Starter syntve

    (@syntve)

    Thank you, it worked a minute until the snippet got deactivated and I got this error message:

    Snippet automatically deactivated due to an error on line 3:

    Cannot redeclare function custom_after_title.

    This is line 3:

    global $product;
    Shahin

    (@skalanter)

    Hello @syntve,

    Thank you for reaching out,

    It seems that you are using a third-party plugin to add that code.
    Since we don’t know what customizations are on your site, the error “Cannot redeclare function” might mean the function is defined multiple times in your code. If you have duplicate code, you may need to modify it. This particular item requires familiarity with PHP, and if you do not have experience with PHP codes and actions, you may need to seek assistance from a PHP expert.

    There may also be a plugin that uses the same name; perform a basic troubleshooting checkup method and make sure the issue is related to our theme or plugin(s). To do this, deactivate all other plugins, then activate them one by one and check for this issue.

    As a general solution, to solve it, you must check for any repeated code blocks containing the function definition; remove them or try renaming the function to something unique to avoid conflicts in the future.

    I hope it helps.
    Best Regards

    Thread Starter syntve

    (@syntve)

    Thank you for the reply, I will check in to that.

    Best regards

    You’re welcome.
    I’m glad we could help.

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.