Merge pull request #6052 from barrykooij/refactor/get_product
Renamed get_product to wc_get_product
This commit is contained in:
commit
474cba9b87
|
@ -1591,9 +1591,9 @@ abstract class WC_Abstract_Order {
|
|||
*/
|
||||
public function get_product_from_item( $item ) {
|
||||
if ( ! empty( $item['variation_id'] ) && 'product_variation' === get_post_type( $item['variation_id'] ) ) {
|
||||
$_product = get_product( $item['variation_id'] );
|
||||
$_product = wc_get_product( $item['variation_id'] );
|
||||
} elseif ( ! empty( $item['product_id'] ) ) {
|
||||
$_product = get_product( $item['product_id'] );
|
||||
$_product = wc_get_product( $item['product_id'] );
|
||||
} else {
|
||||
$_product = false;
|
||||
}
|
||||
|
@ -1872,7 +1872,7 @@ abstract class WC_Abstract_Order {
|
|||
_deprecated_function( 'get_downloadable_file_urls', '2.1', 'get_item_downloads' );
|
||||
|
||||
$download_file = $variation_id > 0 ? $variation_id : $product_id;
|
||||
$_product = get_product( $download_file );
|
||||
$_product = wc_get_product( $download_file );
|
||||
|
||||
$user_email = $this->billing_email;
|
||||
|
||||
|
@ -1903,7 +1903,7 @@ abstract class WC_Abstract_Order {
|
|||
global $wpdb;
|
||||
|
||||
$product_id = $item['variation_id'] > 0 ? $item['variation_id'] : $item['product_id'];
|
||||
$product = get_product( $product_id );
|
||||
$product = wc_get_product( $product_id );
|
||||
$download_ids = $wpdb->get_col( $wpdb->prepare("
|
||||
SELECT download_id
|
||||
FROM {$wpdb->prefix}woocommerce_downloadable_product_permissions
|
||||
|
|
|
@ -174,7 +174,7 @@ class WC_Admin_Post_Types {
|
|||
global $post;
|
||||
|
||||
if ( empty( $the_product ) || $the_product->id != $post->ID ) {
|
||||
$the_product = get_product( $post );
|
||||
$the_product = wc_get_product( $post );
|
||||
}
|
||||
|
||||
switch ( $column ) {
|
||||
|
@ -787,7 +787,7 @@ class WC_Admin_Post_Types {
|
|||
}
|
||||
|
||||
// Get the product and save
|
||||
$product = get_product( $post );
|
||||
$product = wc_get_product( $post );
|
||||
|
||||
if ( ! empty( $_REQUEST['woocommerce_quick_edit'] ) ) {
|
||||
$this->quick_edit_save( $post_id, $product );
|
||||
|
@ -2027,7 +2027,7 @@ class WC_Admin_Post_Types {
|
|||
$product_id = $variation_id;
|
||||
}
|
||||
|
||||
$product = get_product( $product_id );
|
||||
$product = wc_get_product( $product_id );
|
||||
$existing_download_ids = array_keys( (array) $product->get_files() );
|
||||
$updated_download_ids = array_keys( (array) $downloadable_files );
|
||||
|
||||
|
|
|
@ -105,7 +105,7 @@ class WC_Meta_Box_Coupon_Data {
|
|||
$product_ids = array_map( 'absint', explode( ',', $product_ids ) );
|
||||
foreach ( $product_ids as $product_id ) {
|
||||
|
||||
$product = get_product( $product_id );
|
||||
$product = wc_get_product( $product_id );
|
||||
|
||||
echo '<option value="' . esc_attr( $product_id ) . '" selected="selected">' . wp_kses_post( $product->get_formatted_name() ) . '</option>';
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ class WC_Meta_Box_Coupon_Data {
|
|||
$product_ids = array_map( 'absint', explode( ',', $product_ids ) );
|
||||
foreach ( $product_ids as $product_id ) {
|
||||
|
||||
$product = get_product( $product_id );
|
||||
$product = wc_get_product( $product_id );
|
||||
|
||||
echo '<option value="' . esc_attr( $product_id ) . '" selected="selected">' . wp_kses_post( $product->get_formatted_name() ) . '</option>';
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ class WC_Meta_Box_Order_Downloads {
|
|||
if ( $download_permissions && sizeof( $download_permissions ) > 0 ) foreach ( $download_permissions as $download ) {
|
||||
|
||||
if ( ! $product || $product->id != $download->product_id ) {
|
||||
$product = get_product( absint( $download->product_id ) );
|
||||
$product = wc_get_product( absint( $download->product_id ) );
|
||||
$file_counter = 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -605,7 +605,7 @@ class WC_Meta_Box_Product_Data {
|
|||
if ( $product_ids ) {
|
||||
foreach ( $product_ids as $product_id ) {
|
||||
|
||||
$product = get_product( $product_id );
|
||||
$product = wc_get_product( $product_id );
|
||||
|
||||
if ( $product ) {
|
||||
echo '<option value="' . esc_attr( $product_id ) . '" selected="selected">' . esc_html( $product->get_formatted_name() ) . '</option>';
|
||||
|
@ -623,7 +623,7 @@ class WC_Meta_Box_Product_Data {
|
|||
if ( $product_ids ) {
|
||||
foreach ( $product_ids as $product_id ) {
|
||||
|
||||
$product = get_product( $product_id );
|
||||
$product = wc_get_product( $product_id );
|
||||
|
||||
if ( $product ) {
|
||||
echo '<option value="' . esc_attr( $product_id ) . '" selected="selected">' . esc_html( $product->get_formatted_name() ) . '</option>';
|
||||
|
|
|
@ -147,7 +147,7 @@ class WC_Report_Sales_By_Product extends WC_Admin_Report {
|
|||
$this->product_ids_titles = array();
|
||||
|
||||
foreach ( $this->product_ids as $product_id ) {
|
||||
$product = get_product( $product_id );
|
||||
$product = wc_get_product( $product_id );
|
||||
if ( $product ) {
|
||||
$this->product_ids_titles[] = $product->get_formatted_name();
|
||||
} else {
|
||||
|
|
|
@ -64,7 +64,7 @@ class WC_Report_Stock extends WP_List_Table {
|
|||
global $product;
|
||||
|
||||
if ( ! $product || $product->id !== $item->id )
|
||||
$product = get_product( $item->id );
|
||||
$product = wc_get_product( $item->id );
|
||||
|
||||
switch( $column_name ) {
|
||||
case 'product' :
|
||||
|
|
|
@ -768,7 +768,7 @@ class WC_API_Orders extends WC_API_Resource {
|
|||
}
|
||||
}
|
||||
|
||||
$product = get_product( $item['product_id'] );
|
||||
$product = wc_get_product( $item['product_id'] );
|
||||
|
||||
// must be a valid WC_Product
|
||||
if ( ! is_object( $product ) ) {
|
||||
|
|
|
@ -121,7 +121,7 @@ class WC_API_Products extends WC_API_Resource {
|
|||
return $id;
|
||||
}
|
||||
|
||||
$product = get_product( $id );
|
||||
$product = wc_get_product( $id );
|
||||
|
||||
// add data that applies to every product type
|
||||
$product_data = $this->get_product_data( $product );
|
||||
|
@ -839,7 +839,7 @@ class WC_API_Products extends WC_API_Resource {
|
|||
}
|
||||
|
||||
// Update parent if grouped so price sorting works and stays in sync with the cheapest child
|
||||
$_product = get_product( $id );
|
||||
$_product = wc_get_product( $id );
|
||||
if ( $_product->post->post_parent > 0 || $product_type == 'grouped' ) {
|
||||
|
||||
$clear_parent_ids = array();
|
||||
|
|
|
@ -394,7 +394,7 @@ class WC_API_Reports extends WC_API_Resource {
|
|||
|
||||
foreach ( $top_sellers as $top_seller ) {
|
||||
|
||||
$product = get_product( $top_seller->product_id );
|
||||
$product = wc_get_product( $top_seller->product_id );
|
||||
|
||||
$top_sellers_data[] = array(
|
||||
'title' => $product->get_title(),
|
||||
|
|
|
@ -104,7 +104,7 @@ class WC_API_Products extends WC_API_Resource {
|
|||
if ( is_wp_error( $id ) )
|
||||
return $id;
|
||||
|
||||
$product = get_product( $id );
|
||||
$product = wc_get_product( $id );
|
||||
|
||||
// add data that applies to every product type
|
||||
$product_data = $this->get_product_data( $product );
|
||||
|
|
|
@ -395,7 +395,7 @@ class WC_API_Reports extends WC_API_Resource {
|
|||
|
||||
foreach ( $top_sellers as $top_seller ) {
|
||||
|
||||
$product = get_product( $top_seller->product_id );
|
||||
$product = wc_get_product( $top_seller->product_id );
|
||||
|
||||
$top_sellers_data[] = array(
|
||||
'title' => $product->get_title(),
|
||||
|
|
|
@ -687,7 +687,7 @@ class WC_AJAX {
|
|||
}
|
||||
|
||||
$variations = array();
|
||||
$_product = get_product( $post_id, array( 'product_type' => 'variable' ) );
|
||||
$_product = wc_get_product( $post_id, array( 'product_type' => 'variable' ) );
|
||||
|
||||
// Put variation attributes into an array
|
||||
foreach ( $_product->get_attributes() as $attribute ) {
|
||||
|
@ -874,7 +874,7 @@ class WC_AJAX {
|
|||
}
|
||||
|
||||
foreach ( $product_ids as $product_id ) {
|
||||
$product = get_product( $product_id );
|
||||
$product = wc_get_product( $product_id );
|
||||
$files = $product->get_files();
|
||||
|
||||
if ( ! $order->billing_email ) {
|
||||
|
@ -955,7 +955,7 @@ class WC_AJAX {
|
|||
die();
|
||||
}
|
||||
|
||||
$_product = get_product( $post->ID );
|
||||
$_product = wc_get_product( $post->ID );
|
||||
$order = wc_get_order( $order_id );
|
||||
$order_taxes = $order->get_taxes();
|
||||
$class = 'new_row';
|
||||
|
@ -1305,7 +1305,7 @@ class WC_AJAX {
|
|||
|
||||
// Get product details
|
||||
if ( get_post_type( $product_id ) == 'product' ) {
|
||||
$_product = get_product( $product_id );
|
||||
$_product = wc_get_product( $product_id );
|
||||
$item_tax_status = $_product->get_tax_status();
|
||||
} else {
|
||||
$item_tax_status = 'taxable';
|
||||
|
@ -1573,7 +1573,7 @@ class WC_AJAX {
|
|||
|
||||
if ( $posts ) {
|
||||
foreach ( $posts as $post ) {
|
||||
$product = get_product( $post );
|
||||
$product = wc_get_product( $post );
|
||||
|
||||
$found_products[ $post ] = $product->get_formatted_name();
|
||||
}
|
||||
|
@ -1666,7 +1666,7 @@ class WC_AJAX {
|
|||
|
||||
if ( $posts ) {
|
||||
foreach ( $posts as $post ) {
|
||||
$product = get_product( $post->ID );
|
||||
$product = wc_get_product( $post->ID );
|
||||
$found_products[ $post->ID ] = $product->get_formatted_name();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -190,7 +190,7 @@ class WC_Cart {
|
|||
|
||||
if ( is_array( $cart ) ) {
|
||||
foreach ( $cart as $key => $values ) {
|
||||
$_product = get_product( $values['variation_id'] ? $values['variation_id'] : $values['product_id'] );
|
||||
$_product = wc_get_product( $values['variation_id'] ? $values['variation_id'] : $values['product_id'] );
|
||||
|
||||
if ( ! empty( $_product ) && $_product->exists() && $values['quantity'] > 0 ) {
|
||||
|
||||
|
@ -801,7 +801,7 @@ class WC_Cart {
|
|||
}
|
||||
|
||||
// Get the product
|
||||
$product_data = get_product( $variation_id ? $variation_id : $product_id );
|
||||
$product_data = wc_get_product( $variation_id ? $variation_id : $product_id );
|
||||
|
||||
if ( ! $product_data )
|
||||
return false;
|
||||
|
|
|
@ -36,7 +36,7 @@ class WC_Download_Handler {
|
|||
$order_key = $_GET['order'];
|
||||
$email = sanitize_email( str_replace( ' ', '+', $_GET['email'] ) );
|
||||
$download_id = isset( $_GET['key'] ) ? preg_replace( '/\s+/', ' ', $_GET['key'] ) : '';
|
||||
$_product = get_product( $product_id );
|
||||
$_product = wc_get_product( $product_id );
|
||||
|
||||
if ( ! is_email( $email) ) {
|
||||
wp_die( __( 'Invalid email address.', 'woocommerce' ) . ' <a href="' . esc_url( home_url() ) . '" class="wc-forward">' . __( 'Go to homepage', 'woocommerce' ) . '</a>', '', array( 'response' => 403 ) );
|
||||
|
|
|
@ -564,7 +564,7 @@ class WC_Form_Handler {
|
|||
$product_id = apply_filters( 'woocommerce_add_to_cart_product_id', absint( $_REQUEST['add-to-cart'] ) );
|
||||
$was_added_to_cart = false;
|
||||
$added_to_cart = array();
|
||||
$adding_to_cart = get_product( $product_id );
|
||||
$adding_to_cart = wc_get_product( $product_id );
|
||||
$add_to_cart_handler = apply_filters( 'woocommerce_add_to_cart_handler', $adding_to_cart->product_type, $adding_to_cart );
|
||||
|
||||
// Variable product handling
|
||||
|
@ -582,7 +582,7 @@ class WC_Form_Handler {
|
|||
}
|
||||
|
||||
$attributes = $adding_to_cart->get_attributes();
|
||||
$variation = get_product( $variation_id );
|
||||
$variation = wc_get_product( $variation_id );
|
||||
|
||||
// Verify all attributes
|
||||
foreach ( $attributes as $attribute ) {
|
||||
|
|
|
@ -556,7 +556,7 @@ class WC_Shortcodes {
|
|||
return '';
|
||||
}
|
||||
|
||||
$_product = get_product( $product_data );
|
||||
$_product = wc_get_product( $product_data );
|
||||
|
||||
return esc_url( $_product->add_to_cart_url() );
|
||||
}
|
||||
|
|
|
@ -265,7 +265,7 @@ if ( ! function_exists( 'meta_is_product_attribute' ) ) {
|
|||
* @return bool
|
||||
*/
|
||||
function meta_is_product_attribute( $name, $value, $product_id ) {
|
||||
$product = get_product( $product_id );
|
||||
$product = wc_get_product( $product_id );
|
||||
|
||||
if ( $product->product_type != 'variation' ) {
|
||||
return false;
|
||||
|
|
|
@ -100,6 +100,15 @@ function woocommerce_legacy_paypal_ipn() {
|
|||
}
|
||||
add_action( 'init', 'woocommerce_legacy_paypal_ipn' );
|
||||
|
||||
/**
|
||||
* get_product soft deprecated for wc_get_product
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
function get_product( $the_product = false, $args = array() ) {
|
||||
return wc_get_product( $the_product, $args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Cart functions (soft deprecated)
|
||||
*/
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
* @param array $args (default: array()) Contains all arguments to be used to get this product.
|
||||
* @return WC_Product
|
||||
*/
|
||||
function get_product( $the_product = false, $args = array() ) {
|
||||
function wc_get_product( $the_product = false, $args = array() ) {
|
||||
return WC()->product_factory->get_product( $the_product, $args );
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ function get_product( $the_product = false, $args = array() ) {
|
|||
* @param int $new_stock_level
|
||||
*/
|
||||
function wc_update_product_stock( $product_id, $new_stock_level ) {
|
||||
$product = get_product( $product_id );
|
||||
$product = wc_get_product( $product_id );
|
||||
|
||||
if ( $product->get_stock_quantity() !== $new_stock_level ) {
|
||||
$product->set_stock( $new_stock_level );
|
||||
|
@ -42,7 +42,7 @@ function wc_update_product_stock( $product_id, $new_stock_level ) {
|
|||
* @param int $status
|
||||
*/
|
||||
function wc_update_product_stock_status( $product_id, $status ) {
|
||||
$product = get_product( $product_id );
|
||||
$product = wc_get_product( $product_id );
|
||||
$product->set_stock_status( $status );
|
||||
}
|
||||
|
||||
|
@ -363,7 +363,7 @@ function wc_scheduled_sales() {
|
|||
delete_post_meta( $parent, '_min_price_variation_id' );
|
||||
|
||||
// Grouped products need syncing via a function
|
||||
$this_product = get_product( $product_id );
|
||||
$this_product = wc_get_product( $product_id );
|
||||
|
||||
if ( $this_product->is_type( 'simple' ) ) {
|
||||
$this_product->grouped_product_sync();
|
||||
|
@ -404,7 +404,7 @@ function wc_scheduled_sales() {
|
|||
delete_post_meta( $parent, '_min_variation_price' );
|
||||
|
||||
// Grouped products need syncing via a function
|
||||
$this_product = get_product( $product_id );
|
||||
$this_product = wc_get_product( $product_id );
|
||||
if ( $this_product->is_type( 'simple' ) ) {
|
||||
$this_product->grouped_product_sync();
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ function wc_template_redirect() {
|
|||
|
||||
// Redirect to the product page if we have a single product
|
||||
elseif ( is_search() && is_post_type_archive( 'product' ) && apply_filters( 'woocommerce_redirect_single_search_result', true ) && $wp_query->post_count == 1 ) {
|
||||
$product = get_product( $wp_query->post );
|
||||
$product = wc_get_product( $wp_query->post );
|
||||
|
||||
if ( $product->is_visible() ) {
|
||||
wp_safe_redirect( get_permalink( $product->id ), 302 );
|
||||
|
@ -82,7 +82,7 @@ function wc_setup_product_data( $post ) {
|
|||
if ( empty( $post->post_type ) || ! in_array( $post->post_type, array( 'product', 'product_variation' ) ) )
|
||||
return;
|
||||
|
||||
$GLOBALS['product'] = get_product( $post );
|
||||
$GLOBALS['product'] = wc_get_product( $post );
|
||||
|
||||
return $GLOBALS['product'];
|
||||
}
|
||||
|
@ -206,7 +206,7 @@ function wc_product_post_class( $classes, $class = '', $post_id = '' ) {
|
|||
return $classes;
|
||||
}
|
||||
|
||||
$product = get_product( $post_id );
|
||||
$product = wc_get_product( $post_id );
|
||||
|
||||
if ( $product ) {
|
||||
if ( $product->is_on_sale() ) {
|
||||
|
|
|
@ -430,7 +430,7 @@ function wc_get_customer_available_downloads( $customer_id ) {
|
|||
if ( ! $_product || $_product->id != $result->product_id ) {
|
||||
// new product
|
||||
$file_number = 0;
|
||||
$_product = get_product( $result->product_id );
|
||||
$_product = wc_get_product( $result->product_id );
|
||||
}
|
||||
|
||||
// Check product exists and has the file
|
||||
|
|
|
@ -68,7 +68,7 @@ class WC_Widget_Recent_Reviews extends WC_Widget {
|
|||
|
||||
foreach ( (array) $comments as $comment ) {
|
||||
|
||||
$_product = get_product( $comment->comment_post_ID );
|
||||
$_product = wc_get_product( $comment->comment_post_ID );
|
||||
|
||||
$rating = intval( get_comment_meta( $comment->comment_ID, 'rating', true ) );
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ do_action( 'woocommerce_before_add_to_cart_form' ); ?>
|
|||
<tbody>
|
||||
<?php
|
||||
foreach ( $grouped_products as $product_id ) :
|
||||
$product = get_product( $product_id );
|
||||
$product = wc_get_product( $product_id );
|
||||
$post = $product->post;
|
||||
setup_postdata( $post );
|
||||
?>
|
||||
|
@ -60,7 +60,7 @@ do_action( 'woocommerce_before_add_to_cart_form' ); ?>
|
|||
|
||||
// Reset to parent grouped product
|
||||
$post = $parent_product_post;
|
||||
$product = get_product( $parent_product_post->ID );
|
||||
$product = wc_get_product( $parent_product_post->ID );
|
||||
setup_postdata( $parent_product_post );
|
||||
?>
|
||||
</tbody>
|
||||
|
|
Loading…
Reference in New Issue