简体   繁体   English

问题创建插件woocommerce

[英]Problems creat plugin woocommerce

I'm trying to make a plugin that will display a list of defined quantity on the article page. 我正在尝试制作一个将在文章页面上显示已定义数量列表的插件。 I have 2 problems: 我有2个问题:

1 / I can not seem to include the php file when a product is variable or simple. 1 /当产品可变或简单时,我似乎无法包含php文件。 2 / I would like to see the dropdown also in the cart page when the product is predefined quantity of 2 /我想在购物车页面中看到预定义数量的下拉菜单

The purpose of the plugin is limited number of mini and maxi product 插件的目的是限制mini和maxi产品的数量

Here is the code I tried 这是我尝试的代码

<?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';}
?>

Simple drop dwon.php 简单删除dwon.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>";

    }}

?>

Variable drop dwon.php 可变放置dwon.php

<?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>";

    }}

?>

Thanks 谢谢

I found a solution. 我找到了解决方案。 i have creat one file for the variable and simple product. 我为可变和简单产品创建了一个文件。 I have delete the file drop_down.php and simple_drop_down.php and i've creat drop_down.php and write this : 我已经删除了文件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>";

    }}

?>

Now my probleme are in the cart. 现在我的问题在购物车中。 If you go in the page cart the quantity is not drop down for the product selectioned. 如果您进入页面购物车,则所选产品的数量不会下降。 Have an idea for add the drop down quantity in the page cart? 有想法在页面购物车中添加下拉数量吗?

Thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM