• Resolved sflis

    (@sflis)


    I’d like to display the store credit constantly (ex. on a nav bar). For it I need to pull the value from the logged in user. In the plugin docs you didn’t mention add-on specific functions. Could you please share the property name of the SliceWP_Affiliate object that holds the store credit amount?

    To not create separate ticket please answer also the second question here if possible. Can I assign a affiliate to the WC_Coupon object through php? If yes how?

Viewing 1 replies (of 1 total)
  • Plugin Author iova.mihai

    (@iovamihai)

    Hey @sflis,

    Thank you for reaching out! To pull the store credit balance of an affiliate, please use the following code:

    $balance = slicewp_get_affiliate_store_credit_balance( slicewp_get_current_affiliate_id() );

    The code will pull the numeric value stored in the database. To format the value based on the currency you have set for your affiliate program, please use this code:

    $balance = slicewp_format_amount( slicewp_get_affiliate_store_credit_balance( slicewp_get_current_affiliate_id() ), slicewp_get_setting( 'active_currency', 'USD' ) );

    As for the coupon, the linked affiliate is saved as meta data to the coupon. Here’s how you can programmatically link an affiliate to a coupon:

    $coupon_code  = 'coupon_code'; // The code of the coupon you wish to link to the affiliate.
    $affiliate_id = 21; // The ID of the affiliate you want attached to the coupon.
    
    $coupon = new WC_Coupon( $coupon_code );
    
    $coupon->update_meta_data( 'slicewp_affiliate_id', $affiliate_id );
    $coupon->save_meta_data();

    Thank you and best wishes,

    Mihai

Viewing 1 replies (of 1 total)
  • The topic ‘Get store credit with php’ is closed to new replies.