Skip to content

Instantly share code, notes, and snippets.

@pablo-sg-pacheco
Last active June 21, 2018 15:58
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 pablo-sg-pacheco/a592f3a7362a630735ca0a7571e28fb4 to your computer and use it in GitHub Desktop.
Save pablo-sg-pacheco/a592f3a7362a630735ca0a7571e28fb4 to your computer and use it in GitHub Desktop.
Replace input field by dropdown using the Product Open Pricing plugin
<?php
// Remove default input
add_filter( 'option_' . 'alg_wc_product_open_pricing_frontend_template', 'popwc_remove_default_input' , 10, 2 );
function popwc_remove_default_input($value){
if(!is_admin()){
$value='';
}
return $value;
}
// Add custom input
add_action( 'woocommerce_before_add_to_cart_button', 'popwc_add_input_field_to_frontend' , PHP_INT_MAX );
function popwc_add_input_field_to_frontend(){
global $product;
$product_id = $product->get_id();
$post_meta = get_post_meta($product_id,'custom_field');
?>
<select id="alg_open_price" name="alg_open_price">
<option>4</option>
<option>6</option>
</select>
<?php
}
@pablo-sg-pacheco
Copy link
Author

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