You are missing a few parts here to make this work
-
You need set the global
$post
in your function -
You cannot use template tags directly without setting up postdata
-
You need to add the post ID to
get_permalink()
-
You have a lot of syntax errors. Compare my code with yours
You can try the following: (CAVEAT: Untested)
function add_twitter_cards()
{
global $post;
if(is_singular( 'shops' )) {
setup_postdata($post);
$tc_url = get_permalink($post->ID);
$tc_title = get_the_title();
$tc_description = get_the_excerpt();
$tc_image = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' );
$tc_image_thumb = $tc_image[0];
?>
<meta name="twitter:card" value="product" />
<meta name="twitter:site" value="@mytwitter" />
<meta name="twitter:title" value="<?php echo $tc_title; ?>" />
<meta name="twitter:description" value="<?php echo $tc_description; ?>" />
<meta name="twitter:url" value="<?php echo $tc_url; ?>" />
<?php if($tc_image) { ?>
<meta name="twitter:image" value="<?php echo $tc_image_thumb; ?>" />
<?php } if($tc_author) { ?>
<meta name="twitter:creator" value="<?php echo $twitter; ?>" />
<meta name="twitter:label1" value="Total Sales" />
<meta name="twitter:data1" value="<?php echo $totalsales; ?> <?php _e('of', 'sales'); ?> <?php echo $totalsales; ?>" />
<meta name="twitter:label2" value="Amount Earned" />
<meta name="twitter:data2" value="<?php echo countAmountForAll($post->ID); ?>" />
<?
}
wp_reset_postdata();
}
}