Ďakovná stránka a dotazník pri objednávke

Odporúčam skopírovať celý priečinok z woocomerce/templates  do child-témy aby sa úpravy zachovali aj pri aktualizácií pluginu
Ak nemáte child tému tak si ju treba vytvoriť. Ďalšia možnosť je použiť include alebo requiere pre vloženie kódu z inej lokality.


Woocomerce dotazník na thank_you page ktorý sa zobrazí pri objednávke

// woocomerce dotaznik na thank_you page ktorý sa zobrazí pri objednávke

add_action( 'woocommerce_thankyou', 'ppp_poll_form', 4 );
function ppp_poll_form( $order_id ) {
    echo '<h2>Ohodnoťte Váš nákup</h2>
        <form id="thankyou_form">
        <label><input type="radio" name="like" value="Super"> Super</label><br>
        <label><input type="radio" name="like" value="Dobre"> Dobré </label><br>
        <label><input type="radio" name="like" value="Mohlo to byť lepšie"> Mohlo to byť lepšie</label>
        <input type="hidden" name="action" value="collect_feedback" />
        <input type="hidden" name="order_id" value="' . $order_id . '" />
        ' . wp_nonce_field( 'thankyou'.$order_id, 'thankyou_nonce', true, false ) . '
        </form><br><br>';


}
add_action( 'wp_footer', 'ppp_send_thankyou_ajax' );
function ppp_send_thankyou_ajax(){
    // exit if we are not on the Thank You page
    if( !is_wc_endpoint_url( 'order-received' ) ) return;
    echo "<script>
    jQuery( function( $ ) {
        $('input[type=radio][name=like]').change(function() {
            $.ajax({
                url: '" . admin_url('admin-ajax.php') . "',
                type: 'POST',
                data: $('#thankyou_form').serialize(),
                beforeSend : function( xhr ){
                    $('#thankyou_form').html('Ďakujeme za Váš názor!');
                },
                success : function( data ){
                    console.log( data );
                }
            });
        });
    });
    </script>";
}
add_action( 'wp_ajax_collect_feedback', 'ppp_thankyou_ajax' ); // wp_ajax_{ACTION}
add_action( 'wp_ajax_nopriv_collect_feedback', 'ppp_thankyou_ajax' );
function ppp_thankyou_ajax(){
    // security check
    check_ajax_referer( 'thankyou'.$_POST['order_id'], 'thankyou_nonce' );
    if( $order = wc_get_order( $_POST['order_id'] ) ) {
        $note = $order->get_formatted_billing_full_name() . ' Zákazník hodnotí obchod ako ' . $_POST['like'] . '.';
        $order->add_order_note( $note, 0, true );
    }


    die();
}
Pri úprave thankyou page sa Vám zídu aj tieto príkazy z objednávky:
// Get an instance of the WC_Order Object from the Order ID (if required)
$order = wc_get_order( $order_id );

// Get the Customer ID (User ID)
$customer_id = $order->get_customer_id(); // Or $order->get_user_id();

// Get the WP_User Object instance
$user = $order->get_user();

// Get the WP_User roles and capabilities
$user_roles = $user->roles;

// Get the Customer billing email
$billing_email  = $order->get_billing_email();

// Get the Customer billing phone
$billing_phone  = $order->get_billing_phone();

// Customer billing information details
$billing_first_name = $order->get_billing_first_name();
$billing_last_name  = $order->get_billing_last_name();
$billing_company    = $order->get_billing_company();
$billing_address_1  = $order->get_billing_address_1();
$billing_address_2  = $order->get_billing_address_2();
$billing_city       = $order->get_billing_city();
$billing_state      = $order->get_billing_state();
$billing_postcode   = $order->get_billing_postcode();
$billing_country    = $order->get_billing_country();

// Customer shipping information details
$shipping_first_name = $order->get_shipping_first_name();
$shipping_last_name  = $order->get_shipping_last_name();
$shipping_company    = $order->get_shipping_company();
$shipping_address_1  = $order->get_shipping_address_1();
$shipping_address_2  = $order->get_shipping_address_2();
$shipping_city       = $order->get_shipping_city();
$shipping_state      = $order->get_shipping_state();
$shipping_postcode   = $order->get_shipping_postcode();
$shipping_country    = $order->get_shipping_country();

Pridaj komentár

Vaša e-mailová adresa nebude zverejnená.