Snippets

Visser Labs Adding custom Subscription fields to the Subscriptions export type

Created by Michael Visser
<?php
function custom_woo_ce_extend_subscription_fields( $fields ) {

    $fields[] = array(
        'name' => 'paypal_subscriber_id',
        'label' => __( 'PayPal Subscriber ID', 'woo_ce' ),
        'hover' => __( 'PayPal Subscriber ID within functions.php', 'woo_ce' )
    );
    return $fields;

}
add_filter( 'woo_ce_subscription_fields', 'custom_woo_ce_extend_subscription_fields' );

function custom_woo_ce_subscription_extend( $subscription, $subscription_id ) {

    $subscription->paypal_subscriber_id = get_post_meta( $subscription_id, 'PayPal Subscriber ID', true );
    // Legacy Post meta name for PayPal Subscriber ID in WooCommerce Subscriptions
    // $subscription->paypal_subscriber_id = get_post_meta( $subscription_id, '_paypal_subscription_id', true );    
    return $subscription;

}
add_filter( 'woo_ce_subscription', 'custom_woo_ce_subscription_extend', 10, 2 );
?>

Comments (0)