Created
April 7, 2020 19:12
-
-
Save cyberwombat/c4d93f946fd996464188eb497dd6bb32 to your computer and use it in GitHub Desktop.
$post conflict resolution
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
public function add_meta_box_product_offers_callback($post) | |
{ | |
$product_id = $post->ID; | |
$args = array( | |
'post_type' => 'woocommerce_offer', | |
'post_status' => array('publish', 'accepted-offer', 'countered-offer', 'buyercountered-offer', 'on-hold-offer', 'expired-offer', 'declined-offer'), | |
'posts_per_page' => -1, | |
'meta_key' => 'offer_product_id', | |
'meta_value' => $product_id, | |
'meta_compare' => '==', | |
); | |
$the_query = new WP_Query($args); | |
if ($the_query->have_posts()) : | |
echo '<table class="wp-list-table widefat fixed striped posts"><thead>'; | |
echo '<tr><th scope="col" id="offer_title" class="manage-column column-offer_title">Title</th><th scope="col" id="offer_date" class="manage-column column-offer_date">Date</th><th scope="col" id="offer_name" class="manage-column column-offer_name">Name</th><th scope="col" id="ofer_price_per" class="manage-column column-ofer_price_per">Price Per</th><th scope="col" id="offer_quantity" class="manage-column column-offer_quantity">Quantity</th><th scope="col" id="offer_amount" class="manage-column column-offer_amount">Amount</th><th scope="col" id="offer_status" class="manage-column column-offer_status">Status</th></tr>'; | |
echo '</thead><tbody id="the-list">'; | |
$p = $GLOBALS['post']; | |
while ($the_query->have_posts()) : $the_query->the_post(); | |
$id = get_the_ID(); | |
$name = get_post_meta($id, 'offer_name', true); | |
$name = ($name != '') ? $name : '-'; | |
$offer_price_per = get_post_meta($id, 'offer_price_per', true); | |
$offer_price_per = ($offer_price_per != '') ? $offer_price_per : '-'; | |
$offer_quantity = get_post_meta($id, 'offer_quantity', true); | |
$offer_quantity = ($offer_quantity != '') ? $offer_quantity : '-'; | |
$offer_amount = get_post_meta($id, 'offer_amount', true); | |
$offer_amount = ($offer_amount > 0) ? $offer_amount : '-'; | |
$status = ''; | |
switch (get_post_status($id)) { | |
case 'publish': $status = 'Pending'; | |
break; | |
case 'accepted-offer': $status = 'Accepted'; | |
break; | |
case 'countered-offer': $status = 'Countered'; | |
break; | |
case 'declined-offer': $status = 'Declined'; | |
break; | |
case 'on-hold-offer': $status = 'On Hold'; | |
break; | |
case 'buyercountered-offer': $status = 'Buyer Countered'; | |
break; | |
case 'expired-offer': $status = 'Expired'; | |
break; | |
case 'completed-offer': $status = 'Completed'; | |
break; | |
default: $status = '-'; | |
break; | |
} | |
echo '<tr>'; | |
echo '<td class="title column-title" data-colname="title"><a href="' . get_edit_post_link() . '">' . get_the_title() . '</a></td>'; | |
echo '<td class="date column-date" data-colname="date"><abbr title="' . get_the_date() . '">' . get_the_date() . '</abbr></td>'; | |
echo '<td class="name column-name" data-colname="name">' . $name . '</td>'; | |
echo '<td class="price_per column-price_per" data-colname="price_per">' . wc_price($offer_price_per) . '</td>'; | |
echo '<td class="quantity column-quantity" data-colname="quantity">' . $offer_quantity . '</td>'; | |
echo '<td class="amount column-amount" data-colname="amount">' . wc_price($offer_amount) . '</td>'; | |
echo '<td class="status column-amount" data-colname="status">' . $status . '</td>'; | |
echo '</tr>'; | |
endwhile; | |
echo '</tbody></table>'; else : | |
echo '<p>No offers for this product.</p>'; | |
endif; | |
wp_reset_postdata(); | |
$GLOBALS['post'] = $p; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment