Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_shortcode('woo_product_meta', function($atts) {
- global $post;
- $atts = shortcode_atts( array(
- 'id' => null,
- 'key' => '',
- ), $atts, 'woo_product_meta' );
- if(empty($atts['key'])) return;
- if( intval( $atts['id'] ) > 0 && function_exists( 'wc_get_product' ) ){
- $product = wc_get_product( intval( $atts['id'] ) );
- } elseif( is_product() ) {
- $product = wc_get_product($post);
- }
- if ( ! is_a( $product, 'WC_Product' ) ) return;
- $meta_val = get_post_meta($product->get_id(), $atts['key'], true);
- return $meta_val;
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement