Created
January 18, 2018 18:43
-
-
Save mahdi-alavi/d2c89d0c62156688d0c2459640220c60 to your computer and use it in GitHub Desktop.
Revisions
-
mahdi-alavi created this gist
Jan 18, 2018 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ /* Add Custom Fee to Woocommerce Cart for Physical Products. =========================================================================== */ function itl_woocommerce_custom_fee() { global $woocommerce; if ( is_admin() && ! defined( 'DOING_AJAX' ) ) { return; } $is_physical = false; $products = $woocommerce->cart->get_cart(); foreach( $products as $product ) { if ( $product['variation_id'] ) { $product_id = $product['variation_id']; } else { $product_id = $product['product_id']; } $is_virtual = get_post_meta( $product_id, '_virtual', true ); $is_downloadable = get_post_meta( $product_id, '_downloadable', true ); if ( $is_virtual != 'yes' && $is_downloadable != 'yes' ) { $is_physical = true; break; } } if ( $is_physical ) { $cost = 100; // fee $woocommerce->cart->add_fee( 'fee', $cost, true, '' ); } } add_action( 'woocommerce_cart_calculate_fees', 'itl_woocommerce_custom_fee' );