Skip to main content

The product ID is necessary to display a specific product via the product-shortcode.

There are generally 2 ways to find out the product ID.

1) the product URL in the backend, there you can find the product ID:

2) You add the product ID into the product overview. This can be done with just a few lines of code. When using the ChildTheme, simply add the code using the functions.php:

add_filter('manage_product_posts_columns', 'at_product_id_row');
function at_product_id_row( $defaults ) {
    $defaults['product_id']  = __('Produkt-ID', 'affiliatetheme-backend');
    return $defaults;
}

add_action( 'manage_product_posts_custom_column', 'at_product_id_row_action', 10, 2 );
function at_product_id_row_action( $column_name, $post_id ) {
    if ($column_name == 'product_id') {
		echo $post_id;
    }   
}

Preferably all the way to the end.

If you are not using the ChildTheme you can also add it as a plugin. Simply access your installation via FTP and create the folder “mu-plugins” in the folder “wp-plugins”. Afterwards you can create a file there (e.G product_id.php) and add the following code:

add_filter('manage_product_posts_columns', 'at_product_id_row');
function at_product_id_row( $defaults ) {
	$defaults['product_id'] = __('Produkt-ID', 'affiliatetheme-backend');
	return $defaults;
}

add_action( 'manage_product_posts_custom_column', 'at_product_id_row_action', 10, 2 );
function at_product_id_row_action( $column_name, $post_id ) {
	if ($column_name == 'product_id') {
		echo $post_id;
	}
}

After that you save the data. Now you will see a new register that displays the product ID under the register “Products” in your backend.

Additional information about adding functions can be found HERE.


Was this article helpful?

1 Star2 Stars3 Stars4 Stars5 Stars
5.00 / 5

Keine Kommentare vorhanden


You have a question or an opinion about this post? Share it with us!

Your email address will not be published. Required fields are marked *

*
*