Skip to content

Instantly share code, notes, and snippets.

@EricBusch
Last active October 31, 2017 13:16
Show Gist options
  • Save EricBusch/7baac5a60ca64d75ff5ea962ef04344e to your computer and use it in GitHub Desktop.
Save EricBusch/7baac5a60ca64d75ff5ea962ef04344e to your computer and use it in GitHub Desktop.
Custom function that returns the affiliate URL with inserted affiliate ID for any Datafeedr product imported by the Product Sets plugin and saved as a WooCommerce External Product. [datafeedr]
<?php
/**
* Returns the affiliate URL with inserted affiliate ID for any
* Datafeedr product imported by the Product Sets plugin and
* saved as a WooCommerce Product.
*
* Usage: $url = mycode_dfrapi_url( $product );
*
* Returns an empty string if no Datafeedr product exists.
*
* @param WC_Product $product
*
* @return string URL or empty string.
*/
function mycode_dfrapi_url( WC_Product $product ) {
$dfrps_product = get_post_meta( $product->get_id(), '_dfrps_product', true );
if ( empty( $dfrps_product ) ) {
return '';
}
$url = dfrapi_url( $dfrps_product );
return $url;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment