SlickNav icon indicating copy to clipboard operation
SlickNav copied to clipboard

Is it possible to insert a php function/plugin into the containing div.slicknav_menu?

Open davemoz opened this issue 9 years ago • 2 comments

I've been wrestling with this for days. Asked everyone and everywhere I could, so I don't think it's even possible.

I have a simple shopping cart link php plugin (with dynamic item and $$ amounts) in Wordpress. I'm looking to insert the cart link function(preferably, otherwise the simplest method of inserting a php plugin) as the first child of <div class="slicknav_menu">. Then I can align it left, opposite the slicknav "Menu" button, etc.

First, is this possible? And second, how or where might I go about doing it? I've tried every method I could think of (jQuery .load + require_once = wp-load.php, loading the php from jquery.slicknav.js), to no avail.

Any help would be greatly appreciated. Thanks!

davemoz avatar Mar 31 '15 21:03 davemoz

@davemoz, the easiest way to get php variables for use in js is to have php print them as javascript in the header of the page. So essentially you create js variables using php which you can then use in the scripts for modifying your SlickNav. Hopefully this makes sense, if not I can put together a quick jsfiddle if needed.

ComputerWolf avatar Apr 01 '15 17:04 ComputerWolf

@ComputerWolf, ok, I hear you. A jsfiddle with an example would be extremely helpful. If you have a script, or can tell me where/how, to add the actual php->js variable inside that slicknav_menu div, that's the part I'm really struggling with. Whenever you have a minute. Thanks!

This is my php plugin (or the part of it, ie. wcct_cart_button();, I need to add inside slicknav_menu):

// Displays the cart total and number of items as a link
    function wcct_cart_button() {
        global $woocommerce;
            ?>
            <div class="cart-btn">
            <a href="<?php echo esc_url( $woocommerce->cart->get_cart_url() ); ?>" title="<?php _e( 'View your shopping cart', 'woocommerce-cart-dropdown' ); ?>" class="cart-tab <?php echo esc_attr( $visibility ); ?>">
            <?php
            echo '<span class="dashicons dashicons-cart"></span>';
            echo wp_kses_post( $woocommerce->cart->get_cart_total() );
            echo '<span class="contents">' . sprintf( _n( '%d item', '%d items', intval( $woocommerce->cart->get_cart_contents_count() ), 'woocommerce-cart-tab' ), intval( $woocommerce->cart->get_cart_contents_count() ) ) . '</span>';
            ?>
            </a>
            </div>
    <?php }

davemoz avatar Apr 01 '15 17:04 davemoz