| Autor | Zpráva | ||
|---|---|---|---|
| vodys Profil |
Zdravím.
Lámu si hlavu s jednou naprostou blbostí. Potřebuji jinde na stránce vyvolat text, který je uvedený ve spanu. U každého produktu se mi zobrazuje cena např: 525 Kč /m2 vč.DPH ... Ve spanu mám uvedeno: <span class="awspn_price_note"> /m2</span>.
Potřebuju však toto jakoby duplikovat ještě jinde na stránce - bohužel vzhledem k tomu, že je to wordpress, nedaří se mi tu funkci vyvolat napříč pluginy.. Proto hledám něco jednoduché, co bude pouze daný span zrcadlit. Jinak přikládám funkcionalitu php souboru zajišťující zobrazení správné jednotky za cenou if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* Woo Set Price Note
*
* Allows user to get WooCommerce Set Price Note.
*
* @class Woo_Set_Price_Note_Frontend
*/
class Woo_Set_Price_Note_Frontend {
/**
* Init and hook in the integration.
*
* @return void
*/
public function __construct() {
$this->id = 'Woo_Set_Price_Note_Frontend';
$this->method_title = __( 'WooCommerce Set Price Note', 'woo-set-price-note' );
$this->method_description = __( 'WooCommerce Set Price Note', 'woo-set-price-note' );
// Filters
// Add saved price note
add_filter( 'woocommerce_get_price_html', array( $this, 'awspn_display_price_note'), 99, 2 );
// Display price note on cart page
add_filter( 'woocommerce_cart_item_price', array( $this, 'awspn_display_cart_price_note'), 10, 2 );
// Display price note on checkout page
add_filter( 'woocommerce_cart_item_name', array( $this, 'awspn_display_checkout_price_note'), 10, 2 );
// Add price note to the cart item meta
add_filter( 'woocommerce_add_cart_item_data', array( $this, 'awspn_add_price_note_to_cart_item'), 10, 3 );
// Add price note to the order item meta
add_action( 'woocommerce_add_order_item_meta', array( $this, 'awspn_add_price_note_to_order_item_meta'), 10, 3 );
// Add item meta from cart to order
if ( version_compare( get_option( 'woocommerce_version', null ), '3.0.0', '<' ) ) {
add_action( 'woocommerce_add_order_item_meta', array( $this, 'awspn_add_price_note_to_order_item_meta' ), 10, 3 );
} else {
add_action( 'woocommerce_checkout_create_order_line_item', array( $this, 'awspn_save_values_in_item' ), 10, 4 );
add_action( 'woocommerce_new_order_item', array( $this, 'awspn_add_price_note_to_order_item_meta_wc3' ), 10, 3 );
}
// Load small styling
add_action('wp_footer', array( $this, 'awspn_print_price_note_style'));
}
/**
* Loading price note options on WooCommerce product section.
*
* @return string
*/
public function awspn_display_price_note( $price, $product ){
//woocommerce 3.0 compatible
if(method_exists($product, 'get_id')){
$product_id = $product->get_id();
}else{
$product_id = $product->id;
}
return $this->awspn_format_price_note($product_id, $price);
}
public function awspn_display_cart_price_note( $price, $cart_item ){
//print_pre($cart_item['price-note-text']);
$product_id = $cart_item['product_id'];
return $this->awspn_format_price_note($product_id, $price);
}
public function awspn_format_price_note($product_id, $price){
$price_note_text = esc_attr( get_post_meta( $product_id, 'awspn_product_price_note', true ) );
$price_note_separator = esc_attr( get_post_meta( $product_id, 'awspn_product_price_note_separator', true ) );
if( !empty( $price_note_text ) && isset( $price_note_text ) ){
if( !empty( $price_note_separator ) && isset( $price_note_separator ) ){
return $price .'<span class="awspn_price_note" > '. $price_note_separator .' '. $price_note_text .'</span>';
} else {
return $price .'<span class="awspn_price_note" > / '. $price_note_text .'</span> vč. DPH';
}
} else {
return $price;
}
} |
||
| nethor Profil |
#2 · Zasláno: 25. 10. 2018, 14:41:41
Tak si na to uprav funkci awspn_format_price_note($product_id, $price), nějak takhle (netestováno) :
public function FromSpan($product_id){
$price_note_text = esc_attr( get_post_meta( $product_id, 'awspn_product_price_note', true ) );
$price_note_separator = esc_attr( get_post_meta( $product_id, 'awspn_product_price_note_separator', true ) );
if( !empty( $price_note_text ) && isset( $price_note_text ) ){
if( !empty( $price_note_separator ) && isset( $price_note_separator ) ){
return ' '. $price_note_separator .' '. $price_note_text ;
} else {
return ' / '. $price_note_text ;
}
}
} |
||
|
Časová prodleva: 8 let
|
|||
0