Last active
March 9, 2021 09:37
-
-
Save Auke1810/331f11567108e2f8bba6966a884ef0c0 to your computer and use it in GitHub Desktop.
Get GTIN or MPN values from products added to products by our product feed manager and create shortcodes to use on website
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// MPN shortcode function | |
function wppfm_brand_shortcode() { | |
// get MPN value. | |
//$r = get_post_meta( $post->ID, 'wppfm_product_brand', true ); | |
$r = get_post_meta( get_the_ID(), 'wppfm_product_brand', true ); | |
// return MPN | |
return $r; | |
} | |
// register shortcode | |
add_shortcode('wppfm-brand', 'wppfm_brand_shortcode'); | |
// MPN shortcode function | |
function wppfm_mpn_shortcode() { | |
// get MPN value. | |
//$r = get_post_meta( $post->ID, 'wppfm_product_mpn', true ); | |
$r = get_post_meta( get_the_ID(), 'wppfm_product_mpn', true ); | |
// return MPN | |
return $r; | |
} | |
// register shortcode | |
add_shortcode('wppfm-mpn', 'wppfm_mpn_shortcode'); | |
// GTIN shortcode function | |
function wppfm_gtin_shortcode() { | |
// get GTIN value. | |
//$r = get_post_meta( $post->ID, 'wppfm_product_gtin', true ); | |
$r = get_post_meta( get_the_ID(), 'wppfm_product_gtin', true ); | |
// return GTIN | |
return $r; | |
} | |
// register shortcode | |
add_shortcode('wppfm-gtin', 'wppfm_gtin_shortcode'); | |
// you can even create a little snippet to add the unique identifier after the price information | |
add_action( 'woocommerce_single_product_summary', 'wppfm_gtin_display', 15 ); | |
function wppfm_gtin_display() { | |
$r = get_post_meta( get_the_ID(), 'wppfm_product_gtin', true ); | |
print '<p id="cont-gtin">GTIN: '. $r .'</p>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment