Skip to content

Instantly share code, notes, and snippets.

@wpmudev-sls
Last active October 9, 2017 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wpmudev-sls/df7cb49d1e258b50caf3ab8f0e1909da to your computer and use it in GitHub Desktop.
Save wpmudev-sls/df7cb49d1e258b50caf3ab8f0e1909da to your computer and use it in GitHub Desktop.
[MarketPress] - Adds Virtual products type in product's Product Kind
<?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 );
@wpmudev-sls
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment