Created
December 9, 2016 19:46
-
-
Save rayflores/c1be802a057237962ca76c405c020d3e to your computer and use it in GitHub Desktop.
sort not working PIP
This file contains 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 | |
add_action( 'wc_pip_styles','add_custom_css' ); | |
function add_custom_css(){ | |
?> | |
.customer-details { | |
margin-left: -15px; | |
margin-right: -15px; | |
} | |
.customer-details li { | |
padding: 0 15px; | |
width: 50%; | |
-webkit-box-sizing: border-box; | |
-moz-box-sizing: border-box; | |
box-sizing: border-box; | |
} | |
.customer-email, .customer-phone { | |
float:left; | |
clear:both; | |
} | |
.customer-name_board_copy { | |
float:right; | |
margin-top:-15px; | |
} | |
.customer-name_board_font, .customer-batch { | |
float:right; | |
clear:right; | |
} | |
table thead.order-table-head th { | |
border-color: #DDD; | |
} | |
ul.customer-details { | |
list-style:none; | |
height:60px; | |
} | |
table.packing-list-order-table .breadcrumbs { | |
display:none; | |
} | |
<?php | |
} | |
add_filter( 'wc_pip_document_shipping_method', 'remove_price_from_shipping_method', 10, 3); | |
function remove_price_from_shipping_method( $shipping_method, $type, $order ){ | |
if ( 'packing-list' === $type) : | |
if ( $get_shipping_method = $order->get_shipping_method() ) { | |
$shipping_method = $get_shipping_method; //. '<br>' . wc_price( $this->order->get_total_shipping() ); | |
} else { | |
$shipping_method = __( 'No shipping', 'woocommerce-pip' ); | |
} | |
endif; | |
return $shipping_method; | |
} | |
add_filter( 'wc_pip_document_table_headers', 'custom_table_headers', 10, 3); | |
function custom_table_headers($table_headers, $order_id, $type ){ | |
if ('packing-list' === $type ) : | |
unset($table_headers['weight']); | |
unset($table_headers['id']); | |
endif; | |
return $table_headers; | |
} | |
add_filter( 'wc_pip_document_table_footer', 'add_custom_rows_of_data_invoice',10,3); | |
function add_custom_rows_of_data_invoice( $rows, $type, $order_id ){ | |
if ('packing-list' === $type) : | |
$rows = array(); | |
endif; | |
if ('invoice' === $type) : | |
$rows = $rows; | |
endif; | |
return $rows; | |
} | |
add_filter('wc_pip_document_table_row_cells','remove_price_from_cells',10,5); | |
function remove_price_from_cells( $table_row_cells, $type, $item_id, $item, $product ){ | |
if ('packing-list' === $type ) : | |
unset($table_row_cells['weight']); | |
unset($table_row_cells['id']); | |
// if ( !empty( $item[ 'composite_parent' ] ) && !$product->is_type('simple') ) : | |
if ( empty($product->get_sku()) ) : // no sku present | |
unset($table_row_cells['quantity']); | |
unset($table_row_cells['product']); | |
unset($table_row_cells['sku']); | |
endif; | |
endif; | |
if ('invoice' === $type ) : | |
unset($table_row_cells['weight']); | |
if ( !empty( $item[ 'composite_parent' ] ) && !$product->is_type('simple') ) : | |
$table_row_cells['quantity'] = ''; | |
$table_row_cells['price'] = ''; | |
// $table_row_cells['product'] = print_r($item['composite_data']); | |
endif; | |
endif; | |
return $table_row_cells; | |
} | |
add_filter( 'wc_pip_document_customer_details', 'add_in_extra_order_details', 10, 3); | |
function add_in_extra_order_details($customer_details, $order_id, $type ){ | |
$order = wc_get_order($order_id); | |
if ('packing-list' === $type ) : | |
$customer_details = array(); | |
if ( isset( $order->billing_email ) && $order->billing_email ) { | |
$customer_details['customer-email'] = array( | |
'label' => __( 'Email:', 'woocommerce-pip' ), | |
'value' => '<a class="packingphone" href="mailto:' . $order->billing_email . '">' . $order->billing_email . '</a>', | |
); | |
} | |
if ( isset( $order->billing_phone ) && $order->billing_phone ) { | |
$customer_details['customer-phone'] = array( | |
'label' => __( 'Phone:', 'woocommerce-pip' ), | |
'value' => '<a class="thisone" href="tel:' . $order->billing_phone . '">' . $order->billing_phone . '</a>', | |
); | |
} | |
if ( get_post_meta($order_id, 'name_board_copy',true) != '' ) { | |
$name_board_copy = get_post_meta($order_id, 'name_board_copy', true); | |
$customer_details['customer-name_board_copy'] = array( | |
'label' => __( 'Name Board Copy:', 'woocommerce-pip' ), | |
'value' => $name_board_copy, | |
); | |
} | |
if ( get_post_meta($order_id, 'name_board_font',true) != '' ) { | |
$name_board_font = get_post_meta($order_id, 'name_board_font', true); | |
$customer_details['customer-name_board_font'] = array( | |
'label' => __( 'Name Board Font:', 'woocommerce-pip' ), | |
'value' => $name_board_font, | |
); | |
} | |
if ( get_post_meta($order_id, 'batch',true) != '' ) { | |
$batch = get_post_meta($order_id, 'batch', true); | |
$customer_details['customer-batch'] = array( | |
'label' => __( 'Batch:', 'woocommerce-pip' ), | |
'value' => $batch, | |
); | |
} | |
if ( get_post_meta($order_id, 'bin',true) != '' ) { | |
$bin = get_post_meta($order_id, 'bin', true); | |
$customer_details['customer-bin'] = array( | |
'label' => __( 'Bin:', 'woocommerce-pip' ), | |
'value' => $bin, | |
); | |
} | |
endif; | |
if ('invoice' === $type ) : | |
$customer_details = array(); | |
if ( isset( $order->billing_email ) && $order->billing_email ) { | |
$customer_details['customer-email'] = array( | |
'label' => __( 'Email:', 'woocommerce-pip' ), | |
'value' => '<a class="packingphone" href="mailto:' . $order->billing_email . '">' . $order->billing_email . '</a>', | |
); | |
} | |
if ( isset( $order->billing_phone ) && $order->billing_phone ) { | |
$customer_details['customer-phone'] = array( | |
'label' => __( 'Phone:', 'woocommerce-pip' ), | |
'value' => '<a class="thisone" href="tel:' . $order->billing_phone . '">' . $order->billing_phone . '</a>', | |
); | |
} | |
if ( get_post_meta($order_id, 'name_board_copy',true) != '' ) { | |
$name_board_copy = get_post_meta($order_id, 'name_board_copy', true); | |
$customer_details['customer-name_board_copy'] = array( | |
'label' => __( 'Name Board Copy:', 'woocommerce-pip' ), | |
'value' => $name_board_copy, | |
); | |
} | |
if ( get_post_meta($order_id, 'name_board_font',true) != '' ) { | |
$name_board_font = get_post_meta($order_id, 'name_board_font', true); | |
$customer_details['customer-name_board_font'] = array( | |
'label' => __( 'Name Board Font:', 'woocommerce-pip' ), | |
'value' => $name_board_font, | |
); | |
} | |
if ( get_post_meta($order_id, 'batch',true) != '' ) { | |
$batch = get_post_meta($order_id, 'batch', true); | |
$customer_details['customer-batch'] = array( | |
'label' => __( 'Batch:', 'woocommerce-pip' ), | |
'value' => $batch, | |
); | |
} | |
if ( get_post_meta($order_id, 'bin',true) != '' ) { | |
$bin = get_post_meta($order_id, 'bin', true); | |
$customer_details['customer-bin'] = array( | |
'label' => __( 'Bin:', 'woocommerce-pip' ), | |
'value' => $bin, | |
); | |
} | |
endif; | |
return $customer_details; | |
} | |
add_action( 'wc_pip_header', 'render_custom_headers',1,4); | |
function render_custom_headers( $type, $action, $document, $order ){ | |
if ('packing-list' === $type ) : | |
$view_order_url = is_admin() && 'send_email' !== $action ? admin_url( 'post.php?post=' . $order->id . '&action=edit' ) : wc_get_endpoint_url( 'view-order', $order->id, get_permalink( wc_get_page_id( 'myaccount' ) ) ); | |
/* translators: Placeholders: %1$s - invoice number, %2$s - order number */ | |
printf( '<h3 class="order-info">' . esc_html__( 'Packing List - Order %1$s', 'woocommerce-pip' ) . '</h3>', '<a href="' . $view_order_url . '" target="_blank">' . $order->get_order_number() . '</a>' ); | |
endif; | |
if ('invoice' === $type ) : | |
$view_order_url = is_admin() && 'send_email' !== $action ? admin_url( 'post.php?post=' . $order->id . '&action=edit' ) : wc_get_endpoint_url( 'view-order', $order->id, get_permalink( wc_get_page_id( 'myaccount' ) ) ); | |
/* translators: Placeholders: %1$s - invoice number, %2$s - order number */ | |
printf( '<h3 class="order-info">' . esc_html__( 'Invoice %1$s', 'woocommerce-pip' ) . '</h3>', $document->get_invoice_number() ); | |
/* translators: Placeholder: %s - order date */ | |
printf( '<h5 class="order-date">' . esc_html__( 'Order Date: %s', 'woocommerce-pip' ) . '</h5>', date_i18n( wc_date_format(), strtotime( $order->order_date ) ) ); | |
endif; | |
} | |
function sv_wc_pip_document_sort_order_items_key( $sort_by, $order_id, $type ) { | |
// sort order items in all document types by SKU. | |
// note: uncomment this line and remove the `switch` statement below | |
$sort_by = 'sku'; | |
// sort order items depending on the document type | |
return $sort_by; | |
} | |
add_filter( 'wc_pip_document_sort_order_items_key', 'sv_wc_pip_document_sort_order_items_key', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
results: http://screencast.com/t/44jCjM8Hr8