2017-03-23 2 views
0

Ich habe einen Dummy Wordpress Website eingerichtet, nur mit dem WooCommerce Plugin.Wordpress - Programmgesteuertes Ändern des Warenkorbversands auf einen beliebigen benutzerdefinierten Wert

Ich habe auch ein Dummy-Produkt: "Cool Watch".

Mein Ziel ist sehr einfach. Nachdem der Benutzer eine "Cool Watch" in den Warenkorb gelegt hat. Ich will sein shipping total zu was auch immer custom value, zum Beispiel: 67.89 USD.

Was muss ich tun, um diese programmatically zu bekommen? jetzt

Für erhalte ich: Shipping total: Free!

Hier gebe ich Ihnen einige Hintergrundinformationen über die aktuelle Situation:

eine „Cool Watch“ auf meinem Wagen zu haben.

Mit diesem Code:

<? 
if (!function_exists("echoc")) { 
    function echoc($data) { 
     echo "\n<pre>\n"; 
     print_r($data); 
     echo "</pre>\n"; 
    } 
} 

$cart_items = $woocommerce->cart->get_cart(); 
echoc($cart_items); 

$shipping_total = $woocommerce->cart->get_cart_shipping_total(); 
echoc("Shipping total: ".$shipping_total); 

?> 

ich diese:

Array 
(
    [c74d97b01eae257e44aa9d5bade97baf] => Array 
     (
      [product_id] => 16 
      [variation_id] => 0 
      [variation] => Array 
       (
       ) 

      [quantity] => 1 
      [line_total] => 50 
      [line_tax] => 3.075 
      [line_subtotal] => 50 
      [line_subtotal_tax] => 3.075 
      [line_tax_data] => Array 
       (
        [total] => Array 
         (
          [1] => 3.075 
         ) 

        [subtotal] => Array 
         (
          [1] => 3.075 
         ) 

       ) 

      [data] => WC_Product_Simple Object 
       (
        [id] => 16 
        [post] => WP_Post Object 
         (
          [ID] => 16 
          [post_author] => 1 
          [post_date] => 2017-03-23 15:05:00 
          [post_date_gmt] => 2017-03-23 15:05:00 
          [post_content] => This is a very cool Watch! 
          [post_title] => Cool Watch 
          [post_excerpt] => 
          [post_status] => publish 
          [comment_status] => open 
          [ping_status] => closed 
          [post_password] => 
          [post_name] => cool-watch 
          [to_ping] => 
          [pinged] => 
          [post_modified] => 2017-03-23 10:09:35 
          [post_modified_gmt] => 2017-03-23 15:09:35 
          [post_content_filtered] => 
          [post_parent] => 0 
          [guid] => http://dummy.development.lagoon.com/?post_type=product&p=16 
          [menu_order] => 0 
          [post_type] => product 
          [post_mime_type] => 
          [comment_count] => 0 
          [filter] => raw 
         ) 

        [product_type] => simple 
        [shipping_class:protected] => 
        [shipping_class_id:protected] => 0 
        [total_stock] => 
        [supports:protected] => Array 
         (
          [0] => ajax_add_to_cart 
         ) 

        [price] => 50.00 
       ) 

     ) 

) 

Shipping total: Free! 
+0

http://stackoverflow.com/questions/27666501/how-to-add-custom-shipping-charge-in-woocommerce Überprüfen Sie dies. BTW gibt es eine "pauschale Versandkosten" -Methode in woocommerce, in der Sie interessiert sein könnten .. –

Antwort

0
add_action('woocommerce_calculate_totals', 'calculate_totals', 10, 1); 

function calculate_totals($totals){ 
//your code 
// return your own value 
} 
Verwandte Themen