How to use fontawesome in param visual composer? - font-awesome

I code element with visual composer. I want to use fontawesome in element.
Code here show list font-awesome in param visual composer
<code>
array(
'type' => 'iconpicker',
'heading' => esc_html__('Fontawesome', 'interior'),
'param_name' => 'fontawesome_icon',
'settings' => array(
'type' => 'fontawesome'
),
'description' => esc_html__( 'Fontawesome list. Pickup your choice.', 'interior'
),
'dependency' => array(
'element' => 'icon_type',
'value' => array( 'fontawesome-icon' )
)
</code>
I showed list icon in element but i chosen it don't saved and i don't know get value font-awsome display html.
Help me!!!

I have made a code only for Font Awesome Icon... You can try this
below code. it's tested and definitely works. here I have used
"Facebook" in title...Let me know via comment if you found any issue
in code or having any trouble for this.
<?php
if ( ! defined( 'ABSPATH' ) ) exit;
if( !class_exists( 'RN_FA_Icon_list' ) ) {
class RN_FA_Icon_list {
private $shortcode;
function __construct() {
/* shortcode base */
$this->shortcode = 'rn_fa_icon_list';
add_action( 'init', array( $this, 'rn_map_shortcode' ) );
add_shortcode( $this->shortcode, array( $this, 'rn_create_shortcode' ) );
}
function rn_map_shortcode( $atts, $content = NULL ) {
if( function_exists( 'vc_map' ) ) {
vc_map(
array(
'name' => esc_html__( 'Font Awesome Icon', 'rn_shortcodes' ),
//'icon' => RN_SHORTCODES_URL . '/admin/img/vc_icons/fancy-list.png',
'base' => $this->shortcode,
'category' => 'Structual',
'class' => 'rn-vc-icon-module rn-structual-module',
'content_element' => true,
'params' => array(
array(
'type' => 'textfield',
'heading' => esc_html__( 'Description', 'rn_shortcodes' ),
'description' => esc_html__( 'Only for internal use. This adds a label to Visual Composer for an easier element identification.', 'rn_shortcodes' ),
'param_name' => 'list_description',
'admin_label' => true,
'group' => 'General'
),
array(
'type' => 'iconpicker',
'heading' => __( 'Icon', 'js_composer' ),
'param_name' => 'icon_fontawesome',
'value' => 'fa fa-adjust',
'group' => 'General',
'settings' => array(
'emptyIcon' => false,
'type' => 'fontawesome',
'iconsPerPage' => 4000,
),
'dependency' => array(
'element' => 'type',
'value' => 'fontawesome',
),
'description' => __( 'Select icon from library.', 'js_composer' ),
),
array(
'type' => 'css_editor',
'param_name' => 'css',
'group' => esc_html__( 'Design Options', 'rn_shortcodes' ),
),
)
)
); /* end mapping */
}
}
function rn_create_shortcode( $atts, $content = NULL ) {
extract( shortcode_atts( array (
'icon_fontawesome' => '',
'css' => ''
), $atts ) );
/* extract list items */
if( function_exists('vc_param_group_parse_atts') && !empty( $values ) ) {
$values = vc_param_group_parse_atts( $values );
}
/* unique listz ID */
$id = uniqid("rn_fa_");
$output = '';
$output .= '<div id="' . esc_attr( $id ) . '">';
$output .= '<i class="' . $icon_fontawesome . '"></i> Facebook';
$output .= '</div>';
return '<div class="wpb_content_element ' . apply_filters( VC_SHORTCODE_CUSTOM_CSS_FILTER_TAG, vc_shortcode_custom_css_class( $css, ' ' ), $this->shortcode, $atts ) . '">' . $output . '</div>';
}
}
}
new RN_FA_Icon_list;
?>

Related

How to Get WooCommerce Product Name with WP_Query?

I am trying to use this code on "Wp All Import". If there is a product name in the database, that product should be omitted, but the code will not work as is. What do I need to do for the code to work?
add_filter('wp_all_import_is_post_to_create', 'create_only_if_unique_custom_field', 10, 3);
function create_only_if_unique_custom_field( $continue_import, $data, $import_id ) {
// Only run for import ID 1.
if ( $import_id == 33 || $import_id == 34 ) {
// The custom field to check.
$key_to_look_up = "post_title";
// The value to check where 'num' is the element name.
$value_to_look_up = $data['name'];
// Prepare the WP_Query arguments
$args = array (
// Set the post type being imported.
'post_type' => array( 'post' ),
// Check our custom field for our value.
'meta_query' => array(array(
'key' => $key_to_look_up,
'value' => $value_to_look_up,
)),
);
// Run the query and do not create post if custom field value is duplicated.
$query = new WP_Query( $args );
return !($query->have_posts());
} else {
// Take no action if a different import ID is running.
return $continue_import;
}
}
You can do like this.
<?php
$params = array('posts_per_page' => 5);
$wc_query = new WP_Query($params);
?>
<?php if ($wc_query->have_posts()) : ?>
<?php while ($wc_query->have_posts()) :
$wc_query->the_post(); ?>
<?php the_title(); ?>
<?php endwhile; ?>
<?php wp_reset_postdata();?>
<?php else: ?>
<p>
<?php _e( 'No Products' ); ?>
</p>
<?php endif; ?>
There are some ways to show the different types of Woocommerce product names with WP_Query.
<?php
//Pulling WooCommerce Products instead of WordPress Posts, Use this param
$params = array(
'posts_per_page' => 5,
'post_type' => 'product'
);
//Displaying products of a given price range, use this param
$params = array(
'posts_per_page' => 100,
'post_type' => array('product', 'product_variation'),
'meta_query' => array(
'relation' => 'OR',
array(
'key' => '_price',
'value' => 5,
'compare' => '<=',
'type' => 'NUMERIC'
),
array(
'key' => '_sales_price',
'value' => 5,
'compare' => '<=',
'type' => 'NUMERIC'
)
)
);
//Displaying available products only, use this param
$params = array(
'posts_per_page' => 5,
'post_type' => array('product', 'product_variation'),
'meta_query' => array(
array(
'key' => '_price',
'value' => 5,
'compare' => '<',
'type' => 'NUMERIC'
),
array(
'key' => '_stock_status',
'value' => 'instock'
)
)
);
$wc_query = new WP_Query($params);
if ($wc_query->have_posts()) :
while ($wc_query->have_posts()) :
$wc_query->the_post();
the_title();
endwhile;
endif;
Also will help you the article https://www.gavick.com/blog/wp_query-woocommerce-products
Thank you
This variable controls the title.
// Xml file column name
$value = = $data['product_title'];
// Get wpdb product title
$posts = get_posts([
'post_type' => 'product',
'title' => $value,
]);

put spans and divs around paginate_links

I wanna style my links and in order to do that I need some spans and divs around it but I dunno how it's done when using paginate_links() from WordPress.
Can you help me to do that?
<div class="pagination">
<?php echo
$pagination = paginate_links( array(
'base' => add_query_arg( 'cpage', '%#%' ),
'format' => '',
'prev_text' => __('← Previous'),
'next_text' => __('Next →'),
'total' => ceil($total / $items_per_page),
'current' => $page,
'type' => 'plain'
));
?>
</div>
so far it looks like that
Just change li to div / span whatever. The main difference is to change your "type" from "plain" to "array" and then you can do what you want with it.
<?php
global $wp_query;
$big = 999999999; // need an unlikely integer
$prev_next = paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages,
'type' => 'array',
'prev_text' => __('← Previous'),
'next_text' => __('Next →')
) );
if($prev_next){ ?>
<ul>
<?php
foreach($prev_next as $key=>$val){
if (strpos($val,"'page-numbers current'") !== false) {
echo '<li class="active item">'.$val.'</li>';
} elseif (strpos($val,'"next page-numbers"') !== false || strpos($val,'"prev page-numbers"') !== false ) {
echo'<li>'.$val.'</li>';
} else {
echo '<li class="item">'.$val.'</li>';
}
} ?>
</ul>
<?php } ?>

Move widget area on inner pages

I have added a widget area to my home page below front page 1 all good, what i want to do is on all pages except the home page have the same widget but just move it to above the footer
the above just shows the widget above the footer on all pages - can some one point me in the right direction please thanks in advanceenter code here
genesis_register_sidebar( array(
'id' => 'newsletter',
'name' => __( 'Newsletter Widget', 'genesis' ),
'description' => __( 'Newsletter Widget Area', 'monochrome-pro' ),
) );
add_action( 'genesis_after_front-page-1_widget_area', 'add_genesis_widget_area' );
if ( is_home() && is_front_page() ) {
function add_genesis_widget_area() {
genesis_widget_area( 'newsletter', array(
'before' => '<div class="newsletter widget-area">',
'after' => '</div>',
) );
}
}
add_action( 'genesis_after_footer', 'add_genesis_widget_area2' );
if ( !is_home() && !is_front_page() ) {
function add_genesis_widget_area2() {
genesis_widget_area( 'newsletter', array(
'before' => '<div class="newsletter widget-area">',
'after' => '</div>',
) );
}
}

Issue on Adding Taxonomy to Custom Post Type Using Function

Using WordPress 3.7.1 and PHP 5.4.12, I am trying to add Custom Post Type and Taxonomy to my Theme, so far the custom post type method works but the Taxonomy is not adding to the Admin Dashboard.
Here is the code I have:
<?php
function add_post_type($name, $args = array()) {
add_action('init', function() use($name, $args) {
$upper = ucwords($name);
$name = strtolower(str_replace(' ','_',$name));
$args = array_merge(
array(
'public'=> true,
'label' => "All $upper" . 's',
'labels' => array('add_new_item' => "Add New $upper"),
'support' => array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments')
),
$args
);
register_post_type('$name', $args);
});
}
function add_taxonomy($name, $post_type, $args = array()) {
$name = strtolower($name);
add_action('init', function() use($name, $post_type, $args) {
$args = array_merge(
array(
'label' => ucwords($name),
),
$args
);
register_taxonomy($name, $post_type, $args);
});
}
add_post_type('book', array(
'supports' => array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments')
));
add_taxonomy('fun', 'book');
?>
Can you please let me know what part I am doing wrong?
The $name variable is not parsed, put it between double quotes:
register_post_type( "$name", $args );
edit
add_action( 'init', 'so19966809_init' );
function so19966809_init()
{
register_post_type( 'book', array(
'public'=> true,
'label' => 'All Books',
'labels' => array( 'add_new_item' => 'Add New Book' ),
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ),
'taxonomies' => array( 'fun' )
) );
register_taxonomy( 'fun', 'book', array(
'label' => 'Fun',
) );
}

