• Resolved adislic

    (@adislic)


    When user completes a course , need to send API call to external platform. Already inserted API call that passes email address of the user and everything is working fine. Right now i am using hardcoded email for testing but need to get current user email and insert it as a variable. Because of Ajax call, i am not able to figure out how to get email of that user using standard wordpress function for user data. Does Learnpress already have some function to get user email inside js file?

    single-course.js
    ……
    finishCourse: function (args) {
    var that = this;
    LP.ajax({
    url : this.get(‘url’),
    action : ‘finish-course’,
    data : args.data,
    dataType : ‘json’,
    beforeSend: function () {
    LP.blockContent();
    },
    success : function (response) {
    LP.unblockContent();

    LP.ajax({
    url: ‘https://somedomain.com/api/Profile/setCourseCompleted?email=’+’[email protected]’+’&secretKey=xxx-xxxx-xxxx-xxxx’,
    type: ‘GET’,
    success: function(data){
    alert(data);
    }
    });

    learn_press_update_item_content

    $.isFunction(args.callback) && args.callback.call(args.context, response, that);
    }
    });
    ….

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Ken Nguyen

    (@kendy73)

    Hi adislic,

    Sorry but I didn’t get your point clearly.

    I though you “already inserted API call that passes email address of the user and everything is working fine”?

    Ken

    Thread Starter adislic

    (@adislic)

    Sorry, when i said everything is working fine i meant i am able to make API call when i use hardcoded email address but i don’t know how to get the email of the current user so i can pass it through the variable in API statement:
    ” Because of Ajax call, i am not able to figure out how to get email of that user using standard wordpress function for user data. Does Learnpress already have some function to get user email inside js file?

    • This reply was modified 6 years, 9 months ago by adislic.
    • This reply was modified 6 years, 9 months ago by adislic.
    • This reply was modified 6 years, 9 months ago by adislic.
    Plugin Contributor Ken Nguyen

    (@kendy73)

    Please try this

    function custom_footer_user_email() {
    	if ( $user = wp_get_current_user() ) {
    		?>
    		<script>var current_user_email = <?php echo $user->user_email; ?></script>
    		<?php
    	}
    }
    add_action( 'wp_footer', 'custom_footer_user_email' );

    and this

    LP.ajax({
    	url    : 'Https://somedomain.com/api/Profile/setCourseCompleted?email=’+current_user_email+’&secretKey=xxx-xxxx-xxxx-xxxx',
    	type   : 'GET',
    	success: function (data) {
    		alert(data);
    	}
    });

    Let me know ??

    Thread Starter adislic

    (@adislic)

    Where am i supposed to put first code ( function custom_footer_user_email() ….) , in learnpress custom functions.php( learnpress/inc/lp-core-functions.php) or wordpress standard functions.php file?

    Plugin Contributor Ken Nguyen

    (@kendy73)

    The best solution is in a child theme (file functions.php) ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Ajax action ” Finish Course” customization’ is closed to new replies.