Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want create method payment different for each product or category in woocommerce , for this i create this function for by one side , create 2 fields and save informations for each product from

function smashing_save_post_class_meta($post_id,$post) 
$new_meta_value2=( isset( $_POST['tfw_woo_active_payment'] ) ? sanitize_html_class( $_POST['tfw_woo_active_payment'] ) : '' );
$meta_key2 = 'tfw_woo_active_payment';
$meta_value2 = get_post_meta( $post_id, $meta_key2, true );
$meta_key3 = 'tfw_woo_payments_let';
$meta_value3 = get_post_meta( $post_id, $meta_key3, true );

update_post_meta( $post_id, $meta_key2, $new_meta_value2 );
update_post_meta( $post_id, $meta_key3, $new_meta_value3 );
function smashing_add_post_meta_boxes() 
global $woocommerce;
'Elements Let',
function smashing_post_class_meta_box( $object, $box ) { ?>
$tfw_value_select="".esc_attr( get_post_meta( $object->ID, 'tfw_woo_active_payment', true ) ).""; 
//echo $tfw_value_select;
Active Select</br>
<select name="tfw_woo_active_payment">
<option value="si" <?php if ($tfw_value_select=="si") {print "selected";}?>>Si</option>
<option value="no" <?php if ($tfw_value_select=="no") {print "selected";}?>>No</option>
Id Select
<input type="text" name="tfw_woo_payments_let" value="<?php echo esc_attr( get_post_meta( $object->ID, 'tfw_woo_payments_let', true ) ); ?>" size="30"/>
<?php }
add_action('add_meta_boxes', 'smashing_add_post_meta_boxes');
add_action( 'save_post', 'smashing_save_post_class_meta', 10, 2 );
$metata1=get_post_meta($post->ID,tfw_woo_payments_let, true);
$metata=get_post_meta($product->ID,tfw_woo_payments_let, true);
function filter_gateways($gateways)
$payment_NAME = 'paypal'; // <--------------- change this
$category_ID = '28';  // <----------- and this
global $woocommerce;
foreach ($woocommerce->cart->cart_contents as $key => $values ) {
// Get the terms, i.e. category list using the ID of the product
$terms = get_the_terms( $values['product_id'], 'product_cat' );
// Because a product can have multiple categories, we need to iterate through the list of the products category for a match
foreach ($terms as $term) {
// 20 is the ID of the category for which we want to remove the payment gateway
if($term->term_id == $category_ID){
// If you want to remove another payment gateway, add it here i.e. unset($gateways['cod']);

return $gateways;
?> backend and by other side 

The problem it´s i can´t show into post - woocommerce - the value i create from admin and with metaboxes , regards

share|improve this question
add comment

1 Answer

The main problem here is, that you have to handle your cart depending on the products and/or categories you have in there. Because what happens if you have products in there with restricted payment methods.
I'm guessing your plan isn't that customers only can buy one item at a time, so you have to take care of that. There is a discussion about that on wordpress.org, take a look: http://wordpress.org/support/topic/restrict-payment-options-based-on-product. There are two solutions that both seem to work, according to the discussion, I didn't test it myself - yet.

share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.