Woocommerce payment gateway integration

Have a problem with latest woocommerce version payment gateway integration.
I recently started using woocommerce for a friend and he was having woocommerce version 1.6.5.2. But now he updated his woocommerce to latest version (2.0.12).
He had some custom made payment gateway that worked on the 1.6 version but now it doesnt.
This is the custom payment gateway code:
/*
Plugin Name ......
.../*
$post_perma = trim( esc_url ( $_SERVER['REQUEST_URI'] ), '/' );
add_action('plugins_loaded', 'woocommerce_rba_etomitreba_init', 0);
if($post_perma == 'uspjeh'||$post_perma == 'greska') {
add_filter('the_content', 'after_processing');
}
function after_processing() {
global $post, $post_perma, $woocommerce;
if($post_perma == 'uspjeh') {
if(isset($_POST['OrderID'])&&isset($_POST['ApprovalCode'])) {
echo '<div class="notify notify-success">Not Important;)</div>';
$order = new WC_Order( $_POST['OrderID'] );
$order->payment_complete();
$order->status = 'completed';
$woocommerce->cart->empty_cart();
unset($_SESSION['order_awaiting_payment']);
}
else {
echo '<div class="notify notify-error">Not Important</div>';
}
}
if($post_perma == 'greska') {
echo '<div class="notify notify-error">DNot Important</div>';
}
}
function woocommerce_rba_etomitreba_init() {
if ( !class_exists( 'WC_Payment_Gateway' ) ) return;
class WC_Raiffeisen_Bank_eToMiTreba extends WC_Payment_Gateway {
public function __construct() {
$this->id = 'rba_etomitreba';
$this->method_title = __( 'Raiffeisen Bank', 'woocommerce' );
$this->icon = apply_filters('woocommerce_cheque_icon', '');
$this->has_fields = false;
// Load the form fields.
$this->form_fields = array(
'enabled' => array(
'title' => __( 'Not Important', 'woothemes' ),
'type' => 'checkbox',
'label' => __( 'Not Important', 'woothemes' ),
'default' => 'yes'
),
'merchant-id' => array(
'title' => __( 'Not Important', 'woothemes' ),
'type' => 'text',
'description' => __( 'Not Important', 'woothemes' ),
'default' => __( '', 'woothemes' )
),
'terminal-id' => array(
'title' => __( 'Not Important', 'woothemes' ),
'type' => 'text',
'description' => __( 'Not Important', 'woothemes' ),
'default' => __( '', 'woothemes' )
),
'rsa-private-key' => array(
'title' => __( 'Not Important', 'woothemes' ),
'type' => 'textarea',
'description' => __( 'Not Important', 'woothemes' ),
'default' => __( '', 'woothemes' )
),
'title' => array(
'title' => __( 'Not Important', 'woothemes' ),
'type' => 'text',
'description' => __( '', 'woothemes' ),
'default' => __( 'Not Important', 'woothemes' )
),
'description' => array(
'title' => __( 'Not Important', 'woothemes' ),
'type' => 'textarea',
'description' => __( '', 'woothemes' ),
'default' => 'Not Important.'
)
);
// Load the settings.
$this->init_settings();
$this->title = $this->settings['title'];
$this->description = $this->settings['description'];
// Actions
add_action('woocommerce_update_options_payment_gateways', array(&$this, 'process_admin_options'));
}
public function process_payment( $order_id ) {
$order = new WC_Order( $order_id );
$order->shipping_first_name;
$order->shipping_last_name;
$order->get_shipping_address();
$url_gateway = 'Not Important';
$merchant_id = 'xxxxx';
$terminal_id = 'xxxxx';
$total = $order->get_total()*100; // kn to lp conversion
$currency_id = 191;
$time = new DateTime('', new DateTimeZone('Europe/Zagreb'));
$purchase_time = $time->format('ymdHis');
$locale = 'hr';
$ordered_items = $order->get_items();
foreach($ordered_items as $item) {
$ordered_items_array[] = $item['name'];
}
$ordered_items = implode(', ',$ordered_items_array);
$purchase_desc = $time->format('d.m.Y. H:i:s').' - '.$order->shipping_first_name.' '.$order->shipping_last_name.' : '.$ordered_items;
$session_id = session_id();
$data = "$merchant_id;$terminal_id;$purchase_time;$order_id;$currency_id;$total;$session_id;";
$priv_key = $this->settings['rsa-private-key'];
$pkeyid = openssl_get_privatekey($priv_key);
openssl_sign($data, $signature, $pkeyid);
openssl_free_key($pkeyid);
$b64sign = base64_encode($signature);
$signature = $b64sign;
//$order->update_status('on-hold', __('Not Important', 'woothemes'));
echo '
<form name="ordersend" action="'.$url_gateway.'" method="post">
<input name="Version" type="hidden" value="1" >
<input name="MerchantID" type="hidden" value="'.$merchant_id.'" >
<input name="TerminalID" type="hidden" value="'.$terminal_id.'" >
<input name="TotalAmount" type="hidden" value="'.$total.'">
<input name="SD" type="hidden" value="'.$session_id.'">
<input name="Currency" type="hidden" value="'.$currency_id.'" >
<input name="Locale" type="hidden" value="'.$locale.'">
<input name="OrderID" type="hidden" value="'.$order_id.'" >
<input name="PurchaseTime" type="hidden" value="'.$purchase_time.'">
<input name="PurchaseDesc" type="hidden" value="'.$purchase_desc.'" >
<input name="Signature" type="hidden" value="'.$signature.'" >
</form>
<script language="javascript">
<!--
document.forms["ordersend"].submit();
--></script>
';
/*
return array (
'result' => 'success'
);*/
}
public function admin_options() {
?>
<img src="<?php echo 'Not Important ?>" width="664" height="114" />
<h3><?php _e('Not Important', 'woothemes'); ?></h3>
<p><?php _e('Not Important'); ?></p>
<table class="form-table">
<?php
// Generate the HTML For the settings form.
$this->generate_settings_html();
?>
</table>
<?php
} // End admin_options()
}
function woocommerce_raiffeisen_bank_etomitreba_gateway($methods) {
$methods[] = 'WC_Raiffeisen_Bank_eToMiTreba';
return $methods;
}
add_filter('woocommerce_payment_gateways', 'woocommerce_raiffeisen_bank_etomitreba_gateway' );
}
Its just a compatibility issue but as i said, i am new to woocommerce and not so experienced with php. Any help would be greatly appreciated.
Change
add_action('woocommerce_update_options_payment_gateways', array(&$this, process_admin_options'));
to
if ( version_compare( WOOCOMMERCE_VERSION, '2.0.0', '>=' ) ) {
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( &$this, 'process_admin_options' ) );
} else {
add_action( 'woocommerce_update_options_payment_gateways', array( &$this, 'process_admin_options' ) );
}