Related
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 } ?>
I have managed to add a custom text area to the woocommerce product data where my client can add in a kit list that is output to the packing list for the shop floor but the line breaks don't save and the output is a flow of text making it less easy on the eye for the guys picking
This is what I have but where and how do I make it preserve the line breaks added in the admin suite to output on the packing slip:
//General Fields
add_action( 'woocommerce_product_options_general_product_data', 'woo_add_custom_general_fields',10,3
);
add_action( 'woocommerce_process_product_meta', 'woo_add_custom_general_fields_save',10,2 );
//variable data
add_action('woocommerce_product_after_variable_attributes', 'variation_settings_fields', 10, 3);
add_action('woocommerce_save_product_variation','save_variation_settings_fields',10, 2);
//data tab
add_action( 'woocommerce_product_data_panels', 'add_my_custom_product_data_fields',10,3 );
add_action( 'woocommerce_process_product_meta','woocommerce_process_product_meta_fields_save',10,2 );
function woo_add_custom_general_fields() {
global $woocommerce, $post;
// Textarea
woocommerce_wp_textarea_input(
array(
'id' => '_textarea[' . $post->ID . ']',
'label' => __( 'Kit List', 'woocommerce' ),
'placeholder' => '',
'description' => __( 'Enter the kit list here.', 'woocommerce' ),
'value' => get_post_meta( $post->ID, '_textarea', true ),
)
);
}
function woo_add_custom_general_fields_save( $post_id ){
// Textarea
$textarea = $_POST['_textarea'][ $post_id ];
if( ! empty( $textarea ) ) {
update_post_meta( $post_id, '_textarea', esc_attr( $textarea ) );
}
}
function variation_settings_fields($loop, $variation_data, $variation){
// Textarea
woocommerce_wp_textarea_input(
array(
'id' => '_textarea[' . $variation->ID . ']',
'label' => __( 'Kit List', 'woocommerce' ),
'placeholder' => '',
'description' => __( 'Enter the kit list here.', 'woocommerce' ),
'value' => get_post_meta( $variation->ID, '_textarea', true ),
)
);
}
function save_variation_settings_fields($post_id){
// Textarea
$textarea = $_POST['_textarea'][ $post_id ];
if( ! empty( $textarea ) ) {
update_post_meta( $post_id, '_textarea', esc_attr( $textarea ) );
}
}
add_action( 'wpo_wcpdf_after_item_meta', 'wpo_wcpdf_product_custom_field', 10, 3 );
function wpo_wcpdf_product_custom_field ( $template_type, $item, $order ) {
if ( $template_type == 'packing-slip' ) {
// check if product exists first
if (empty($item['product'])) return;
// replace 'Location' with your custom field name!
$field_name = '_textarea';
$textarea = method_exists($item['product'], 'get_meta') ? $item['product']
->get_meta($field_name,true,'edit') : get_post_meta( $item['product']->id, $field_name, true );
if (!empty($textarea)) {
echo nl2br('Kit List: '.$textarea.'');
}
}
}
That trouble in function wc_clean - it used to get value and always use _sanitize_text_fields( $str, false ), so regardless of field type, woo removes trailing characters :( See trace below:
In may situation (Need additional field in address), I found it in form edit address.
#/wp-content/plugins/woocommerce/templates/myaccount/form-edit-address.php:38
woocommerce_form_field( $key, $field, wc_get_post_data_by_key( $key, $field['value'] ) );
where wc_get_post_data_by_key function return cleaned data by wc_clean
#/wp-content/plugins/woocommerce/includes/wc-core-functions.php:2005
return wc_clean( wp_unslash( wc_get_var( $_POST[ $key ], $default ) ) ); // #codingStandardsIgnoreLine
that use satinize text
#/wp-content/plugins/woocommerce/includes/wc-formatting-functions.php:392
return is_scalar( $var ) ? sanitize_text_field( $var ) : $var;
where not keep_newlines set (by default it is false):
#WordPress/wp-includes/formatting.php:5244
$filtered = _sanitize_text_fields( $str, false );
Thus, there are no line breaks in all data of any type received by the function wc_get_post_data_by_key()
#WordPress/wp-includes/formatting.php:5317
if ( ! $keep_newlines ) {
$filtered = preg_replace( '/[\r\n\t ]+/', ' ', $filtered );
}
Solution (?)
the solution is cardinal - leave line breaks for all text fields similar to sanitize_textarea_field ():
add_filter( 'sanitize_text_field', function ( $filtered, $str ) {
return _sanitize_text_fields( $str, true );
}
, 10, 2 );
I'm trying to add an additional custom menu to a Wordpress theme. I've registered the menu and location in the functions.php file, created a new page template and added the menu. However whenever I add items to the menu it replaces everything in the main header but also adds it to where I need it to be.
Any help would be greatly appreciated.
Thanks
Jack
Below is my functions.php file. The menu I am trying to add is right
at the bottom called about-menu
<?php
function cc_mime_types( $mimes ){
$mimes['svg'] = 'image/svg+xml';
return $mimes;
}
add_filter( 'upload_mimes', 'cc_mime_types' );
?>
<?php add_theme_support( 'post-thumbnails' ); ?>
<?php
add_filter('next_posts_link_attributes', 'posts_link_next');
add_filter('previous_posts_link_attributes', 'posts_link_prev');
function posts_link_next() {
return 'class="next-button"';
}
function posts_link_prev() {
return 'class="prev-button"';
}; ?>
<?php add_filter('show_admin_bar', '__return_false'); ?>
<?php
/**
* Register our sidebars and widgetized areas.
*
*/
function arphabet_widgets_init() {
register_sidebar( array(
'name' => 'index-sidebar',
'id' => 'index-sidebar-widget',
'before_widget' => '<div class="sidebar-widget">',
'after_widget' => '</div>',
'before_title' => '<h2 class="widget-sidebar">',
'after_title' => '</h2>',
) );
register_sidebar( array(
'name' => 'announcement',
'id' => 'announcement',
'before_widget' => '<div class="announcement">',
'after_widget' => '</div>',
'before_title' => '<h2 class="announcement-title">',
'after_title' => '</h2>',
) );
register_sidebar( array(
'name' => 'tweets',
'id' => 'tweets',
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => '',
) );
register_sidebar( array(
'name' => 'events',
'id' => 'widget-events',
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => '',
) );
}
add_action( 'widgets_init', 'arphabet_widgets_init' );
/*
* Alters event's archive titles
*/
function tribe_alter_event_archive_titles ( $original_recipe_title, $depth ) {
// Modify the titles here
// Some of these include %1$s and %2$s, these will be replaced with relevant dates
$title_upcoming = 'Upcoming Events'; // List View: Upcoming events
$title_past = 'Past Events'; // List view: Past events
$title_range = 'Events for %1$s - %2$s'; // List view: range of dates being viewed
$title_month = 'Events for %1$s'; // Month View, %1$s = the name of the month
$title_day = 'Events for %1$s'; // Day View, %1$s = the day
$title_all = 'All events for %s'; // showing all recurrences of an event, %s = event title
$title_week = 'Events for week of %s'; // Week view
// Don't modify anything below this unless you know what it does
global $wp_query;
$tribe_ecp = Tribe__Events__Main::instance();
$date_format = apply_filters( 'tribe_events_pro_page_title_date_format', tribe_get_date_format( true ) );
// Default Title
$title = $title_upcoming;
// If there's a date selected in the tribe bar, show the date range of the currently showing events
if ( isset( $_REQUEST['tribe-bar-date'] ) && $wp_query->have_posts() ) {
if ( $wp_query->get( 'paged' ) > 1 ) {
// if we're on page 1, show the selected tribe-bar-date as the first date in the range
$first_event_date = tribe_get_start_date( $wp_query->posts[0], false );
} else {
//otherwise show the start date of the first event in the results
$first_event_date = tribe_event_format_date( $_REQUEST['tribe-bar-date'], false );
}
$last_event_date = tribe_get_end_date( $wp_query->posts[ count( $wp_query->posts ) - 1 ], false );
$title = sprintf( $title_range, $first_event_date, $last_event_date );
} elseif ( tribe_is_past() ) {
$title = $title_past;
}
// Month view title
if ( tribe_is_month() ) {
$title = sprintf(
$title_month,
date_i18n( tribe_get_option( 'monthAndYearFormat', 'F Y' ), strtotime( tribe_get_month_view_date() ) )
);
}
// Day view title
if ( tribe_is_day() ) {
$title = sprintf(
$title_day,
date_i18n( tribe_get_date_format( true ), strtotime( $wp_query->get( 'start_date' ) ) )
);
}
// All recurrences of an event
if ( function_exists('tribe_is_showing_all') && tribe_is_showing_all() ) {
$title = sprintf( $title_all, get_the_title() );
}
// Week view title
if ( function_exists('tribe_is_week') && tribe_is_week() ) {
$title = sprintf(
$title_week,
date_i18n( $date_format, strtotime( tribe_get_first_week_day( $wp_query->get( 'start_date' ) ) ) )
);
}
if ( is_tax( $tribe_ecp->get_event_taxonomy() ) && $depth ) {
$cat = get_queried_object();
$title = '' . $title . '';
$title .= ' › ' . $cat->name;
}
return $title;
}
add_filter( 'tribe_get_events_title', 'tribe_alter_event_archive_titles', 11, 2 );
?>
<?php
add_filter('wp_nav_menu_objects', 'ad_filter_menu', 10, 2);
function ad_filter_menu($sorted_menu_objects, $args) {
// check for the right menu to filter
// here we check for the menu with name 'Posts Menu'
// given that you call it in you theme with:
// wp_nav_menu( array( 'menu' => 'Posts Menu' ) );
// if you call the menu using theme_location, eg:
// wp_nav_menu( array( 'theme_location' => 'top_manu' ) );
// check for:
// if ($args->theme_location != 'top_menu')
if ($args->menu != 'Parents Menu')
return $sorted_menu_objects;
// edit the menu objects
foreach ($sorted_menu_objects as $menu_object) {
// searching for menu items linking to posts or pages
// can add as many post types to the array
if ( in_array($menu_object->object, array('post', 'page', 'any_post_type')) ) {
// set the title to the post_thumbnail if available
// thumbnail size is the second parameter of get_the_post_thumbnail()
$menu_object->title = has_post_thumbnail($menu_object->object_id) ? get_the_post_thumbnail($menu_object->object_id, 'full') . '<span class="outer"><span>' . $menu_object->title . "</span></span>": $menu_object->title;
}
}
return $sorted_menu_objects;
};
?>
<?php
function register_my_menu() {
register_nav_menu('about-menu',__( 'About Menu' ));
}
add_action( 'init', 'register_my_menu' );
?>
The next code snippet is from my page template that I want to add the
menu to.
<?php
/*
Template Name: About Us Page
*/
?>
<?php get_header();?>
<div class="main">
<div class="page-top-banner" id="page-four-banner">
<h1><span>About</span></h1>
</div>
<div class="parental-inner">
<?wp_nav_menu( array( 'theme_location' => 'about-menu', 'container_class' => 'about_menu_class' ) ); ?>
</div>
<?php get_footer();?>
Remove your register_my_menu function from functions php, and replace with the following:
Remove this:
function register_my_menu() {
register_nav_menu('about-menu',__( 'About Menu' ));
}
add_action( 'init', 'register_my_menu' );
Replace with this:
//nav
register_nav_menus(array(
'main-menu' => __('Main Menu'),
'about-menu' => __('About Menu'),
));
Does that output correctly on the page template?
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;
?>
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' ) );
}