Site icon Hip-Hop Website Design and Development

Replace routinely a type inside a operate of a plugin

I attempted a number of methods to do it nevertheless it appears I can do it solely really submitting that type (price_form). However how can I do it routinely and with out being in that web page?

Right here the code

    operate woocommerce_gold_price_display_config_tab() {
        if ( ! isset( $_REQUEST['settings-updated'] ) ) {

            $_REQUEST['settings-updated'] = false;

        }

        if ( false !== $_REQUEST['settings-updated'] ) {

            ?>
                <div id="message" class="updated notice">
                    <p><sturdy><?php esc_html_e( 'Your settings have been saved.', 'woocommerce-gold-price' ) ?></sturdy></p>
                </div>
            <?php

        }
        ?>

        <h1><?php esc_html_e( 'Gold Value Settings', 'woocommerce-gold-price' )?></h1>

        <type methodology="post" motion="options.php">
            <?php
                settings_fields( 'woocommerce_gold_price_options' );
                do_settings_sections( 'woocommerce_gold_price' );
            ?>
            <p class="submit">
                <enter id="price_form" sort="submit" class="button-primary" worth="<?php esc_html_e( 'Save changes', 'woocommerce-gold-price' ) ?>" />
            </p>
        </type>
        <hr />

        <h1><?php esc_html_e( 'Gold priced merchandise', 'woocommerce-gold-price' )?></h1>

        <?php

        $karats = get_option( 'woocommerce_gold_price_options' );

        if ( ! $karats ) {

            $karats = array( '24k' => 0, '22k' => 0, '18k' => 0, '14k' => 0 );

        }

        foreach( $karats as $key => $worth ) {

            $worth     = floatval( str_replace( ',', '', $worth ) );

            $the_query = new WP_Query( array(
                'post_type'      => 'product',
                'posts_per_page' => -1,
                'meta_key'       => 'is_gold_price_product',
                'meta_value'     => 'sure',
                'meta_query'     => array(
                    'key'     => 'gold_price_karats',
                    'worth'   =>  $key,
                    'examine' => '=',
                    ),
                ) ); 

            ?>

            <h2><?php echo $key ?></h2>

            <?php

            if ( 0 == $the_query->found_posts ) {

                echo '<p>' . __( 'No gold merchandise discovered.', 'woocommerce-gold-price' ) . '</p>';

            } else {

                echo '
                    <ol>';

                // The Loop
                whereas ( $the_query->have_posts() ) {

                    $the_query->the_post();

                    $the_product = wc_get_product( $the_query->post->ID );

                    $edit_url    = admin_url( 'publish.php?publish=' . $the_product->get_id() . '&motion=edit' );
                    $message     = '';
                    
                    $unfold = empty(get_post_meta( $the_product->get_id(), 'gold_price_product_spread', true )) ? 0 : get_post_meta( $the_product->get_id(), 'gold_price_product_spread', true );

                    //$unfold      = get_post_meta( $the_product->get_id(), 'gold_price_product_spread', true );

                    $charge         = get_post_meta( $the_product->get_id(), 'gold_price_product_fee', true );
                    $charge         = floatval( str_replace( ',', '', $charge   ) );

                    echo '
                        <li><a href="' . $edit_url. '">' . get_the_title(). '</a>';

                    if ( ! $the_product->has_weight() ) {
                        
                        $message = __( 'Product has zero weight, cannot calculate worth primarily based on weight.', 'woocommerce-gold-price' );

                    } else {

                        if ( $the_product->is_on_sale() ) {

                            $message = __( 'Product was on sale, cannot calculate sale worth.', 'woocommerce-gold-price' );

                        }

                        $weight_price = $the_product->get_weight() * $worth;
                        $spread_price = $weight_price * ( ( $unfold / 100 ) + 1 );
                        $gold_price   = $spread_price +  $charge;

                        echo ': ' . $the_product->get_weight() . woocommerce_gold_price_weight_description()  . ' * ' .  wc_price( str_replace(',', '', $karats[ $key ] ) ) ;


                        echo ' (' . wc_price( $weight_price )  . ') ';

                        if ( $unfold ) {

                            echo ' + ' . wc_price( $spread_price - $weight_price  ) . ' (' . $unfold . '%)' ;

                        }

                        if ( $charge ) {

                            echo ' + ' . wc_price( $charge );

                        }

                        echo ' = <sturdy>' . wc_price( $gold_price ) . '</sturdy>';

                        if ( false === $_REQUEST['settings-updated'] ) {

                            if ( wc_price( $gold_price ) != wc_price( $the_product->get_regular_price() ) )  ' . sprintf( __( 'Warning! This product worth (%s) isn't primarily based on Gold Value, press the "Save changes" button to replace it.', 'woocommerce-gold-price' ), wc_price( $the_product->get_regular_price() ) );
                            

                        } else {

                            $the_product->set_price( $gold_price );
                            $the_product->set_regular_price( $gold_price );
                            $the_product->set_sale_price( '' );
                            $the_product->set_date_on_sale_from( '' );
                            $the_product->set_date_on_sale_to( '' );

                            $the_product->save();

                            update_post_meta( $the_product->get_id(), '_price',         $gold_price );
                            update_post_meta( $the_product->get_id(), '_regular_price', $gold_price );
                            update_post_meta( $the_product->get_id(), '_sale_price', '' );
                            update_post_meta( $the_product->get_id(), '_sale_price_dates_from', '' );
                            update_post_meta( $the_product->get_id(), '_sale_price_dates_to', '' );

                            $log_message = sprintf( __( 'Up to date worth for %1$s', 'woocommerce-gold-price' ), $the_product->get_title() );

                            woocommerce_gold_price_log( $log_message );


                        }
                    }

                    echo ' ' . $message . '</li>';
                }

                echo '
                    </ol>';
            }

            // Restore authentic Question & Submit Information
            wp_reset_query();
            wp_reset_postdata();

        }
    }