וורדפרס ואתרי אינטרנט

owl-158414_960_720
דורג 5 מתוך 5

באתר תמצאו מדריכים ומאמרים ייחודים בעברית, המדריכים לרוב מנסיון מעשי ומיוחסים לפרוייקטים שאני עובד עליהם באותו הזמן. האתר הוא יותר לשימוש פרטי ולתיעוד דברים, בכדי להשתמש מאוחר יותר, אבל החלטתי לפרסם ניתן לשאול כל שאלה וגם לתרום מדריכים באתר דרך תגובה או דרך צור קשר

האקשיין הראשון קורה כאשר מגיעים לעמוד תשלום ולוחצים על שלח אז בעצם הוא שומר את השדה הנוסף שהוספתי

האקשיין השני פשוט מציג את השדה בלוח בקרה של ההזמנה מצד ימין

הקוד למטה קצת JS יש שם עוד קוד שלא שייך שהוא בעצם מעלים את השדות של המשלם כשלוחצים על הצקבוקס של ההזמנה כמתנה

יוצר גם שדה אינפוט שאליו בעצם מכניסים את הערך במקרה הזה אני שומר את עיר המשלם

add_action('woocommerce_checkout_update_order_meta', 'custom_checkout_field_update_order_meta');

function custom_checkout_field_update_order_meta($order_id) {
	if (!empty($_POST['save_city'])) {
		update_post_meta($order_id, 'save_city',sanitize_text_field($_POST['save_city']));
	}
}


add_action( 'woocommerce_admin_order_data_after_order_details', 'mycustom_order_meta_general' );

function mycustom_order_meta_general( $order ){  ?>

        <br class="clear" />
        <?php 
            /*
             * get all the meta data values we need
             */ 
            $_mycustomfield = get_post_meta( $order->get_id(), 'save_city', true );

        ?>
        <div class="save_city">
            <?php

                if( $_mycustomfield ) : 
                ?>
                    <h3>עיר המשלם האמיתית:</h3>
					<?php echo $_mycustomfield ?>

                <?php
                endif;
            ?>
        </div>
<?php } ?>
<script>
jQuery(function(){
	//if (jQuery('#shipping-checkbox-input').is(':checked')) {
		jQuery('#shipping_state').on('change',function(){
			jQuery('#billing_state').val(jQuery('#shipping_state').val());
			jQuery(document.body).trigger('update_checkout');
		});
	//}
	// 
	if (jQuery('#shipping-checkbox-input').is(':checked')) {
		jQuery('#shipping-checkbox-input').click();
	}
	//jQuery('#shipping-checkbox-input').is(':checked') 
	jQuery('#shipping-checkbox-input').on('click',function(){
		if (jQuery('#shipping-checkbox-input').is(':checked')) {
			//jQuery('#billing_state').prop('disabled',true);
			jQuery('#billing_state_field').css('opacity','0');
			jQuery('#billing_address_1_field').css('opacity','0');
			jQuery('#billing_address_2_field').css('opacity','0');
			jQuery('#billing_address_3_field').css('opacity','0');
			jQuery('#billing_address_4_field').css('opacity','0');
			jQuery('#billing_postcode_field').css('opacity','0');
			jQuery('#billing_address_5_field').css('opacity','0');
			
			// שמירת העיר 
			jQuery('.save_city').val(jQuery('#select2-billing_state-container').html());
			
		} else {
			//jQuery('#billing_state').prop('disabled',false);
			jQuery('#billing_state_field').css('opacity','1');
			jQuery('#billing_address_1_field').css('opacity','1');
			jQuery('#billing_address_2_field').css('opacity','1');
			jQuery('#billing_address_3_field').css('opacity','1');
			jQuery('#billing_address_4_field').css('opacity','1');
			jQuery('#billing_postcode_field').css('opacity','1');
			jQuery('#billing_address_5_field').css('opacity','1');
			
		}
	});
		
	// שמירת עיר המשלם 
	jQuery('#billing_address_5_field').append("<input type='hidden' name='save_city' class='save_city' /> ");		
	jQuery('.save_city').val(jQuery('#select2-billing_state-container').html());
	jQuery('#billing_state').on('change',function(){
		if (jQuery('#shipping-checkbox-input').is(':not(:checked)')) {
			jQuery('.save_city').val(jQuery('#select2-billing_state-container').html());
		}


	});
	
	
	
});


</script>

תפריט נגישות