WooCommerce下载POST-TYPE\\Writepanels限制?

时间:2013-09-18 作者:Kimberly Schroeder-Hargis

如何更改这些代码,以便设置下载限制,并且没有人可以在添加产品方面更改它们?或者把它们藏起来,让别人看不见?

// Download Limit
woocommerce_wp_text_input( array( 
    \'id\' => \'_download_limit\', 
    \'label\' => __( \'Download Limit\', \'woocommerce\' ), 
    \'placeholder\' => __( \'Unlimited\', \'woocommerce\' ), 
    \'description\' => __( \'Leave blank for unlimited re-downloads.\', \'woocommerce\' ), 
    \'type\' => \'number\', 
    \'custom_attributes\' => array(
        \'step\'  => \'1\',
        \'min\'   => \'0\'
    ) 
));

// Expirey
woocommerce_wp_text_input( array( 
    \'id\' => \'_download_expiry\', 
    \'label\' => __( \'Download Expiry\', \'woocommerce\' ), 
    \'placeholder\' => __( \'Never\', \'woocommerce\' ), 
    \'description\' => __( \'Enter the number of days before a download link expires, or leave blank.\', \'woocommerce\' ), 
    \'type\' => \'number\', 
    \'custom_attributes\' => array(
        \'step\'  => \'1\',
        \'min\'   => \'0\'
    ) 
));

do_action( \'woocommerce_product_options_downloads\' );

echo \'</div>\';

1 个回复
SO网友:brasofilo

可以拦截get_post_meta(\'_download_limit\') 并为其设置一个固定值。尝试保存其他值时,会返回到固定值:

add_filter( \'get_post_metadata\', function( $value, $object_id, $meta_key, $single )
{
    if( \'_download_limit\' == $meta_key )
        $value = 100;

    return $value;
}, 10, 4 );
参见Where to put my code: plugin or functions.php?

结束