• Hi, I am trying to add custom metadata, following https://woocommerce.com/document/stripe/customization/products-as-metadata/

    However, the filter is never applied. Any clue?

    Here is my filter:

    add_filter( 'wc_stripe_intent_metadata', 'add_custom_stripe_metadata', 50, 2 );

    function add_custom_stripe_metadata( $metadata, $order, $prepared_source = null ) {

    error_log("--- add_custom_stripe_metadata, order: " . $order->get_id());
    // Add name, quantity, and price for each line item.
    $count = 1;
    foreach ( $order->get_items() as $item_id => $line_item ) {
    $product = $line_item->get_product();
    $product_sku = $product->get_sku();
    error_log("--- add_custom_stripe_metadata, sku: " . $product_sku);
    $metadata['sku' . $count] = $product_sku;
    $count += 1;
    }

    return $metadata;
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter jmgeffroy

    (@jmgeffroy)

    I thought I had found the solution. I was using the wrong filter. Thanks to https://docs.paymentplugins.com/wc-stripe/api/source-class-WC_Stripe_Payment.html#259, I noticed that I should use 'wc_stripe_order_meta_data':

    add_filter( 'wc_stripe_order_meta_data', 'add_custom_stripe_metadata', 50, 2 );

    function add_custom_stripe_metadata( $metadata, $order) {
    ...
    return $metadata;
    }

    However, for some unknown reason, this filter is not called. But it should, as I read in the aforementioned documentation:

    $args['metadata'] = apply_filters( 'wc_stripe_order_meta_data', $meta_data, $order );

    Perplexed…

    Plugin Author Payment Plugins

    (@mrclayton)

    Hi @jmgeffroy

    The filter wc_stripe_order_meta_data is called. Typically when custom code is not being called, it’s because the the add_filter is being called used in an incorrect sequence. I would recommend something like:

    add_action('init', function(){
    add_filter('wc_stripe_order_meta_data', 'add_custom_stripe_metadata', 50, 2);
    });

    Kind Regards

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.