Last active
August 1, 2019 10:24
-
-
Save wpweb101/c7511378d58ca00b12aa212555e77ee2 to your computer and use it in GitHub Desktop.
WooCommerce Pdf Voucher - hide buyer's information while using shortcode [woo_vou_check_code]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Handles to hide product information from check voucher code page for frontend | |
| */ | |
| add_filter('woo_vou_check_vou_productinfo_fields', 'woo_vou_hide_product_info_fields'); | |
| function woo_vou_hide_product_info_fields( $product_info_columns ){ | |
| if( woo_vou_check_is_frontend_ajax() ){ | |
| if( isset( $product_info_columns['redeemable_price'] )){ | |
| unset( $product_info_columns['redeemable_price'] ); | |
| } | |
| if( isset( $product_info_columns['item_price'] )){ | |
| unset( $product_info_columns['item_price'] ); | |
| } | |
| } | |
| return $product_info_columns; | |
| } | |
| /** | |
| * Handles to hide voucher information from check voucher code page for frontend | |
| */ | |
| add_filter('woo_vou_check_vou_voucherinfo_fields', 'woo_vou_hide_voucher_info_fields'); | |
| function woo_vou_hide_voucher_info_fields( $voucher_info_columns ){ | |
| if( woo_vou_check_is_frontend_ajax() ){ | |
| if( isset( $voucher_info_columns['voucher_data'] )){ | |
| unset( $voucher_info_columns['voucher_data'] ); | |
| } | |
| if( isset( $voucher_info_columns['logo'] )){ | |
| unset( $voucher_info_columns['logo'] ); | |
| } | |
| } | |
| return $voucher_info_columns; | |
| } | |
| /** | |
| * Handles to hide buyer information from check voucher code page for frontend | |
| */ | |
| add_filter('woo_vou_check_vou_buyerinfo_fields', 'woo_vou_hide_buyer_info_fields'); | |
| function woo_vou_hide_buyer_info_fields( $buyer_info_columns ){ | |
| if( woo_vou_check_is_frontend_ajax() ){ | |
| if( isset( $buyer_info_columns['buyer_email'] )){ | |
| unset( $buyer_info_columns['buyer_email'] ); | |
| } | |
| if( isset( $buyer_info_columns['billing_address'] )){ | |
| unset( $buyer_info_columns['billing_address'] ); | |
| } | |
| if( isset( $buyer_info_columns['shipping_address'] )){ | |
| unset( $buyer_info_columns['shipping_address'] ); | |
| } | |
| if( isset( $buyer_info_columns['buyer_phone'] )){ | |
| unset( $buyer_info_columns['buyer_phone'] ); | |
| } | |
| } | |
| return $buyer_info_columns; | |
| } | |
| /** | |
| * Handles to hide order information from check voucher code page for frontend | |
| */ | |
| add_filter('woo_vou_check_vou_orderinfo_fields', 'woo_vou_hide_order_info_fields'); | |
| function woo_vou_hide_order_info_fields( $order_info_columns ){ | |
| if( woo_vou_check_is_frontend_ajax() ){ | |
| if( isset( $order_info_columns['payment_method'] )){ | |
| unset( $order_info_columns['payment_method'] ); | |
| } | |
| if( isset( $order_info_columns['order_total'] )){ | |
| unset( $order_info_columns['order_total'] ); | |
| } | |
| if( isset( $order_info_columns['order_discount'] )){ | |
| unset( $order_info_columns['order_discount'] ); | |
| } | |
| } | |
| return $order_info_columns; | |
| } | |
| /** | |
| * Handles to check request from frontend | |
| */ | |
| function woo_vou_check_is_frontend_ajax() { | |
| $script_filename = isset($_SERVER['SCRIPT_FILENAME']) ? $_SERVER['SCRIPT_FILENAME'] : ''; | |
| if((defined('DOING_AJAX') && DOING_AJAX)) | |
| { | |
| $ref = ''; | |
| if ( ! empty( $_REQUEST['_wp_http_referer'] ) ) | |
| $ref = wp_unslash( $_REQUEST['_wp_http_referer'] ); | |
| elseif ( ! empty( $_SERVER['HTTP_REFERER'] ) ) | |
| $ref = wp_unslash( $_SERVER['HTTP_REFERER'] ); | |
| //If referer does not contain admin URL and we are using the admin-ajax.php endpoint, this is likely a frontend AJAX request | |
| if(((strpos($ref, admin_url()) === false) && (basename($script_filename) === 'admin-ajax.php'))){ | |
| return true; | |
| } | |
| } | |
| //If no checks triggered, we end up here - not an AJAX request. | |
| return false; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment