getCustomFields(); ?>
$fieldData ) { if ( ! is_array( $fieldData ) ) { $fieldData = array( 'label' => ucfirst( str_replace( '_', ' ', $key ) ), 'value' => $fieldData, ); } $label = isset( $fieldData['label'] ) && ! empty( $fieldData['label'] ) ? $fieldData['label'] : ucfirst( str_replace( '_', ' ', $key ) ); $value = isset( $fieldData['value'] ) ? $fieldData['value'] : ''; ?>
getProductId(); $quantity = $quote->getQuantity(); $price = $quote->getPrice(); $product = wc_get_product( $productId ); if ( ! $product ) { ?>

get_image( array( 48, 48 ) ) ); ?>
get_name() ); ?> get_sku() ) : ?>
get_sku() ); ?>
getConvertedOrderId() ) : ?>

#getConvertedOrderId() ); ?>

getMeta( '_form_id' ); if ( $formId ) { $form = \TierPricingTable\Addons\RequestAQuote\Models\RequestQuoteForm::get( (string) $formId ); if ( $form ) { $formUrl = admin_url( 'admin.php?page=wc-settings&tab=tiered_pricing_table_settings§ion=request-a-quote&form_id=' . $formId ); ?>
getName() ?: __( 'Unnamed Form', 'tier-pricing-table' ) ); ?>
getUserId(); $email = $quote->getCustomerEmail(); $customFields = $quote->getCustomFields(); $name = ''; $user = null; if ( $userId ) { $user = get_userdata( $userId ); if ( $user ) { $name = $user->display_name; $email = $user->user_email ?: $email; } } if ( ! $name ) { // Try to find name in custom fields foreach ( $customFields as $k => $field ) { $fieldKey = strtolower( $k ); if ( strpos( $fieldKey, 'name' ) !== false || strpos( $fieldKey, 'first_name' ) !== false ) { $name = is_array( $field ) ? ( $field['value'] ?? '' ) : $field; break; } } if ( ! $name ) { $name = __( 'Guest', 'tier-pricing-table' ); } } $avatarUrl = get_avatar_url( $userId ?: $email, array( 'size' => 160 ) ); ?>
Avatar
setPrice( wc_format_decimal( $_POST['tier_pricing_table_quote_price'] ) ); } if ( isset( $_POST['tier_pricing_table_quote_quantity'] ) ) { $quote->setQuantity( (int) $_POST['tier_pricing_table_quote_quantity'] ); } if ( isset( $_POST['tier_pricing_table_quote_status'] ) ) { $quote->setStatus( sanitize_text_field( $_POST['tier_pricing_table_quote_status'] ) ); } // Handle Conversion to Order if ( isset( $_POST['tpt_convert_to_order'] ) && ! $quote->getConvertedOrderId() ) { $productId = $quote->getProductId(); $quantity = $quote->getQuantity(); $price = $quote->getPrice(); $order = wc_create_order(); $order->add_product( wc_get_product( $productId ), $quantity, array( 'subtotal' => $price * $quantity, 'total' => $price * $quantity, ) ); $order->calculate_totals(); // Add customer note // Add customer note $customFields = $quote->getCustomFields(); $notes = "Quote Request Notes:\n"; foreach ( $customFields as $k => $fieldData ) { if ( ! is_array( $fieldData ) ) { $fieldData = array( 'label' => ucfirst( str_replace( '_', ' ', $k ) ), 'value' => $fieldData ); } $label = isset( $fieldData['label'] ) && ! empty( $fieldData['label'] ) ? $fieldData['label'] : ucfirst( str_replace( '_', ' ', $k ) ); $value = isset( $fieldData['value'] ) ? $fieldData['value'] : ''; $notes .= $label . ": " . $value . "\n"; } $order->update_meta_data( 'quote_request_notes', $notes ); $order->save(); // Update quote remove_action( 'save_post', array( $this, 'savePost' ), 10, 2 ); $quote->setConvertedOrderId( $order->get_id() ); $quote->setStatus( 'converted' ); $quote->save(); add_filter( 'redirect_post_location', function ( $location ) use ( $order ) { return $order->get_edit_order_url(); } ); return; } $quote->save(); } public function setCustomColumns( $columns ) { $columns = array( 'cb' => '', 'title' => __( 'Quote', 'tier-pricing-table' ), 'customer' => __( 'Customer', 'tier-pricing-table' ), 'product' => __( 'Product', 'tier-pricing-table' ), 'status' => __( 'Status', 'tier-pricing-table' ), 'date' => __( 'Date', 'tier-pricing-table' ), ); return $columns; } public function customColumnData( $column, $post_id ) { $quote = new QuoteRequest( $post_id ); switch ( $column ) { case 'customer': $name = $quote->getCustomerName(); $email = $quote->getCustomerEmail(); ?>
getProductId(); $quantity = $quote->getQuantity(); $product = wc_get_product( $productId ); if ( $product ) : ?> get_name() ); ?>
getStatus(); $statusLabels = array( 'unread' => __( 'Unread', 'tier-pricing-table' ), 'read' => __( 'Read', 'tier-pricing-table' ), 'converted' => __( 'Converted', 'tier-pricing-table' ), 'rejected' => __( 'Rejected', 'tier-pricing-table' ), ); $label = isset( $statusLabels[ $status ] ) ? $statusLabels[ $status ] : $status; ?> is_main_query() ) { return; } if ( 'edit.php' === $pagenow && isset( $_GET['post_type'] ) && QuoteRequestCPT::POST_TYPE === $_GET['post_type'] && isset( $_GET['tpt_product_filter'] ) && $_GET['tpt_product_filter'] > 0 ) { $meta_query = $query->get( 'meta_query' ); if ( ! is_array( $meta_query ) ) { $meta_query = array(); } $meta_query[] = array( 'key' => '_product_id', 'value' => absint( $_GET['tpt_product_filter'] ), 'compare' => '=', ); $query->set( 'meta_query', $meta_query ); } } public function registerBulkActions( $bulk_actions ) { $bulk_actions['tpt_mark_unread'] = __( 'Mark as Unread', 'tier-pricing-table' ); $bulk_actions['tpt_mark_read'] = __( 'Mark as Read', 'tier-pricing-table' ); $bulk_actions['tpt_mark_rejected'] = __( 'Mark as Rejected', 'tier-pricing-table' ); return $bulk_actions; } public function processBulkActions( $redirect_to, $doaction, $post_ids ) { if ( ! in_array( $doaction, array( 'tpt_mark_unread', 'tpt_mark_read', 'tpt_mark_rejected' ) ) ) { return $redirect_to; } $changed = 0; foreach ( $post_ids as $post_id ) { $quote = new QuoteRequest( $post_id ); if ( 'tpt_mark_unread' === $doaction ) { $quote->setStatus( 'unread' ); } elseif ( 'tpt_mark_read' === $doaction ) { $quote->setStatus( 'read' ); } elseif ( 'tpt_mark_rejected' === $doaction ) { $quote->setStatus( 'rejected' ); } $quote->save(); $changed ++; } $redirect_to = add_query_arg( 'tpt_bulk_changed', $changed, $redirect_to ); $redirect_to = add_query_arg( 'tpt_bulk_action', $doaction, $redirect_to ); return $redirect_to; } public function bulkActionNotices() { if ( ! empty( $_REQUEST['tpt_bulk_changed'] ) && ! empty( $_REQUEST['tpt_bulk_action'] ) ) { $changed = absint( $_REQUEST['tpt_bulk_changed'] ); $action = sanitize_text_field( $_REQUEST['tpt_bulk_action'] ); if ( 'tpt_mark_unread' === $action ) { // translators: %s: number of quotes. $message = sprintf( _n( '%s quote marked as unread.', '%s quotes marked as unread.', $changed, 'tier-pricing-table' ), $changed ); } elseif ( 'tpt_mark_read' === $action ) { // translators: %s: number of quotes. $message = sprintf( _n( '%s quote marked as read.', '%s quotes marked as read.', $changed, 'tier-pricing-table' ), $changed ); } elseif ( 'tpt_mark_rejected' === $action ) { // translators: %s: number of quotes. $message = sprintf( _n( '%s quote marked as rejected.', '%s quotes marked as rejected.', $changed, 'tier-pricing-table' ), $changed ); } else { return; } echo '

' . esc_html( $message ) . '

'; } } }