Last active
October 9, 2017 16:50
-
-
Save wpmudev-sls/df7cb49d1e258b50caf3ab8f0e1909da to your computer and use it in GitHub Desktop.
[MarketPress] - Adds Virtual products type in product's Product Kind
This file contains 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 characters
<?php | |
/* | |
Plugin Name: [MarketPress] Virtual products | |
Plugin URI: https://premium.wpmudev.org/ | |
Description: Adds Virtual products type in product's Product Kind | |
Author: Panos Lyrakis @ WPMUDEV | |
Author URI: https://premium.wpmudev.org/ | |
License: GPLv2 or later | |
*/ | |
add_filter( 'mp_product_kinds', function( $product_kinds ){ | |
$product_kinds[ 'virtual' ] = 'Virtual'; | |
return $product_kinds; | |
}, 10 ); | |
add_filter( 'mp_cart/is_product_downloadable', function( $is_virtual, $product ){ | |
if( $product->is_variation() ){ | |
$product_type = get_post_meta( $product->post_parent, 'product_type', true ); | |
} | |
else{ | |
$product_type = get_post_meta( $product->ID, 'product_type', true ); | |
} | |
if( $product_type == 'virtual' ){ | |
$is_virtual = true; | |
} | |
return $is_virtual; | |
}, 10, 2); | |
add_filter( 'mp_add_field_array_has_variation', function( $metabox_field ){ | |
$metabox_field['conditional']['value'][] = 'virtual'; | |
return $metabox_field; | |
}, 10 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This adds a new Product type in the Product Kind options of a product "Virtual". By choosing this type for a product it will hide the address section in the checkout page without adding the download link to order page and emails.