Last active
May 31, 2019 16:21
-
-
Save CarlosLongarela/69ec6fba4cbe97b15320c8bfd4ebb760 to your computer and use it in GitHub Desktop.
Delete WordPress WooCommerce ld+json price for hide in snippets like Google results
This file contains 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 | |
function cl_product_delete_meta_price( $product = null ) { | |
if ( ! is_object( $product ) ) { | |
global $product; | |
} | |
if ( ! is_a( $product, 'WC_Product' ) ) { | |
return; | |
} | |
if ( '' !== $product->get_price() ) { | |
$shop_name = get_bloginfo( 'name' ); | |
$shop_url = home_url(); | |
$markup_offer = array( | |
'@type' => 'Offer', | |
'availability' => 'https://schema.org/' . $stock = ( $product->is_in_stock() ? 'InStock' : 'OutOfStock' ), | |
'sku' => $product->get_sku(), | |
'image' => wp_get_attachment_url( $product->get_image_id() ), | |
'description' => $product->get_description(), | |
'seller' => array( | |
'@type' => 'Organization', | |
'name' => $shop_name, | |
'url' => $shop_url, | |
), | |
); | |
} | |
return $markup_offer; | |
} | |
add_filter( 'woocommerce_structured_data_product_offer', 'cl_product_delete_meta_price' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment