Чтобы изменить переводимый текст на странице оформления заказа при наличии определенного элемента в корзине, используйте следующее:
add_filter( 'gettext', 'change_conditionally_checkout_heading_text', 10, 3 );
function change_conditionally_checkout_heading_text( $translated, $text, $domain ) {
if( $text === 'Billing details' && is_checkout() && ! is_wc_endpoint_url() ){
// HERE set the desired specific product ID
$targeted_product_id = 1980;
// Loop through cart items
foreach( WC()->cart->get_cart() as $cart_item ) {
if( $targeted_product_id == $cart_item['data']->get_id() )
return __( 'Your Details', $domain );
}
}
return $translated;
}
Код помещается в файл function.php вашей активной дочерней темы (или активной темы) , Проверено и работает.
Примечание: В оформлении заказа на Woocommerce текст, который нужно изменить, - это «Сведения о счете» без прописной буквы в « D etails»
blockquote>
Попробуйте это:
require 'nokogiri'
html_text = "<html><body><h1>Foo</h1><p>The quick brown fox.</p><h1>Bar</h1><p>Jumps over the lazy dog.</p></body></html>"
frag = Nokogiri::HTML(html_text)
frag.xpath("//h1").each { |div| div.name= "p"; div.set_attribute("class" , "title") }
Кажется, что это работает правильно:
require 'rubygems'
require 'nokogiri'
markup = Nokogiri::HTML.parse(<<-somehtml)
<html>
<body>
<h1>Foo</h1>
<p>The quick brown fox.</p>
<h1>Bar</h1>
<p>Jumps over the lazy dog.</p>
</body>
</html>
somehtml
markup.css('h1').each do |el|
el.name = 'p'
el.set_attribute('class','title')
end
puts markup.to_html
# >> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
# >> <html><body>
# >> <p class="title">Foo</p>
# >> <p>The quick brown fox.</p>
# >> <p class="title">Bar</p>
# >> <p>Jumps over the lazy dog.</p>
# >> </body></html>
#!/usr/bin/env ruby
require 'rubygems'
gem 'nokogiri', '~> 1.2.1'
require 'nokogiri'
doc = Nokogiri::HTML.parse <<-HERE
<html>
<body>
<h1>Foo</h1>
<p>The quick brown fox.</p>
<h1>Bar</h1>
<p>Jumps over the lazy dog.</p>
</body>
</html>
HERE
doc.search('h1').each do |heading|
heading.name = 'p'
heading['class'] = 'title'
end
puts doc.to_html