Woocommerce: Permite a los clientes editar pedidos en proceso
/**
* @snippet Edit Order Functionality @ WooCommerce My Account Page
* @how-to Get CustomizeWoo.com FREE
* @sourcecode https://businessbloomer.com/?p=91893
* @author Rodolfo Melogli
* @compatible WooCommerce 4.1
* @donate $9 https://businessbloomer.com/bloomer-armada/
*/
// ----------------
// 1. Allow Order Again for Processing Status
add_filter( 'woocommerce_valid_order_statuses_for_order_again', 'bbloomer_order_again_statuses' );
function bbloomer_order_again_statuses( $statuses ) {
$statuses[] = 'processing';
return $statuses;
}
// ----------------
// 2. Add Order Actions @ My Account
add_filter( 'woocommerce_my_account_my_orders_actions', 'bbloomer_add_edit_order_my_account_orders_actions', 50, 2 );
function bbloomer_add_edit_order_my_account_orders_actions( $actions, $order ) {
if ( $order->has_status( 'processing' ) ) {
$actions['edit-order'] = array(
'url' => wp_nonce_url( add_query_arg( array( 'order_again' => $order->get_id(), 'edit_order' => $order->get_id() ) ), 'woocommerce-order_again' ),
'name' => __( 'Edit Order', 'woocommerce' )
);
}
return $actions;
}
// ----------------
// 3. Detect Edit Order Action and Store in Session
add_action( 'woocommerce_cart_loaded_from_session', 'bbloomer_detect_edit_order' );
function bbloomer_detect_edit_order( $cart ) {
if ( isset( $_GET['edit_order'], $_GET['_wpnonce'] ) && is_user_logged_in() && wp_verify_nonce( wp_unslash( $_GET['_wpnonce'] ), 'woocommerce-order_again' ) ) WC()->session->set( 'edit_order', absint( $_GET['edit_order'] ) );
}
// ----------------
// 4. Display Cart Notice re: Edited Order
add_action( 'woocommerce_before_cart', 'bbloomer_show_me_session' );
function bbloomer_show_me_session() {
if ( ! is_cart() ) return;
$edited = WC()->session->get('edit_order');
if ( ! empty( $edited ) ) {
$order = new WC_Order( $edited );
$credit = $order->get_total();
wc_print_notice( 'A credit of ' . wc_price($credit) . ' has been applied to this new order. Feel free to add products to it or change other details such as delivery date.', 'notice' );
}
}
// ----------------
// 5. Calculate New Total if Edited Order
add_action( 'woocommerce_cart_calculate_fees', 'bbloomer_use_edit_order_total', 20, 1 );
function bbloomer_use_edit_order_total( $cart ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return;
$edited = WC()->session->get('edit_order');
if ( ! empty( $edited ) ) {
$order = new WC_Order( $edited );
$credit = -1 * $order->get_total();
$cart->add_fee( 'Credit', $credit );
}
}
// ----------------
// 6. Save Order Action if New Order is Placed
add_action( 'woocommerce_checkout_update_order_meta', 'bbloomer_save_edit_order' );
function bbloomer_save_edit_order( $order_id ) {
$edited = WC()->session->get( 'edit_order' );
if ( ! empty( $edited ) ) {
// update this new order
update_post_meta( $order_id, '_edit_order', $edited );
$neworder = new WC_Order( $order_id );
$oldorder_edit = get_edit_post_link( $edited );
$neworder->add_order_note( 'Order placed after editing. Old order number: <a href="' . $oldorder_edit . '">' . $edited . '</a>' );
// cancel previous order
$oldorder = new WC_Order( $edited );
$neworder_edit = get_edit_post_link( $order_id );
$oldorder->update_status( 'cancelled', 'Order cancelled after editing. New order number: <a href="' . $neworder_edit . '">' . $order_id . '</a> -' );
WC()->session->set( 'edit_order', null );
}
}
Visto en Business Bloomer
Eliminar la palabra Archivos del título de los archivos de WordPress
add_filter('gettext', function($translated_text, $untranslated_text, $domain){
if($untranslated_text == "Archives: %s" && $domain == 'default'){
$translated_text = '%s';
}
return $translated_text;
}, 20, 3);
Visto en Toolset
Custom logout
/** Custom Logout Shortcode
*/
function custom_logout_link_func() {
$return = wp_logout_url();?>
<a href="<?php echo $return; ?>" class="btn btn-primary btn-xs btn-block" role="button" style="margin-bottom: 10px;">Logout</a>
<?php
}
add_shortcode('logout_link', 'custom_logout_link_func');
/**
*Used to redirect after logout
*/
function logout_page() {
$login_page = home_url();
wp_redirect( $login_page . "" );
exit;
}
add_action('wp_logout','logout_page');
WP-Cred login form: redirects based on different member roles
/**
* Redirect user after successful login.
*
* @param string $redirect_to URL to redirect to.
* @param string $request URL the user is coming from.
* @param object $user Logged user's data.
* @return string
*/
function my_login_redirect( $redirect_to, $request, $user ) {
//is there a user to check?
if ( isset( $user->roles ) && is_array( $user->roles ) ) {
//check for admins
if ( in_array( 'administrator', $user->roles ) ) {
// redirect them to the default place
return $redirect_to;
} else {
return home_url();
}
} else {
return $redirect_to;
}
}
add_filter( 'login_redirect', 'my_login_redirect', 10, 3 );
https://codex.wordpress.org/Plugin_API/Filter_Reference/login_redirect
function my_login_redirect( $redirect_to, $request, $user ) {
if( !isset( $user->user_login ) ){ // we only want this to run when credentials have been supplied
return $redirect_to;
}
//is there a user to check?
if (isset($user->roles) && is_array($user->roles)) {
//check for subscribers
if (in_array('subscriber', $user->roles)) {
// redirect them to another URL, in this case, the homepage
$redirect_to = '<em><u>hidden link</u></em>';
}
if (in_array('contributor', $user->roles)) {
// redirect them to another URL, in this case, the search page
$redirect_to = '<em><u>hidden link</u></em>';
}
// copy and paste the block above for each role
}
return $redirect_to;
}
add_filter( 'login_redirect', 'my_login_redirect', 10, 3 );
https://toolset.com/forums/topic/need-to-have-1-login-form-that-redirects-based-on-wp_user-role/
Change “Return to Shop” Button Link – WooCommerce
/**
* @snippet Change return to shop link, send to homepage instead
* @how-to Get CustomizeWoo.com FREE
* @sourcecode https://businessbloomer.com/?p=603
* @author Rodolfo Melogli
* @compatible WooCommerce 3.5.6
* @donate $9 https://businessbloomer.com/bloomer-armada/
*/
add_filter( 'woocommerce_return_to_shop_redirect', 'bbloomer_change_return_shop_url' );
function bbloomer_change_return_shop_url() {
return home_url();
}
Visto en https://businessbloomer.com/woocommerce-change-return-shop-url/
Primera letra de cada custom post type
[wpv-layout-start]
[wpv-items-found]
<a href="[current_url]">All</a>
<!-- wpv-loop-start -->
<wpv-loop>
<a href="?wpvalphabet=[wpv-taxonomy-title]">[wpv-taxonomy-title]</a>
</wpv-loop>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
[/wpv-no-items-found]
[wpv-layout-end]
add_shortcode( 'current_url', function(){
$request = $_SERVER['HTTP_HOST'].strtok($_SERVER["REQUEST_URI"],'?');
$protocol = 'http://';
if ( isset($_SERVER['HTTPS']) ) {
$protocol = 'https://';
}
return $protocol . $request;
} );
wpv-layout-start]
[wpv-view name="alphabet-terms"]
[wpv-items-found]
<!-- wpv-loop-start -->
<wpv-loop>
<h3>[wpv-post-link]</h3>
</wpv-loop>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
[/wpv-no-items-found]
[wpv-layout-end]
add_filter('wpv_filter_query', 'func_filter_by_title', 10, 2);
function func_filter_by_title($query, $setting) {
global $wpdb;
if($setting['view_id'] == 9999) {
if(isset($_GET['wpvalphabet']) and $_GET['wpvalphabet']!='' ){
$first_char = $_GET['wpvalphabet'];
$postids = $wpdb->get_col($wpdb->prepare("SELECT ID
FROM $wpdb->posts
WHERE SUBSTR($wpdb->posts.post_title,1,1) = %s
AND post_type = '".$query['post_type'][0]."'
AND post_status = 'publish'
ORDER BY $wpdb->posts.post_title",$first_char));
$query['post__in'] = $postids;
}
}
return
https://toolset.com/forums/topic/show-hidden-links/#post-1612419