Php 问题创造了商业
我正在尝试制作一个插件,它将在文章页面上显示定义数量的列表。我有两个问题: 1/当产品是可变的或简单的时,我似乎不能包含php文件。 2/我希望在购物车页面中也可以看到该下拉列表,因为产品是预定义数量的 该插件的目的是限制mini和maxi产品的数量 这是我试过的代码Php 问题创造了商业,php,plugins,woocommerce,Php,Plugins,Woocommerce,我正在尝试制作一个插件,它将在文章页面上显示定义数量的列表。我有两个问题: 1/当产品是可变的或简单的时,我似乎不能包含php文件。 2/我希望在购物车页面中也可以看到该下拉列表,因为产品是预定义数量的 该插件的目的是限制mini和maxi产品的数量 这是我试过的代码 <?php /* Plugin Name: Woo Best Drop Down Plugin URI: http://www.fr Description: Drop Down Version: 1.0 Author: x
<?php
/*
Plugin Name: Woo Best Drop Down
Plugin URI: http://www.fr
Description: Drop Down
Version: 1.0
Author: xxx
Author URI: http://xxx.fr
*/
function tab_woo_drop_dwon() {
?>
<li class="woo_best_drop_down_tab"><a href="#woo_best_drop_down_tab"><?php _e('Woo Best Drop Down', 'woo-best-drop-down'); ?></a></li>
<?php }
add_action('woocommerce_product_write_panel_tabs', 'tab_woo_drop_dwon');
function woo_tab_best_drop_down() {
global $post;
$woo_tab_best_drop_down = array(
'hop' => get_post_meta($post->ID, 'woo_best_drop_down_text', true),
'enabled' => get_post_meta($post->ID, 'woo_best_drop_down_enabled', true),
);
?>
<div id="woo_best_drop_down_tab" class="panel woocommerce_options_panel">
<div class="options_group">
<p class="form-field">
<?php woocommerce_wp_checkbox( array( 'id' => 'woo_best_drop_down_enabled', 'label' => __('Activer le seuil du stock faible?', 'woo-best-drop-down'), 'description' => __('Cochez la case pour activer le stock faible personalisé pour ce produit', 'woo-best-drop-down') ) ); ?>
</p>
</div>
<div class="options_group woo_tab_best_drop_down">
<p class="form-field">
<label><?php _e('Seuil du stock faible pour cet article', 'woo-icon-stock'); ?></label>
<input type="textarea" name="woo_best_drop_down_text" value="<?php echo @$woo_tab_best_drop_down['hop']; ?>" placeholder="<?php _e('Saisissez le seuil de stock', 'woo-best-drop-down'); ?>" />
</p>
</div>
</div>
<?php }
add_action('woocommerce_product_write_panels', 'woo_tab_best_drop_down');
function woo_best_drop_down_custom_tab( $post_id ) {
update_post_meta( $post_id, 'woo_best_drop_down_enabled', ( isset($_POST['woo_best_drop_down_enabled']) && $_POST['woo_best_drop_down_enabled'] ) ? 'yes' : 'no' );
update_post_meta( $post_id, 'woo_best_drop_down_text', $_POST['woo_best_drop_down_text']); }
add_action('woocommerce_process_product_meta', 'woo_best_drop_down_custom_tab');
if ( $product->product_type == 'simple' ){include 'simple_drop_down.php';}
elseif ( $product->product_type == 'variable' ) {include 'variable_drop_down.php';}
?>
我找到了解决办法。我已经为变量和简单产品创建了一个文件。我删除了drop_down.php和simple_drop_down.php文件,创建了drop_down.php并编写了以下内容:
<?php
add_action( 'woocommerce_after_add_to_cart_button' , 'add_woo_best_drop_dwon');
function add_woo_best_drop_dwon(){
global $post,$product,$woocommerce;
$truc = get_post_meta($post->ID, 'woo_best_drop_down_text', true);
$values = explode(',',$truc);
$validate = get_post_meta($post->ID, 'woo_best_drop_down_enabled', true);
if (( $validate == 'yes' ) ){
echo "<style>.quantity.buttons_added {
display: none !important;}</style><div class='quantity_select'><select name='quantity'>";
foreach($values as $v){
echo "<option value='$v'>$v</option>";}
echo "</select></div>";
}}
apply_filters( 'woocommerce_quantity_input' , 'add_woo_best_drop_down_variable');
function add_woo_best_drop_down_variable(){
global $post,$product,$woocommerce;
$truc = get_post_meta($post->ID, 'woo_best_drop_down_text', true);
$values = explode(',',$truc);
$validate = get_post_meta($post->ID, 'woo_best_drop_down_enabled', true);
if (( $validate == 'yes' ) ){
echo "<style>.quantity.buttons_added {
display: none !important;}</style><div class='quantity_select'><select name='quantity'>";
foreach($values as $v){
echo "<option value='$v'>$v</option>";}
echo "</select></div>";
}}
?>
Woop很抱歉我编辑了这篇文章!
<?php
add_action( 'woocommerce_after_single_variation' , 'add_woo_best_drop_dwon');
function add_woo_best_drop_dwon(){
global $post,$product,$woocommerce;
$truc = get_post_meta($post->ID, 'woo_best_drop_down_text', true);
$values = explode(',',$truc);
$validate = get_post_meta($post->ID, 'woo_best_drop_down_enabled', true);
if (( $validate == 'yes' ) ){
echo "<style>.quantity.buttons_added {
display: none !important;}</style><div class='quantity_select'><select name='quantity'>";
foreach($values as $v){
echo "<option value='$v'>$v</option>";}
echo "</select></div>";
}}
?>
<?php
add_action( 'woocommerce_after_add_to_cart_button' , 'add_woo_best_drop_dwon');
function add_woo_best_drop_dwon(){
global $post,$product,$woocommerce;
$truc = get_post_meta($post->ID, 'woo_best_drop_down_text', true);
$values = explode(',',$truc);
$validate = get_post_meta($post->ID, 'woo_best_drop_down_enabled', true);
if (( $validate == 'yes' ) ){
echo "<style>.quantity.buttons_added {
display: none !important;}</style><div class='quantity_select'><select name='quantity'>";
foreach($values as $v){
echo "<option value='$v'>$v</option>";}
echo "</select></div>";
}}
apply_filters( 'woocommerce_quantity_input' , 'add_woo_best_drop_down_variable');
function add_woo_best_drop_down_variable(){
global $post,$product,$woocommerce;
$truc = get_post_meta($post->ID, 'woo_best_drop_down_text', true);
$values = explode(',',$truc);
$validate = get_post_meta($post->ID, 'woo_best_drop_down_enabled', true);
if (( $validate == 'yes' ) ){
echo "<style>.quantity.buttons_added {
display: none !important;}</style><div class='quantity_select'><select name='quantity'>";
foreach($values as $v){
echo "<option value='$v'>$v</option>";}
echo "</select></div>";
}}
?>