Created
April 12, 2024 07:53
-
-
Save code-flow/585d2c4708513234b854ef24098f9624 to your computer and use it in GitHub Desktop.
Add Merchant fields to WooCommerce offers
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 | |
/* | |
Plugin Name: SNIP WooCommerce Offers Merchants | |
Description: Adds new fields for merchants in the WooCommerce Offers schema. | |
Author: Florian Simeth | |
Version: 0.1.0 | |
Author URI: https://rich-snippets.io | |
Plugin URI: https://rich-snippets.io/add-merchant-fields-to-woocommerce-offers/ | |
*/ | |
namespace snip\woocommerce\merchantext; | |
if ( ! defined( 'ABSPATH' ) ) { | |
exit; | |
} // Exit if accessed directly | |
add_filter( 'wpbuddy/rich_snippets/fields/internal_subselect/values', '\snip\woocommerce\merchantext\subselects' ); | |
/** | |
* Adds new field to use in Global Snippets in the SNIP plugin. | |
* | |
* @param array $values | |
* | |
* @return array | |
* @since 0.1.0 | |
* | |
*/ | |
function subselects( $values ) { | |
$values['http://schema.org/Offer'][] = [ | |
'id' => 'woocommerce_offers_merchant', | |
'label' => esc_html_x( 'WooCommerce Offers with Merchant data', 'subselect field', 'snip-fte' ), | |
'method' => '\snip\woocommerce\merchantext\offers_with_merchant', | |
]; | |
return $values; | |
} | |
/** | |
* Returns the value. | |
* | |
* @param $val | |
* @param \wpbuddy\rich_snippets\Rich_Snippet $rich_snippet | |
* @param array $meta_info | |
* | |
* @return object | |
*/ | |
function offers_with_merchant( $val, \wpbuddy\rich_snippets\Rich_Snippet $rich_snippet, array $meta_info ) { | |
$offers = \wpbuddy\rich_snippets\pro\WooCommerce_Model::offers( $val, $rich_snippet, $meta_info ); | |
$offers->hasMerchantReturnPolicy = new \stdClass(); | |
$offers->hasMerchantReturnPolicy->type = 'MerchantReturnPolicy'; | |
$offers->hasMerchantReturnPolicy->merchantReturnDays = 30; | |
$offers->hasMerchantReturnPolicy->applicableCountry = 'US'; | |
$offers->hasMerchantReturnPolicy->returnPolicyCategory = 'https://schema.org/MerchantReturnFiniteReturnWindow'; | |
$offers->hasMerchantReturnPolicy->returnMethod = 'https://schema.org/ReturnByMail'; | |
$offers->hasMerchantReturnPolicy->returnFees = 'https://schema.org/FreeReturn'; | |
$offers->shippingDetails = new \stdClass(); | |
$offers->shippingDetails->type = 'OfferShippingDetails'; | |
$offers->shippingDetails->shippingRate = new \stdClass(); | |
$offers->shippingDetails->shippingRate->type = 'MonetaryAmount'; | |
$offers->shippingDetails->shippingRate->currency = 'USD'; | |
$offers->shippingDetails->shippingRate->value = 0; | |
$offers->shippingDetails->shippingDestination = new \stdClass(); | |
$offers->shippingDetails->shippingDestination->type = 'DefinedRegion'; | |
$offers->shippingDetails->shippingDestination->addressCountry = 'US'; | |
return $offers; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment