Это попытка создать настраиваемое поле для «Покупной цены», и цель состоит в том, чтобы рассчитать разницу между ценой продукта и покупной ценой и таким образом получить «прибыль», которая в данном случае называется «Чистая».".
Это выдает мне ошибку:« Предупреждение: встречается нечисловое значение », и это относится к строке 115, которая выглядит следующим образом:
$netwin = $product_standard_cost - $product_purchase_price;
Код выглядит следующим образом:
if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) {
if (is_admin()) {
$url = plugin_dir_url(__FILE__);
add_action('woocommerce_product_options_general_product_data', 'wppp_add_product_purchase_price_field');
add_action('woocommerce_process_product_meta', 'wppp_save_product_purchase_price_field', 10, 2);
add_action('woocommerce_product_after_variable_attributes', 'wppp_add_variable_product_purchase_price_field', 10, 3);
add_action('woocommerce_save_product_variation', 'wppp_save_variable_product_purchase_price_field', 10, 2);
add_action('plugins_loaded', 'wppp_load_product_purchase_price_textdomain');
}
}
function wppp_load_product_purchase_price_textdomain() {
load_plugin_textdomain('products-purchase-price-for-woocommerce', false, plugin_basename(dirname(__FILE__)) . '/languages/');
}
function wppp_add_product_purchase_price_field() {
$currency = get_woocommerce_currency_symbol();
woocommerce_wp_text_input(
array(
'id' => '_purchase_price',
'class' => '',
'wrapper_class' => 'pricing show_if_simple show_if_external',
'label' => __("Purchase Price", 'products-purchase-price-for-woocommerce') . " ($currency)",
'data_type' => 'price',
'desc_tip' => true,
'description' => __('Submit the total product purchase cost.', 'products-purchase-price-for-woocommerce'),
)
);
}
function wppp_save_product_purchase_price_field($post_id, $post) {
if (isset($_POST['_purchase_price'])) {
$purchase_price = ($_POST['_purchase_price'] === '' ) ? '' : wc_format_decimal($_POST['_purchase_price']);
update_post_meta($post_id, '_purchase_price', $purchase_price);
}
}
function wppp_add_variable_product_purchase_price_field($loop, $variation_data, $variation) {
$currency = get_woocommerce_currency_symbol();
woocommerce_wp_text_input(array(
'id' => 'variable_purchase_price[' . $loop . ']',
'wrapper_class' => 'form-row form-row-first',
'label' => __("Purchase Price", 'products-purchase-price-for-woocommerce') . " ($currency)",
'placeholder' => 'Submit the product purchase price.',
'data_type' => 'price',
'desc_tip' => false,
'value' => get_post_meta($variation->ID, '_purchase_price', true)
));
}
function wppp_save_variable_product_purchase_price_field($variation_id, $i) {
if (isset($_POST['variable_purchase_price'][$i])) {
$purchase_price = ($_POST['variable_purchase_price'][$i] === '' ) ? '' : wc_format_decimal($_POST['variable_purchase_price'][$i]);
update_post_meta($variation_id, '_purchase_price', $purchase_price);
}
}
add_filter( 'manage_edit-product_columns', 'wppp_add_purchase_price_product_column', 11);
function wppp_add_purchase_price_product_column( $columns )
{
$columns['_purchase_price'] = __( 'Buy-in Cost','woocommerce');
return $columns;
}
add_action( 'manage_product_posts_custom_column' , 'wppp_display_purchase_price_in_column', 10, 2 );
function wppp_display_purchase_price_in_column( $column, $product_id )
{
global $post;
$purchase_price = get_post_meta( $product_id, '_purchase_price', true );
switch ( $column )
{
case '_purchase_price' :
echo get_woocommerce_currency_symbol() . $purchase_price;
break;
}
}
add_filter( 'manage_edit-product_columns', 'wppp_add_net_winnings_product_column', 11);
function wppp_add_net_winnings_product_column($columns)
{
$columns['net_winnings'] = __( 'Net','woocommerce');
return $columns;
}
add_action( 'manage_product_posts_custom_column' , 'wppp_net_winnings_display', 10, 2 );
function wppp_net_winnings_display( $column, $product_id )
{
global $product;
$product_purchase_price = get_post_meta( $product_id, '_purchase_price', true );
$product_standard_cost = $product->get_regular_price();
$netwin = $product_standard_cost - $product_purchase_price;
switch ( $column )
{
case 'net_winnings' :
echo get_woocommerce_currency_symbol() . $netwin;
break;
}
}
add_filter( "manage_edit-product_sortable_columns", 'wppp_make_purchase_price_column_sortable' );
function wppp_make_purchase_price_column_sortable( $columns )
{
$custom = array(
'_purchase_price' => 'Purchase Price',
'net_winnings' => 'Net',
);
return wp_parse_args( $custom, $columns );
}
Любая помощь высоко ценится.