Linkwise Affiliate integration in Woocommerce thankyou page

后端 未结 1 889
眼角桃花
眼角桃花 2020-12-21 23:51

I have a Woocommerce store and I like to send an order completion data to an affiliate and they ask me to include the following code:



        
1条回答
  •  清歌不尽
    2020-12-22 00:45

    Here is a way to integrate it; But you will have to add some settings to the code:

    • The program number (your program affiliation ID)
    • The decimal separator (can be a coma or a point).
    • The currency number code (in ISO_4217 format).

    You will have to remove other related code from header or footer as not needed anymore…

    The code is divided in 2 parts:

    • The utility function that contain Linkwise Affiliate script (and settings)
    • The hooked function that will run Linkwise Affiliate scripts on order received (2 choices):

    The first function (Where you will add your settings):

    // Utility function that contain Linkwise Affiliate script
    function linkwise_affiliate_scripts( $order_id ){
    
        ## --- YOUR SETTINGS START BELOW --- ##
    
        $program_id  = '12686'; // <== Your program number
        $decimal_sep = ',';     // Decimal separator
        $currency    = '978';   // For "EUR" => See: https://en.wikipedia.org/wiki/ISO_4217
    
        ## --- END SETTINGS --- ##
    
        $order        = wc_get_order( $order_id );
        $order_status = $order->get_status();
        $items_string = array();
        $count        = 0;
    
        ?>
        
        
        
        
        

    And the hooked function that will run the utility function (with 2 different possibilities):

    A) Using woocommerce_thankyou action hook:

    add_action( 'woocommerce_thankyou','wc_linkwise_affiliate_thanyou_integration', 20, 1 );
    function wc_linkwise_affiliate_thanyou_integration( $order_id ){
        if ( empty($order_id) || $order_id == 0 )
            return; // Exit
    
        linkwise_affiliate_scripts( $order_id ); // Run the Linkwise Affiliate
    }
    

    B) or Using WordPress wp_footer action hook:

    add_action( 'wp_footer', 'wc_linkwise_affiliate_order_received_integration' );
    function wc_linkwise_affiliate_order_received_integration() {
        if ( ! is_wc_endpoint_url( 'order-received' ) )
            return; // Exit
    
        global $wp;
    
        $order_id  = absint( $wp->query_vars['order-received'] );
        if ( empty($order_id) || $order_id == 0 )
            return; // Exit
    
        linkwise_affiliate_scripts( $order_id ); // Run the Linkwise Affiliate
    }
    

    Code goes in function.php file of your active child theme (or theme).

    Tested and works.

    You can check in your browser console, you will see no errors and the correct output flags in Order received page.

    0 讨论(0)
提交回复
热议问题