how to make Function active Code on wordpress

Question

Now I have ideal coding Activate function serves to my business.
My ideal: i will send to customer active code and order id to they can active their order on my website.
The Coding as bellow.
enter image description here
enter image description here
Step 1: Add Meta box in Order page at admin backend
(To make active code order) (Post_id = orderid , meta_key= activecodefield ,value = activecode)
this step done!

//Adding Meta container admin shop_order pages
add_action( 'add_meta_boxes', 'mv_add_meta_boxes' );
if ( ! function_exists( 'mv_add_meta_boxes' ) )
{
    function mv_add_meta_boxes()
    {

        add_meta_box( 'mv_other_fields', __('Mã Code kích hoạt','woocommerce'), 'mv_add_other_fields_for_packaging', 'shop_order', 'side', 'core' );

    }
}
// Adding Meta field in the meta container admin shop_order pages
if ( ! function_exists( 'mv_add_other_fields_for_packaging' ) )
{
    function mv_add_other_fields_for_packaging()
    {
        global $post;

        $meta_field_data = get_post_meta( $post->ID, '_ma_kich_hoat', true ) ? get_post_meta( $post->ID, '_ma_kich_hoat', true ) : '';

        echo '<input type="hidden" name="mv_other_meta_field_nonce" value="' . wp_create_nonce() . '">
        <p style="border-bottom:solid 1px #eee;padding-bottom:13px;">
            <input type="text" style="width:250px;";" name="my_field_name" placeholder="' . $meta_field_data . '" value="' . $meta_field_data . '"></p>';

    }
}
// Save the data of the Meta field
add_action( 'save_post', 'mv_save_wc_order_other_fields', 10, 1 );
if ( ! function_exists( 'mv_save_wc_order_other_fields' ) )
{

    function mv_save_wc_order_other_fields( $post_id ) {

        // We need to verify this with the proper authorization (security stuff).

        // Check if our nonce is set.
        if ( ! isset( $_POST[ 'mv_other_meta_field_nonce' ] ) ) {
            return $post_id;
        }
        $nonce = $_POST[ 'mv_other_meta_field_nonce' ];

        //Verify that the nonce is valid.
        if ( ! wp_verify_nonce( $nonce ) ) {
            return $post_id;
        }

        // If this is an autosave, our form has not been submitted, so we don't want to do anything.
        if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
            return $post_id;
        }

        // Check the user's permissions.
        if ( 'page' == $_POST[ 'post_type' ] ) {

            if ( ! current_user_can( 'edit_page', $post_id ) ) {
                return $post_id;
            }
        } else {

            if ( ! current_user_can( 'edit_post', $post_id ) ) {
                return $post_id;
            }
        }
        // --- Its safe for us to save the data ! --- //

        // Sanitize user input  and update the meta field in the database.
        update_post_meta( $post_id, '_ma_kich_hoat', $_POST[ 'my_field_name' ] );

    }
}

Step 2: Make shortcode to make active page on frontend
Fill active code and order ID , customer press Active button – this code as bellow:

add_shortcode( 'insertactivecode', 'active_code' );
function active_code(){
    echo '<label for="active_code">Insert active code here : </label>';
    echo '<input type="text" id="active_code" name="active_code" /> ';
    echo  '<label for="id-order">Insert Order ID: </label>';
    echo '<input type="text" id="id_order" name="id_order"/> ';
    echo '<input type="submit" id="activecodesubmit" name="activecodesubmit" value="Active Complete Order" />';
    return;
}

Step 3: Checking after Press Active Button:
+ True : will change status of Order to Completed and Send email to customer order information
+ False : inform they wrong active code and input again.

I DON’T KNOW HOW TO CODE, PLEASE HELP INSTRUCT TO ME TO COMPLETE THIS FUNCTION

0
mr Lightd 8 months 0 Answers 98 views 0

Leave an answer