Aktivieren Sie benutzerdefinierte Preisvarianten für einfache WooCommerce-ProduktePhp

PHP-Programmierer chatten hier
Guest
 Aktivieren Sie benutzerdefinierte Preisvarianten für einfache WooCommerce-Produkte

Post by Guest »

Ich habe derzeit einige benutzerdefinierte Preise basierend auf Benutzerrollen eingerichtet, die für variable Produkte funktionieren.
[img]https: //i.sstatic.net/53Cker1H.png[/img]

Und das ist der Code, den ich verwende, damit es funktioniert:

Code: Select all

    // Add custom fields to variations option pricing
add_action( 'woocommerce_variation_options_pricing', 'add_variation_options_pricing', 20, 3 );
function add_variation_options_pricing( $loop, $variation_data, $post_variation )
{
$value1  = get_post_meta( $post_variation->ID, '_food_price', true );
$value2  = get_post_meta( $post_variation->ID, '_hot_food_price', true );
$value3  = get_post_meta( $post_variation->ID, '_general_price', true );

$symbol = ' (' . get_woocommerce_currency_symbol() . ')';

$key_1 = '_food_price[' . $loop . ']';
$key_2 = '_hot_food_price[' . $loop . ']';
$key_3 = '_general_price[' . $loop . ']';

// General
echo '
' . __( "General", "woocommerce" ) . $symbol . '

';

// Food
echo '
' . __( "Food", "woocommerce" ) . $symbol . '

';

// Hot Food
echo '
' . __( "Hot Food", "woocommerce" ) . $symbol . '

';
}

// Save variations prices custom fields values
add_action( 'woocommerce_save_product_variation', 'save_product_variation_price', 20, 2 );
function save_product_variation_price( $variation_id, $i )
{
if ( isset( $_POST['_food_price'][$i] ) )
{
update_post_meta( $variation_id, '_food_price', floatval( $_POST['_food_price'][$i] ) );
}

if ( isset( $_POST['_hot_food_price'][$i] ) )
{
update_post_meta( $variation_id, '_hot_food_price', floatval( $_POST['_hot_food_price'][$i] ) );
}

if ( isset( $_POST['_general_price'][$i] ) )
{
update_post_meta( $variation_id, '_general_price', floatval( $_POST['_general_price'][$i] ) );
}
}

// Variable product price range
add_filter('woocommerce_variation_prices_price', 'variation_price', 900, 2 );

// Product variations (of a variable product)
add_filter('woocommerce_product_variation_get_price', 'variation_price', 900, 2 );
function variation_price( $price, $object )
{
if( is_user_logged_in() ) {
// Hot Food User
if ( current_user_can( 'stallholder') && current_user_can( 'hot_food' ) ) {
$new_price = (float) get_post_meta( $object->get_id(), '_hot_food_price', true );
$price     = empty($new_price) ? $price : $new_price;
}
// Food User
elseif ( current_user_can( 'stallholder') && current_user_can( 'food' ) ){
$new_price = (float) get_post_meta( $object->get_id(), '_food_price', true );
$price     = empty($new_price) ? $price : $new_price;
}
// General User
else {
$new_price = (float) get_post_meta( $object->get_id(), '_general_price', true );
$price     = empty($new_price) ? $price : $new_price;
}
}
return $price;
}
Ich möchte jetzt dasselbe für einfache Produkte tun und diese Felder hier hinzufügen.
Image

Ich habe jetzt versucht, nachzuforschen, um diese Felder dort hinzuzufügen, wo ich sie brauche zu gehen, habe aber eine Lücke gezogen.
Jede Hilfe wird dankbar angenommen. Danke.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post